]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OTCuttlefishContext.h
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / ot / OTCuttlefishContext.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #if OCTAGON
25 #ifndef OTCUTTLEFISH_CONTEXT
26 #define OTCUTTLEFISH_CONTEXT
27
28 #import <ApplePushService/ApplePushService.h>
29 #import <Foundation/Foundation.h>
30 #import <CloudKit/CloudKit.h>
31 #import <CloudKit/CloudKit_Private.h>
32
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"
53
54 #import <CoreCDP/CDPAccount.h>
55
56 #import "keychain/ckks/CKKSLockStateTracker.h"
57 #import "keychain/ckks/CKKSViewManager.h"
58 #import "keychain/ckks/CKKSKeychainView.h"
59
60 NS_ASSUME_NONNULL_BEGIN
61
62 @interface OTCuttlefishContext : NSObject <OctagonCuttlefishUpdateReceiver,
63 OTAuthKitAdapterNotifier,
64 OctagonStateMachineEngine,
65 CKKSCloudKitAccountStateListener,
66 CKKSPeerUpdateListener,
67 OTDeviceInformationNameUpdateListener>
68
69 @property (readonly) CuttlefishXPCWrapper* cuttlefishXPCWrapper;
70 @property (readonly) OTFollowup *followupHandler;
71
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;
84
85 @property (readonly, nullable) CKKSViewManager* viewManager;
86
87 // Dependencies (for injection)
88 @property id<OTAuthKitAdapter> authKitAdapter;
89
90 @property dispatch_queue_t queue;
91
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;
104
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;
109
110 - (void)deviceNameUpdated;
111
112 - (void)startOctagonStateMachine;
113 - (void)handlePairingRestart:(OTJoiningConfiguration*)config;
114
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;
127
128 - (void)rpcResetAndEstablish:(CuttlefishResetReason)resetReason reply:(nonnull void (^)(NSError * _Nullable))reply;
129
130 - (void)localReset:(nonnull void (^)(NSError * _Nullable))reply;
131
132 - (void)rpcEstablish:(nonnull NSString *)altDSID
133 reply:(nonnull void (^)(NSError * _Nullable))reply;
134
135 - (void)rpcLeaveClique:(nonnull void (^)(NSError * _Nullable))reply;
136
137
138 -(void)joinWithBottle:(NSString*)bottleID
139 entropy:(NSData *)entropy
140 bottleSalt:(NSString *)bottleSalt
141 reply:(void (^)(NSError * _Nullable error))reply;
142
143 -(void)joinWithRecoveryKey:(NSString*)recoveryKey
144 reply:(void (^)(NSError * _Nullable error))reply;
145
146 - (void)rpcRemoveFriendsInClique:(NSArray<NSString*>*)peerIDs
147 reply:(void (^)(NSError * _Nullable))reply;
148
149 - (void)notifyContainerChange:(APSIncomingMessage* _Nullable)notification;
150 - (void)notifyContainerChangeWithUserInfo:(NSDictionary*)userInfo;
151
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,
158 BOOL isExcluded,
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;
167
168 - (void)requestTrustedDeviceListRefresh;
169
170 - (OTDeviceInformation*)prepareInformation;
171
172 // called when circle changed notification fires
173 - (void) moveToCheckTrustedState;
174
175 - (OTOperationDependencies*)operationDependencies;
176
177 - (void)attemptSOSUpgrade:(void (^)(NSError* _Nullable error))reply;
178
179 - (void)waitForOctagonUpgrade:(void (^)(NSError* error))reply NS_SWIFT_NAME(waitForOctagonUpgrade(reply:));
180
181 - (void)clearPendingCFUFlags;
182
183 - (BOOL)waitForReady:(int64_t)timeOffset;
184
185
186 // For testing.
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;
193
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;
199
200 @end
201
202 NS_ASSUME_NONNULL_END
203 #endif // OTCUTTLEFISH_CONTEXT
204 #endif
205