]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OTCuttlefishContext.h
Security-59306.11.20.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/escrowrequest/Framework/SecEscrowRequest.h"
52
53 #import <CoreCDP/CDPAccount.h>
54
55 #import "keychain/ckks/CKKSLockStateTracker.h"
56 #import "keychain/ckks/CKKSViewManager.h"
57 #import "keychain/ckks/CKKSKeychainView.h"
58
59 NS_ASSUME_NONNULL_BEGIN
60
61 @interface OTCuttlefishContext : NSObject <OctagonCuttlefishUpdateReceiver,
62 OTAuthKitAdapterNotifier,
63 OctagonStateMachineEngine,
64 CKKSCloudKitAccountStateListener,
65 CKKSPeerUpdateListener>
66
67 @property (readonly) id<NSXPCProxyCreating> cuttlefishXPCConnection;
68 @property (readonly) OTFollowup *followupHandler;
69
70 @property (readonly) NSString *containerName;
71 @property (readonly) NSString *contextID;
72 @property (readonly) NSString *altDSID;
73 @property (nonatomic,strong) NSString *_Nullable pairingUUID;
74 @property (nonatomic, readonly) CKKSLockStateTracker *lockStateTracker;
75 @property (nonatomic, readonly) OTCuttlefishAccountStateHolder* accountMetadataStore;
76 @property (readonly) OctagonStateMachine* stateMachine;
77 @property (readonly) BOOL postedRepairCFU;
78 @property (readonly) BOOL postedEscrowRepairCFU;
79 @property (readonly) BOOL postedRecoveryKeyCFU;
80 @property (nullable, nonatomic) CKKSNearFutureScheduler* apsRateLimiter;
81
82 @property (readonly, nullable) CKKSViewManager* viewManager;
83
84 // Dependencies (for injection)
85 @property id<OTAuthKitAdapter> authKitAdapter;
86
87 @property dispatch_queue_t queue;
88
89 - (instancetype)initWithContainerName:(NSString*)containerName
90 contextID:(NSString*)contextID
91 cuttlefish:(id<NSXPCProxyCreating>)cuttlefish
92 sosAdapter:(id<OTSOSAdapter>)sosAdapter
93 authKitAdapter:(id<OTAuthKitAdapter>)authKitAdapter
94 ckksViewManager:(CKKSViewManager* _Nullable)viewManager
95 lockStateTracker:(CKKSLockStateTracker*)lockStateTracker
96 accountStateTracker:(id<CKKSCloudKitAccountStateTrackingProvider, CKKSOctagonStatusMemoizer>)accountStateTracker
97 deviceInformationAdapter:(id<OTDeviceInformationAdapter>)deviceInformationAdapter
98 apsConnectionClass:(Class<OctagonAPSConnection>)apsConnectionClass
99 escrowRequestClass:(Class<SecEscrowRequestable>)escrowRequestClass
100 cdpd:(id<OctagonFollowUpControllerProtocol>)cdpd;
101
102 // Call one of these when the account state changes. OTCuttlefishContext is responsible for maintaining this state across daemon restarts.
103 - (BOOL)accountAvailable:(NSString*)altDSID error:(NSError**)error;
104 - (BOOL)accountNoLongerAvailable:(NSError**)error;
105 - (BOOL)idmsTrustLevelChanged:(NSError**)error;
106
107 - (void)startOctagonStateMachine;
108 - (void)handlePairingRestart:(OTJoiningConfiguration*)config;
109
110 - (void)rpcPrepareIdentityAsApplicantWithConfiguration:(OTJoiningConfiguration*)config
111 epoch:(uint64_t)epoch
112 reply:(void (^)(NSString * _Nullable peerID,
113 NSData * _Nullable permanentInfo,
114 NSData * _Nullable permanentInfoSig,
115 NSData * _Nullable stableInfo,
116 NSData * _Nullable stableInfoSig,
117 NSError * _Nullable error))reply;
118 - (void)rpcJoin:(NSData*)vouchData
119 vouchSig:(NSData*)vouchSig
120 preapprovedKeys:(NSArray<NSData*>* _Nullable)preapprovedKeys
121 reply:(void (^)(NSError * _Nullable error))reply;
122
123 - (void)rpcResetAndEstablish:(nonnull void (^)(NSError * _Nullable))reply;
124
125 - (void)localReset:(nonnull void (^)(NSError * _Nullable))reply;
126
127 - (void)rpcEstablish:(nonnull NSString *)altDSID
128 reply:(nonnull void (^)(NSError * _Nullable))reply;
129
130 - (void)rpcLeaveClique:(nonnull void (^)(NSError * _Nullable))reply;
131
132
133 -(void)joinWithBottle:(NSString*)bottleID
134 entropy:(NSData *)entropy
135 bottleSalt:(NSString *)bottleSalt
136 reply:(void (^)(NSError * _Nullable error))reply;
137
138 -(void)joinWithRecoveryKey:(NSString*)recoveryKey
139 reply:(void (^)(NSError * _Nullable error))reply;
140
141 - (void)rpcRemoveFriendsInClique:(NSArray<NSString*>*)peerIDs
142 reply:(void (^)(NSError*))reply;
143
144 - (void)notifyContainerChange:(APSIncomingMessage* _Nullable)notification;
145 - (void)notifyContainerChangeWithUserInfo:(NSDictionary*)userInfo;
146
147 - (void)rpcStatus:(void (^)(NSDictionary* _Nullable result, NSError* _Nullable error))reply;
148 - (void)rpcFetchEgoPeerID:(void (^)(NSString* _Nullable peerID, NSError* _Nullable error))reply;
149 - (void)rpcTrustStatus:(OTOperationConfiguration *)configuration
150 reply:(void (^)(CliqueStatus status,
151 NSString* _Nullable peerID,
152 NSDictionary<NSString*, NSNumber*>* _Nullable peerCountByModelID,
153 BOOL isExcluded,
154 NSError * _Nullable))reply;
155 - (void)rpcFetchDeviceNamesByPeerID:(void (^)(NSDictionary<NSString*, NSString*>* _Nullable peers, NSError* _Nullable error))reply;
156 - (void)rpcFetchAllViableBottles:(void (^)(NSArray<NSString*>* _Nullable sortedBottleIDs, NSArray<NSString*>* _Nullable sortedPartialEscrowRecordIDs, NSError* _Nullable error))reply;
157 - (void)fetchEscrowContents:(void (^)(NSData* _Nullable entropy,
158 NSString* _Nullable bottleID,
159 NSData* _Nullable signingPublicKey,
160 NSError* _Nullable error))reply;
161 - (void)rpcSetRecoveryKey:(NSString*)recoveryKey reply:(void (^)(NSError * _Nullable error))reply;
162
163 - (void)requestTrustedDeviceListRefresh;
164
165 - (OTDeviceInformation*)prepareInformation;
166
167 // called when circle changed notification fires
168 - (void) moveToCheckTrustedState;
169
170 - (OTOperationDependencies*)operationDependencies;
171
172 - (void)attemptSOSUpgrade:(void (^)(NSError* _Nullable error))reply;
173
174 - (void)waitForOctagonUpgrade:(void (^)(NSError* error))reply;
175
176 - (void)clearPendingCFUFlags;
177
178 // For testing.
179 - (void)setPostedBool:(BOOL)posted;
180 - (OTAccountMetadataClassC_AccountState)currentMemoizedAccountState;
181 - (OTAccountMetadataClassC_TrustState)currentMemoizedTrustState;
182 - (NSDate* _Nullable) currentMemoizedLastHealthCheck;
183 - (void) checkTrustStatusAndPostRepairCFUIfNecessary:(void (^ _Nullable)(CliqueStatus status, BOOL posted, BOOL hasIdentity, NSError * _Nullable error))reply;
184 - (void) setAccountStateHolder:(OTCuttlefishAccountStateHolder*)accountMetadataStore;
185
186 // Octagon Health Check Helpers
187 - (void)checkOctagonHealth:(BOOL)skipRateLimitingCheck reply:(void (^)(NSError * _Nullable error))reply;
188 - (BOOL)postRepairCFU:(NSError**)error;
189 - (void)postConfirmPasscodeCFU:(NSError**)error;
190 - (void)postRecoveryKeyCFU:(NSError**)error;
191
192 @end
193
194 NS_ASSUME_NONNULL_END
195 #endif // OTCUTTLEFISH_CONTEXT
196 #endif
197