2 * Copyright (c) 2018 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@
28 typedef NS_ENUM(NSInteger
, CliqueStatus
) {
29 CliqueStatusIn
= 0, /*There is a clique and I am in it*/
30 CliqueStatusNotIn
= 1, /*There is a clique and I am not in it - you should get a voucher to join or tell another peer to trust us*/
31 CliqueStatusPending
= 2, /*For compatibility, keeping the pending state */
32 CliqueStatusAbsent
= 3, /*There is no clique - you can establish one */
33 CliqueStatusNoCloudKitAccount
= 4, /* no cloudkit account present */
34 CliqueStatusError
= -1 /*unable to determine circle status, inspect CFError to find out why */
37 #import <Security/SecRecoveryKey.h>
41 #import <Foundation/Foundation.h>
42 #import <Security/SecureObjectSync/SOSCloudCircleInternal.h>
43 #import <Security/SecureObjectSync/SOSPeerInfo.h>
44 #import <Security/SecureObjectSync/SOSTypes.h>
45 #import <Security/OTConstants.h>
47 typedef NS_ENUM(NSInteger
, OTCDPStatus
) {
48 OTCDPStatusUnknown
= 0,
49 OTCDPStatusDisabled
= 1,
50 OTCDPStatusEnabled
= 2,
53 NS_ASSUME_NONNULL_BEGIN
55 NSString
* OTCliqueStatusToString(CliqueStatus status
);
56 CliqueStatus
OTCliqueStatusFromString(NSString
* str
);
57 NSString
* OTCDPStatusToString(OTCDPStatus status
);
59 @
class KCPairingChannelContext
;
60 @
class KCPairingChannel
;
61 @
class OTPairingChannel
;
62 @
class OTPairingChannelContext
;
66 extern NSString
* kSecEntitlementPrivateOctagonEscrow
;
68 @interface OTConfigurationContext
: NSObject
69 @
property (nonatomic
, copy
) NSString
* context
;
70 @
property (nonatomic
, copy
, nullable
) NSString
* dsid
;
71 @
property (nonatomic
, copy
, nullable
) NSString
* altDSID
;
72 @
property (nonatomic
, strong
, nullable
) SFSignInAnalytics
* analytics
;
73 @
property (nonatomic
, copy
, nullable
) NSString
* authenticationAppleID
;
74 @
property (nonatomic
, copy
, nullable
) NSString
* passwordEquivalentToken
;
76 // Use this to inject your own OTControl object. It must be configured as synchronous.
77 @
property (nullable
, strong
) OTControl
* otControl
;
79 // Use this to inject your own CKKSControl object. It must be configured as synchronous.
80 @
property (nullable
, strong
) CKKSControl
* ckksControl
;
82 // Use this to inject your own SecureBackup object. It must conform to the OctagonEscrowRecoverer protocol.
83 @
property (nullable
, strong
) id sbd
;
85 // Create a new synchronous OTControl if one doesn't already exist in context.
86 - (OTControl
* _Nullable
)makeOTControl
:(NSError
**)error
;
89 // OTBottleIDs: an Obj-C Tuple
91 @interface OTBottleIDs
: NSObject
92 @
property (strong
) NSArray
<NSString
*>* preferredBottleIDs
;
93 @
property (strong
) NSArray
<NSString
*>* partialRecoveryBottleIDs
;
96 @interface OTOperationConfiguration
: NSObject
<NSSecureCoding
>
97 @
property (nonatomic
, assign
) uint64_t timeoutWaitForCKAccount
;
98 @
property (nonatomic
, assign
) NSQualityOfService qualityOfService
;
99 @
property (nonatomic
, assign
) BOOL discretionaryNetwork
;
100 @
property (nonatomic
, assign
) BOOL useCachedAccountStatus
;
103 typedef NSString
* OTCliqueCDPContextType NS_STRING_ENUM
;
104 extern OTCliqueCDPContextType OTCliqueCDPContextTypeNone
;
105 extern OTCliqueCDPContextType OTCliqueCDPContextTypeSignIn
;
106 extern OTCliqueCDPContextType OTCliqueCDPContextTypeRepair
;
107 extern OTCliqueCDPContextType OTCliqueCDPContextTypeFinishPasscodeChange
;
108 extern OTCliqueCDPContextType OTCliqueCDPContextTypeRecoveryKeyGenerate
;
109 extern OTCliqueCDPContextType OTCliqueCDPContextTypeRecoveryKeyNew
;
110 extern OTCliqueCDPContextType OTCliqueCDPContextTypeUpdatePasscode
;
115 @interface OTClique
: NSObject
117 + (BOOL
)platformSupportsSOS
;
119 @
property (nonatomic
, readonly
, nullable
) NSString
* cliqueMemberIdentifier
;
121 - (instancetype
) init NS_UNAVAILABLE
;
126 * @abstract, initializes a clique object given a context. A clique object enables octagon trust operations for a given context and dsid.
127 * @param ctx, a collection of arguments describing the world
128 * @return an instance of octagon trust
130 - (instancetype
)initWithContextData
:(OTConfigurationContext
*)ctx
;
133 * Much like initWithContextData, but might fail. There are currently no failures possible.
135 - (instancetype _Nullable
)initWithContextData
:(OTConfigurationContext
*)ctx error
:(NSError
**)error
__deprecated_msg("Use initWithContextData instead");
138 * @abstract Establish a new clique, reset protected data
141 * Delete all CKKS data
143 * @param ctx, context containing parameters to setup OTClique
144 * @return clique, returns a new clique instance
145 * @param error, error gets filled if something goes horribly wrong
147 + (instancetype _Nullable
)newFriendsWithContextData
:(OTConfigurationContext
*)data error
:(NSError
* __autoreleasing
*)error
__deprecated_msg("use newFriendsWithContextData:resetReason:error: instead");
150 * @abstract Establish a new clique, reset protected data
153 * Delete all CKKS data
155 * @param ctx, context containing parameters to setup OTClique
156 * @param resetReason, a reason that drives cdp to perform a reset
157 * @return clique, returns a new clique instance
158 * @param error, error gets filled if something goes horribly wrong
160 + (instancetype _Nullable
)newFriendsWithContextData
:(OTConfigurationContext
*)data resetReason
:(CuttlefishResetReason
)resetReason error
:(NSError
* __autoreleasing
*)error
;
163 * @abstract Perform a SecureBackup escrow/keychain recovery and attempt to use the information therein to join this account.
164 * You do not need to call joinAfterRestore after calling this method.
165 * @param data The OTClique configuration data
166 * @param sbdRecoveryArguments the grab bag of things you'd normally pass to SecureBackup's recoverWithInfo.
167 * @param error Reports any error along the process, including 'incorrect secret' and 'couldn't rejoin account'.
168 * @return a fresh new OTClique, if the account rejoin was successful. Otherwise, nil.
170 + (OTClique
* _Nullable
)performEscrowRecoveryWithContextData
:(OTConfigurationContext
*)data
171 escrowArguments
:(NSDictionary
*)sbdRecoveryArguments
172 error
:(NSError
**)error
;
175 * @abstract Create pairing channel with
177 * @param ctx, context containing parameters to setup the pairing channel as the initiator
178 * @return KCPairingChannel, An instance of a KCPairingCHannel
180 - (KCPairingChannel
*)setupPairingChannelAsInitiator
:(KCPairingChannelContext
*)ctx
;
182 - (KCPairingChannel
* _Nullable
)setupPairingChannelAsInitator
:(KCPairingChannelContext
*)ctx error
:(NSError
* __autoreleasing
*)error
__deprecated_msg("setupPairingChannelAsInitiator:error: deprecated, use setupPairingChannelAsInitiator:");
185 * @abstract Configure this peer as the acceptor during piggybacking
187 * @param ctx, context containing parameters to setup the pairing channel as the acceptor
188 * @return KCPairingChannel, An instance of a KCPairingChannel
190 - (KCPairingChannel
*)setupPairingChannelAsAcceptor
:(KCPairingChannelContext
*)ctx
;
192 - (KCPairingChannel
* _Nullable
)setupPairingChannelAsAcceptor
:(KCPairingChannelContext
*)ctx error
:(NSError
* __autoreleasing
*)error
__deprecated_msg("setupPairingChannelAsAcceptor:error: deprecated, use setupPairingChannelAsAcceptor:");
195 * @abstract Get the cached status of clique - returns one of:
196 * There is no clique - you can establish one
197 * There is a clique and I am not in it - you should get a voucher to join or tell another peer to trust us
198 * There is a clique and I am in it
199 * @param error, error gets filled if something goes horribly wrong
200 * @return cached cliqueStatus, value will represent one of the above
202 - (CliqueStatus
)cachedCliqueStatus
:(BOOL
)useCached error
:(NSError
* __autoreleasing
*)error
203 __deprecated_msg("use fetchCliqueStatus:");
206 * @abstract Get status of clique - returns one of:
207 * There is no clique - you can establish one
208 * There is a clique and I am not in it - you should get a voucher to join or tell another peer to trust us
209 * There is a clique and I am in it
210 * @param error, error gets filled if something goes horribly wrong
211 * @return cliqueStatus, value will represent one of the above
213 - (CliqueStatus
)fetchCliqueStatus
:(NSError
* __autoreleasing
* _Nonnull
)error
;
216 * @abstract Get status of clique - returns one of:
217 * There is no clique - you can establish one
218 * There is a clique and I am not in it - you should get a voucher to join or tell another peer to trust us
219 * There is a clique and I am in it
220 * @param configuration, behavior of operations performed follow up this operation
221 * @param error, error gets filled if something goes horribly wrong
222 * @return cliqueStatus, value will represent one of the above
224 - (CliqueStatus
)fetchCliqueStatus
:(OTOperationConfiguration
*)configuration error
:(NSError
* __autoreleasing
* _Nonnull
)error
;
227 * @abstract Exclude given a member identifier
228 * @param friendIdentifiers, friends to remove
229 * @param error, error gets filled if something goes horribly wrong
230 * @return BOOL, YES if successful. No if call failed.
232 - (BOOL
)removeFriendsInClique
:(NSArray
<NSString
*>*)friendIdentifiers error
:(NSError
* __autoreleasing
*)error
;
235 * @abstract Depart (exclude self)
236 * Un-enroll from escrow
237 * @param error, error gets filled if something goes horribly wrong
238 * @return BOOL, YES if successful. No if call failed.
240 - (BOOL
)leaveClique
:(NSError
* __autoreleasing
*)error
;
243 * @abstract Get list of peerIDs and device names
244 * @param error, error gets filled if something goes horribly wrong
245 * @return friends, list of peer ids and their mapping to device names of all devices currently in the clique,
246 * ex: NSDictionary[peerID, device Name];
248 - (NSDictionary
<NSString
*,NSString
*>* _Nullable
)peerDeviceNamesByPeerID
:(NSError
* __autoreleasing
*)error
;
255 + (BOOL
)setCDPEnabled
:(OTConfigurationContext
*)arguments
256 error
:(NSError
* __autoreleasing
*)error
;
258 + (OTCDPStatus
)getCDPStatus
:(OTConfigurationContext
*)arguments
259 error
:(NSError
* __autoreleasing
*)error
;
263 - (BOOL
)joinAfterRestore
:(NSError
* __autoreleasing
*)error
;
265 - (BOOL
)safariPasswordSyncingEnabled
:(NSError
*__autoreleasing
*)error
;
267 - (BOOL
)isLastFriend
:(NSError
*__autoreleasing
*)error
;
269 - (BOOL
)waitForInitialSync
:(NSError
*__autoreleasing
*)error
;
271 - (NSArray
* _Nullable
)copyViewUnawarePeerInfo
:(NSError
*__autoreleasing
*)error
;
273 - (BOOL
)viewSet
:(NSSet
*)enabledViews disabledViews
:(NSSet
*)disabledViews
;
275 - (BOOL
)setUserCredentialsAndDSID
:(NSString
*)userLabel
276 password
:(NSData
*)userPassword
277 error
:(NSError
*__autoreleasing
*)error
;
279 - (BOOL
)tryUserCredentialsAndDSID
:(NSString
*)userLabel
280 password
:(NSData
*)userPassword
281 error
:(NSError
*__autoreleasing
*)error
;
283 - (NSArray
* _Nullable
)copyPeerPeerInfo
:(NSError
*__autoreleasing
*)error
;
285 - (BOOL
)peersHaveViewsEnabled
:(NSArray
<NSString
*>*)viewNames error
:(NSError
*__autoreleasing
*)error
;
287 - (BOOL
)requestToJoinCircle
:(NSError
*__autoreleasing
*)error
;
289 - (BOOL
)accountUserKeyAvailable
;
292 - (void)setPairingDefault
:(BOOL
)defaults
;
293 - (void)removePairingDefault
;
294 /* Internal/sbd only */
298 * @abstract Ask for the list of best bottle IDs to restore for this account
299 * Ideally, we will replace this with a findOptimalEscrowRecordIDsWithContextData, but we're gated on
300 * Cuttlefish being able to read EscrowProxy (to get real escrow record IDs):
301 * <rdar://problem/44618259> [CUTTLEFISH] Cuttlefish needs to call Escrow Proxy to validate unmigrated accounts
302 * @param data The OTClique configuration data
303 * @param error Reports any error along the process
304 * @return A pair of lists of escrow record IDs
306 + (OTBottleIDs
* _Nullable
)findOptimalBottleIDsWithContextData
:(OTConfigurationContext
*)data
307 error
:(NSError
**)error
;
309 // This call is a noop.
310 + (instancetype _Nullable
)recoverWithContextData
:(OTConfigurationContext
*)data
311 bottleID
:(NSString
*)bottleID
312 escrowedEntropy
:(NSData
*)entropy
313 error
:(NSError
**)error
__deprecated_msg("recoverWithContextData:bottleID:escrowedEntropy:error: deprecated, use performEscrowRecoveryWithContextData:escrowArguments:error");
315 // used by sbd to fill in the escrow record
316 // You must have the entitlement "com.apple.private.octagon.escrow-content" to use this
317 // Also known as kSecEntitlementPrivateOctagonEscrow
318 - (void)fetchEscrowContents
:(void (^)(NSData
* _Nullable entropy
,
319 NSString
* _Nullable bottleID
,
320 NSData
* _Nullable signingPublicKey
,
321 NSError
* _Nullable error
))reply
;
323 // used by sbd to enroll a recovery key in octagon
324 + (void)setNewRecoveryKeyWithData
:(OTConfigurationContext
*)ctx
325 recoveryKey
:(NSString
*)recoveryKey
326 reply
:(void(^)(SecRecoveryKey
* _Nullable rk
,
327 NSError
* _Nullable error
))reply
;
329 // used by sbd to recover octagon data by providing a
330 + (void)recoverOctagonUsingData
:(OTConfigurationContext
*)ctx
331 recoveryKey
:(NSString
*)recoveryKey
332 reply
:(void(^)(NSError
* _Nullable error
))reply
;
335 // CoreCDP will call this function when they failed to complete a successful CDP state machine run.
336 // Errors provided may be propagated from layers beneath CoreCDP, or contain the CoreCDP cause of failure.
337 - (void)performedFailureCDPStateMachineRun
:(OTCliqueCDPContextType
)type
338 error
:(NSError
* _Nullable
)error
339 reply
:(void(^)(NSError
* _Nullable error
))reply
;
341 // CoreCDP will call this function when they complete a successful CDP state machine run.
342 - (void)performedSuccessfulCDPStateMachineRun
:(OTCliqueCDPContextType
)type
343 reply
:(void(^)(NSError
* _Nullable error
))reply
;
345 // CoreCDP will call this function when they are upgrading an account from SA to HSA2
346 - (BOOL
)waitForOctagonUpgrade
:(NSError
** _Nullable
)error
;
350 * @abstract CoreCDP to call this function when they need to reset protected data.
351 * This routine resets all circles, creates a new octagon and sos circle, then puts this device into each circle.
352 * This routine does not create a new escrow record
353 * This routine will need ensure OTConfigurationContext contains appleID and passwordEquivalentToken to delete all CDP records
354 * @param data The OTClique configuration data
355 * @param error Reports any error along the process
356 * @return a new clique
358 + (OTClique
* _Nullable
)resetProtectedData
:(OTConfigurationContext
*)data error
:(NSError
**)error
;
361 NS_ASSUME_NONNULL_END
364 #endif /* OctagonTrust_h */