2 * Copyright (c) 2017 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 <TargetConditionals.h>
26 #include <MobileGestalt.h>
29 #import <os/feature_private.h>
31 #import "keychain/ot/OTConstants.h"
32 #import "utilities/debugging.h"
34 NSString* const OctagonErrorDomain = @"com.apple.security.octagon";
36 NSString* OTDefaultContext = @"defaultContext";
37 NSString* OTDefaultsDomain = @"com.apple.security.octagon";
38 NSString* OTDefaultsOctagonEnable = @"enable";
40 NSString* OTProtocolPairing = @"OctagonPairing";
41 NSString* OTProtocolPiggybacking = @"OctagonPiggybacking";
43 const char * OTTrustStatusChangeNotification = "com.apple.security.octagon.trust-status-change";
45 // I don't recommend using this command, but it does describe the plist that will enable this feature:
47 // defaults write /System/Library/FeatureFlags/Domain/Security octagon -dict Enabled -bool YES
49 static bool OctagonEnabledOverrideSet = false;
50 static bool OctagonEnabledOverride = false;
52 static bool OctagonRecoveryKeyEnabledOverrideSet = false;
53 static bool OctagonRecoveryKeyEnabledOverride = false;
55 static bool OctagonAuthoritativeTrustEnabledOverrideSet = false;
56 static bool OctagonAuthoritativeTrustEnabledOverride = false;
58 static bool OctagonSOSFeatureIsEnabledOverrideSet = false;
59 static bool OctagonSOSFeatureIsEnabledOverride = false;
61 bool OctagonIsEnabled(void)
63 if(OctagonEnabledOverrideSet) {
64 secnotice("octagon", "Octagon is %@ (overridden)", OctagonEnabledOverride ? @"enabled" : @"disabled");
65 return OctagonEnabledOverride;
68 static bool octagonEnabled = false;
69 static dispatch_once_t onceToken;
70 dispatch_once(&onceToken, ^{
71 octagonEnabled = os_feature_enabled(Security, octagon);
72 secnotice("octagon", "Octagon is %@ (via feature flags)", octagonEnabled ? @"enabled" : @"disabled");
75 return octagonEnabled;
78 void OctagonSetIsEnabled(BOOL value)
80 OctagonEnabledOverrideSet = true;
81 OctagonEnabledOverride = value;
84 static bool OctagonOverridePlatformSOS = false;
85 static bool OctagonPlatformSOSOverrideValue = false;
86 static bool OctagonPlatformSOSUpgrade = false;
88 BOOL OctagonPlatformSupportsSOS(void)
90 if(OctagonOverridePlatformSOS) {
91 return OctagonPlatformSOSOverrideValue ? YES : NO;
97 static bool isSOSCapable = false;
99 static dispatch_once_t onceToken;
100 dispatch_once(&onceToken, ^{
101 // Only iPhones, iPads, and iPods support SOS.
102 CFStringRef deviceClass = MGCopyAnswer(kMGQDeviceClass, NULL);
104 isSOSCapable = deviceClass && (CFEqual(deviceClass, kMGDeviceClassiPhone) ||
105 CFEqual(deviceClass, kMGDeviceClassiPad) ||
106 CFEqual(deviceClass, kMGDeviceClassiPod));
109 CFRelease(deviceClass);
111 secerror("octagon: Unable to determine device class. Guessing SOS status as Not Supported");
112 isSOSCapable = false;
115 secnotice("octagon", "SOS is %@ on this platform" , isSOSCapable ? @"supported" : @"not supported");
118 return isSOSCapable ? YES : NO;
124 void OctagonSetPlatformSupportsSOS(BOOL value)
126 OctagonPlatformSOSOverrideValue = value;
127 OctagonOverridePlatformSOS = YES;
130 void OctagonSetSOSUpgrade(BOOL value)
132 OctagonPlatformSOSUpgrade = value;
135 BOOL OctagonPerformSOSUpgrade()
137 if(OctagonPlatformSOSUpgrade){
138 return OctagonPlatformSOSUpgrade;
140 return os_feature_enabled(Security, octagonSOSupgrade);
143 BOOL OctagonRecoveryKeyIsEnabled(void)
145 if(OctagonRecoveryKeyEnabledOverrideSet) {
146 secnotice("octagon", "Octagon RecoveryKey is %@ (overridden)", OctagonRecoveryKeyEnabledOverride ? @"enabled" : @"disabled");
147 return OctagonRecoveryKeyEnabledOverride;
150 static bool octagonRecoveryKeyEnabled = false;
151 static dispatch_once_t onceToken;
152 dispatch_once(&onceToken, ^{
153 octagonRecoveryKeyEnabled = os_feature_enabled(Security, recoverykey);
154 secnotice("octagon", "Octagon is %@ (via feature flags)", octagonRecoveryKeyEnabled ? @"enabled" : @"disabled");
157 return octagonRecoveryKeyEnabled;
160 void OctagonRecoveryKeySetIsEnabled(BOOL value)
162 OctagonRecoveryKeyEnabledOverrideSet = true;
163 OctagonRecoveryKeyEnabledOverride = value;
167 BOOL OctagonAuthoritativeTrustIsEnabled(void)
169 if(OctagonAuthoritativeTrustEnabledOverrideSet) {
170 secnotice("octagon", "Authoritative Octagon Trust is %@ (overridden)", OctagonAuthoritativeTrustEnabledOverride ? @"enabled" : @"disabled");
171 return OctagonAuthoritativeTrustEnabledOverride;
174 static bool octagonAuthoritativeTrustEnabled = false;
175 static dispatch_once_t onceToken;
176 dispatch_once(&onceToken, ^{
177 octagonAuthoritativeTrustEnabled = os_feature_enabled(Security, octagonTrust);
178 secnotice("octagon", "Authoritative Octagon Trust is %@ (via feature flags)", octagonAuthoritativeTrustEnabled ? @"enabled" : @"disabled");
181 return octagonAuthoritativeTrustEnabled;
184 void OctagonAuthoritativeTrustSetIsEnabled(BOOL value)
186 OctagonAuthoritativeTrustEnabledOverrideSet = true;
187 OctagonAuthoritativeTrustEnabledOverride = value;
190 BOOL OctagonIsSOSFeatureEnabled(void)
192 if(OctagonSOSFeatureIsEnabledOverrideSet) {
193 secnotice("octagon", "SOS Feature is %@ (overridden)", OctagonSOSFeatureIsEnabledOverride ? @"enabled" : @"disabled");
194 return OctagonSOSFeatureIsEnabledOverrideSet;
197 static bool sosEnabled = true;
198 static dispatch_once_t onceToken;
199 dispatch_once(&onceToken, ^{
200 sosEnabled = os_feature_enabled(Security, EnableSecureObjectSync);
201 secnotice("octagon", "SOS Feature is %@ (via feature flags)", sosEnabled ? @"enabled" : @"disabled");
207 void OctagonSetSOSFeatureEnabled(BOOL value)
209 OctagonSOSFeatureIsEnabledOverrideSet = true;
210 OctagonSOSFeatureIsEnabledOverride = value;