2 * Copyright (c) 2020 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include "entitlements.h"
26 /// Moves the entitlement value from the original entitlement into the target entitlement.
27 static void transferEntitlement(CFMutableDictionaryRef entitlements
, CFStringRef originalEntitlement
, CFStringRef targetEntitlement
)
29 CFTypeRef value
= (CFStringRef
)CFDictionaryGetValue(entitlements
, originalEntitlement
);
30 CFDictionaryAddValue(entitlements
, targetEntitlement
, value
);
33 /// Determines if an entitlement needs fixup, which means it has a value for the original entitlement and no value for the
34 /// target entitlement.
35 static bool entitlementNeedsFixup(CFDictionaryRef entitlements
, CFStringRef originalEntitlement
, CFStringRef targetEntitlement
)
37 // Entitlements only need fixup on macOS running on Apple Silicon, so just always fall through to the default case otherwise.
38 #if TARGET_OS_OSX && TARGET_CPU_ARM64
39 CFTypeRef originalValue
= (CFStringRef
)CFDictionaryGetValue(entitlements
, originalEntitlement
);
40 CFTypeRef newValue
= (CFStringRef
)CFDictionaryGetValue(entitlements
, targetEntitlement
);
41 if (originalValue
!= NULL
&& newValue
== NULL
) {
48 bool needsCatalystEntitlementFixup(CFDictionaryRef entitlements
)
50 return entitlementNeedsFixup(entitlements
, CFSTR("application-identifier"), CFSTR("com.apple.application-identifier")) ||
51 entitlementNeedsFixup(entitlements
, CFSTR("aps-environment"), CFSTR("com.apple.developer.aps-environment"));
54 bool updateCatalystEntitlements(CFMutableDictionaryRef entitlements
)
57 if (entitlementNeedsFixup(entitlements
, CFSTR("application-identifier"), CFSTR("com.apple.application-identifier"))) {
58 transferEntitlement(entitlements
, CFSTR("application-identifier"), CFSTR("com.apple.application-identifier"));
61 if (entitlementNeedsFixup(entitlements
, CFSTR("aps-environment"), CFSTR("com.apple.developer.aps-environment"))) {
62 transferEntitlement(entitlements
, CFSTR("aps-environment"), CFSTR("com.apple.developer.aps-environment"));