Warning, /graphics/krita/libs/macosutils/KisMacosEntitlements.mm is written in an unsupported language. File is not indexed.
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2023 Ivan Santa MarĂa <ghevan@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "KisMacosEntitlements.h" 0008 0009 #import <Foundation/Foundation.h> 0010 0011 #include <QHash> 0012 #include <QVariant> 0013 #include <QString> 0014 0015 #if ! __has_feature(objc_arc) 0016 #error "Enable ARC to compile this file" 0017 #endif 0018 0019 //Q_GLOBAL_STATIC(KisMacosEntitlements, s_instance) 0020 0021 class KisMacosEntitlements::Private 0022 { 0023 public: 0024 Private() 0025 : entitlements(QHash<Entitlements,QVariant>()) 0026 { 0027 } 0028 0029 ~Private() 0030 { 0031 } 0032 0033 QHash<Entitlements, QVariant> entitlements; 0034 }; 0035 0036 //KisMacosEntitlements* KisMacosEntitlements::instance() 0037 //{ 0038 // return s_instance; 0039 //} 0040 0041 0042 KisMacosEntitlements::KisMacosEntitlements() 0043 : m_d(new Private()) 0044 { 0045 loadAvailableEntitlements(); 0046 } 0047 0048 KisMacosEntitlements::~KisMacosEntitlements() 0049 { 0050 } 0051 0052 0053 void KisMacosEntitlements::loadAvailableEntitlements(void) 0054 { 0055 OSStatus status; 0056 SecCodeRef kritaRef = NULL; 0057 CFDictionaryRef dynamicInfo = NULL; 0058 0059 status = SecCodeCopySelf(kSecCSDefaultFlags, &kritaRef); 0060 // KIS_ASSERT_RECOVER_RETURN_VALUE(status == errSecSuccess, isSandboxed); 0061 0062 SecCodeCopySigningInformation(kritaRef, (SecCSFlags) kSecCSDynamicInformation, &dynamicInfo); 0063 // KIS_ASSERT_RECOVER_RETURN_VALUE(status == errSecSuccess, isSandboxed); 0064 0065 CFDictionaryRef rawEntitlements = (CFDictionaryRef)CFDictionaryGetValue(dynamicInfo, kSecCodeInfoEntitlementsDict); 0066 0067 if (rawEntitlements) { 0068 NSDictionary *entitlementsDir = (__bridge NSDictionary*)rawEntitlements; 0069 0070 for (NSString *key in entitlementsDir) { 0071 id value = entitlementsDir[key]; 0072 if ([key isEqualToString:@"com.apple.security.app-sandbox"]) { 0073 m_d->entitlements[Entitlements::Sandbox] = [value boolValue]; 0074 } 0075 else if ([key isEqualToString:@"com.apple.security.files.bookmarks.app-scope"]) { 0076 m_d->entitlements[Entitlements::BookmarkScopeApp] = [value boolValue]; 0077 } 0078 else if ([key isEqualToString:@"com.apple.security.files.bookmarks.document-scope"]) { 0079 m_d->entitlements[Entitlements::BookmarkScopeDocument] = [value boolValue]; 0080 } 0081 } 0082 } 0083 0084 if (dynamicInfo != NULL) { 0085 CFRelease(dynamicInfo); 0086 } 0087 if (kritaRef != NULL) { 0088 CFRelease(kritaRef); 0089 } 0090 0091 return; 0092 } 0093 0094 bool KisMacosEntitlements::hasEntitlement(Entitlements key) 0095 { 0096 // we assume if given entitlement exists then its true, but this is not always the case 0097 return m_d->entitlements.contains(key); 0098 } 0099 0100 bool KisMacosEntitlements::sandbox() 0101 { 0102 return m_d->entitlements.contains(Entitlements::Sandbox); 0103 }