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@
25 #ifndef OTCUTTLEFISH_CONTEXT
26 #define OTCUTTLEFISH_CONTEXT
28 #import <ApplePushService/ApplePushService.h>
29 #import <Foundation/Foundation.h>
30 #import <CloudKit/CloudKit.h>
31 #import <CloudKit/CloudKit_Private.h>
33 #import "keychain/ckks/OctagonAPSReceiver.h"
34 #import "keychain/ckks/CKKSAccountStateTracker.h"
35 #import "keychain/ckks/CKKSCondition.h"
36 #import "keychain/TrustedPeersHelper/TrustedPeersHelperProtocol.h"
37 #import "OTDeviceInformation.h"
38 #import "keychain/ot/OTDefines.h"
39 #import "keychain/ot/OTClique.h"
40 #import "keychain/ot/OTFollowup.h"
41 #import "keychain/ot/OTSOSAdapter.h"
42 #import "keychain/ot/OTAuthKitAdapter.h"
43 #import "keychain/ot/OTDeviceInformationAdapter.h"
44 #import "keychain/ot/OTCuttlefishAccountStateHolder.h"
45 #import "keychain/ot/OctagonStateMachineHelpers.h"
46 #import "keychain/ot/OctagonStateMachine.h"
47 #import "keychain/ot/proto/generated_source/OTAccountMetadataClassC.h"
48 #import <KeychainCircle/PairingChannel.h>
49 #import "keychain/ot/OTJoiningConfiguration.h"
50 #import "keychain/ot/OTOperationDependencies.h"
51 #import "keychain/ot/CuttlefishXPCWrapper.h"
52 #import "keychain/escrowrequest/Framework/SecEscrowRequest.h"
54 #import <CoreCDP/CDPAccount.h>
56 #import "keychain/ckks/CKKSLockStateTracker.h"
57 #import "keychain/ckks/CKKSViewManager.h"
58 #import "keychain/ckks/CKKSKeychainView.h"
60 NS_ASSUME_NONNULL_BEGIN
62 @interface OTCuttlefishContext
: NSObject
<OctagonCuttlefishUpdateReceiver
,
63 OTAuthKitAdapterNotifier
,
64 OctagonStateMachineEngine
,
65 CKKSCloudKitAccountStateListener
,
66 CKKSPeerUpdateListener
,
67 OTDeviceInformationNameUpdateListener
>
69 @
property (readonly
) CuttlefishXPCWrapper
* cuttlefishXPCWrapper
;
70 @
property (readonly
) OTFollowup
*followupHandler
;
72 @
property (readonly
) NSString
*containerName
;
73 @
property (readonly
) NSString
*contextID
;
74 @
property (readonly
) NSString
*altDSID
;
75 @
property (nonatomic
,strong
) NSString
*_Nullable pairingUUID
;
76 @
property (nonatomic
, readonly
) CKKSLockStateTracker
*lockStateTracker
;
77 @
property (nonatomic
, readonly
) OTCuttlefishAccountStateHolder
* accountMetadataStore
;
78 @
property (readonly
) OctagonStateMachine
* stateMachine
;
79 @
property (readonly
) BOOL postedRepairCFU
;
80 @
property (readonly
) BOOL postedEscrowRepairCFU
;
81 @
property (readonly
) BOOL postedRecoveryKeyCFU
;
82 @
property (nullable
, nonatomic
) CKKSNearFutureScheduler
* apsRateLimiter
;
83 @
property (nullable
, nonatomic
) CKKSNearFutureScheduler
* sosConsistencyRateLimiter
;
85 @
property (readonly
, nullable
) CKKSViewManager
* viewManager
;
87 // Dependencies (for injection)
88 @property id
<OTAuthKitAdapter
> authKitAdapter
;
90 @property dispatch_queue_t queue
;
92 - (instancetype
)initWithContainerName
:(NSString
*)containerName
93 contextID
:(NSString
*)contextID
94 cuttlefish
:(id
<NSXPCProxyCreating
>)cuttlefish
95 sosAdapter
:(id
<OTSOSAdapter
>)sosAdapter
96 authKitAdapter
:(id
<OTAuthKitAdapter
>)authKitAdapter
97 ckksViewManager
:(CKKSViewManager
* _Nullable
)viewManager
98 lockStateTracker
:(CKKSLockStateTracker
*)lockStateTracker
99 accountStateTracker
:(id
<CKKSCloudKitAccountStateTrackingProvider
, CKKSOctagonStatusMemoizer
>)accountStateTracker
100 deviceInformationAdapter
:(id
<OTDeviceInformationAdapter
>)deviceInformationAdapter
101 apsConnectionClass
:(Class
<OctagonAPSConnection
>)apsConnectionClass
102 escrowRequestClass
:(Class
<SecEscrowRequestable
>)escrowRequestClass
103 cdpd
:(id
<OctagonFollowUpControllerProtocol
>)cdpd
;
105 // Call one of these when the account state changes. OTCuttlefishContext is responsible for maintaining this state across daemon restarts.
106 - (BOOL
)accountAvailable
:(NSString
*)altDSID error
:(NSError
**)error
;
107 - (BOOL
)accountNoLongerAvailable
:(NSError
**)error
;
108 - (BOOL
)idmsTrustLevelChanged
:(NSError
**)error
;
110 - (void)deviceNameUpdated
;
112 - (void)startOctagonStateMachine
;
113 - (void)handlePairingRestart
:(OTJoiningConfiguration
*)config
;
115 - (void)rpcPrepareIdentityAsApplicantWithConfiguration
:(OTJoiningConfiguration
*)config
116 epoch
:(uint64_t)epoch
117 reply
:(void (^)(NSString
* _Nullable peerID
,
118 NSData
* _Nullable permanentInfo
,
119 NSData
* _Nullable permanentInfoSig
,
120 NSData
* _Nullable stableInfo
,
121 NSData
* _Nullable stableInfoSig
,
122 NSError
* _Nullable error
))reply
;
123 - (void)rpcJoin
:(NSData
*)vouchData
124 vouchSig
:(NSData
*)vouchSig
125 preapprovedKeys
:(NSArray
<NSData
*>* _Nullable
)preapprovedKeys
126 reply
:(void (^)(NSError
* _Nullable error
))reply
;
128 - (void)rpcResetAndEstablish
:(CuttlefishResetReason
)resetReason reply
:(nonnull
void (^)(NSError
* _Nullable
))reply
;
130 - (void)localReset
:(nonnull
void (^)(NSError
* _Nullable
))reply
;
132 - (void)rpcEstablish
:(nonnull NSString
*)altDSID
133 reply
:(nonnull
void (^)(NSError
* _Nullable
))reply
;
135 - (void)rpcLeaveClique
:(nonnull
void (^)(NSError
* _Nullable
))reply
;
138 -(void)joinWithBottle
:(NSString
*)bottleID
139 entropy
:(NSData
*)entropy
140 bottleSalt
:(NSString
*)bottleSalt
141 reply
:(void (^)(NSError
* _Nullable error
))reply
;
143 -(void)joinWithRecoveryKey
:(NSString
*)recoveryKey
144 reply
:(void (^)(NSError
* _Nullable error
))reply
;
146 - (void)rpcRemoveFriendsInClique
:(NSArray
<NSString
*>*)peerIDs
147 reply
:(void (^)(NSError
* _Nullable
))reply
;
149 - (void)notifyContainerChange
:(APSIncomingMessage
* _Nullable
)notification
;
150 - (void)notifyContainerChangeWithUserInfo
:(NSDictionary
*)userInfo
;
152 - (void)rpcStatus
:(void (^)(NSDictionary
* _Nullable result
, NSError
* _Nullable error
))reply
;
153 - (void)rpcFetchEgoPeerID
:(void (^)(NSString
* _Nullable peerID
, NSError
* _Nullable error
))reply
;
154 - (void)rpcTrustStatus
:(OTOperationConfiguration
*)configuration
155 reply
:(void (^)(CliqueStatus status
,
156 NSString
* _Nullable peerID
,
157 NSDictionary
<NSString
*, NSNumber
*>* _Nullable peerCountByModelID
,
159 NSError
* _Nullable
))reply
;
160 - (void)rpcFetchDeviceNamesByPeerID
:(void (^)(NSDictionary
<NSString
*, NSString
*>* _Nullable peers
, NSError
* _Nullable error
))reply
;
161 - (void)rpcFetchAllViableBottles
:(void (^)(NSArray
<NSString
*>* _Nullable sortedBottleIDs
, NSArray
<NSString
*>* _Nullable sortedPartialEscrowRecordIDs
, NSError
* _Nullable error
))reply
;
162 - (void)fetchEscrowContents
:(void (^)(NSData
* _Nullable entropy
,
163 NSString
* _Nullable bottleID
,
164 NSData
* _Nullable signingPublicKey
,
165 NSError
* _Nullable error
))reply
;
166 - (void)rpcSetRecoveryKey
:(NSString
*)recoveryKey reply
:(void (^)(NSError
* _Nullable error
))reply
;
168 - (void)requestTrustedDeviceListRefresh
;
170 - (OTDeviceInformation
*)prepareInformation
;
172 // called when circle changed notification fires
173 - (void) moveToCheckTrustedState
;
175 - (OTOperationDependencies
*)operationDependencies
;
177 - (void)attemptSOSUpgrade
:(void (^)(NSError
* _Nullable error
))reply
;
179 - (void)waitForOctagonUpgrade
:(void (^)(NSError
* error
))reply
NS_SWIFT_NAME(waitForOctagonUpgrade(reply
:));
181 - (void)clearPendingCFUFlags
;
183 - (BOOL
)waitForReady
:(int64_t)timeOffset
;
187 - (void)setPostedBool
:(BOOL
)posted
;
188 - (OTAccountMetadataClassC_AccountState
)currentMemoizedAccountState
;
189 - (OTAccountMetadataClassC_TrustState
)currentMemoizedTrustState
;
190 - (NSDate
* _Nullable
) currentMemoizedLastHealthCheck
;
191 - (void) checkTrustStatusAndPostRepairCFUIfNecessary
:(void (^ _Nullable
)(CliqueStatus status
, BOOL posted
, BOOL hasIdentity
, NSError
* _Nullable error
))reply
;
192 - (void) setAccountStateHolder
:(OTCuttlefishAccountStateHolder
*)accountMetadataStore
;
194 // Octagon Health Check Helpers
195 - (void)checkOctagonHealth
:(BOOL
)skipRateLimitingCheck reply
:(void (^)(NSError
* _Nullable error
))reply
;
196 - (BOOL
)postRepairCFU
:(NSError
**)error
;
197 - (void)postConfirmPasscodeCFU
:(NSError
**)error
;
198 - (void)postRecoveryKeyCFU
:(NSError
**)error
;
202 NS_ASSUME_NONNULL_END
203 #endif // OTCUTTLEFISH_CONTEXT