]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSViewManager.h
Security-58286.200.222.tar.gz
[apple/security.git] / keychain / ckks / CKKSViewManager.h
1 /*
2 * Copyright (c) 2016 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
25 #import <Foundation/Foundation.h>
26
27 #if OCTAGON
28
29 #include <securityd/SecDbItem.h>
30 #import "keychain/ckks/CKKS.h"
31 #import "keychain/ckks/CKKSAPSReceiver.h"
32 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
33 #import "keychain/ckks/CKKSCondition.h"
34 #import "keychain/ckks/CKKSControlProtocol.h"
35 #import "keychain/ckks/CKKSLockStateTracker.h"
36 #import "keychain/ckks/CKKSReachabilityTracker.h"
37 #import "keychain/ckks/CKKSNotifier.h"
38 #import "keychain/ckks/CKKSPeer.h"
39 #import "keychain/ckks/CKKSRateLimiter.h"
40 #import "keychain/ckks/CloudKitDependencies.h"
41 #import "keychain/ckks/CKKSZoneChangeFetcher.h"
42 #import "keychain/ot/OTDefines.h"
43
44 NS_ASSUME_NONNULL_BEGIN
45
46 @class CKKSKeychainView, CKKSRateLimiter;
47
48 @interface CKKSViewManager : NSObject <CKKSControlProtocol, CKKSPeerProvider>
49
50 @property CKContainer* container;
51 @property CKKSCKAccountStateTracker* accountTracker;
52 @property CKKSLockStateTracker* lockStateTracker;
53 @property CKKSReachabilityTracker *reachabilityTracker;
54 @property CKKSZoneChangeFetcher* zoneChangeFetcher;
55 @property bool initializeNewZones;
56
57 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
58 @property CKKSCondition* completedSecCKKSInitialize;
59
60 @property CKKSRateLimiter* globalRateLimiter;
61
62 - (instancetype)initCloudKitWithContainerName:(NSString*)containerName usePCS:(bool)usePCS;
63 - (instancetype)initWithContainerName:(NSString*)containerName
64 usePCS:(bool)usePCS
65 fetchRecordZoneChangesOperationClass:(Class<CKKSFetchRecordZoneChangesOperation>)fetchRecordZoneChangesOperationClass
66 fetchRecordsOperationClass:(Class<CKKSFetchRecordsOperation>)fetchRecordsOperationClass
67 queryOperationClass:(Class<CKKSQueryOperation>)queryOperationClass
68 modifySubscriptionsOperationClass:(Class<CKKSModifySubscriptionsOperation>)modifySubscriptionsOperationClass
69 modifyRecordZonesOperationClass:(Class<CKKSModifyRecordZonesOperation>)modifyRecordZonesOperationClass
70 apsConnectionClass:(Class<CKKSAPSConnection>)apsConnectionClass
71 nsnotificationCenterClass:(Class<CKKSNSNotificationCenter>)nsnotificationCenterClass
72 notifierClass:(Class<CKKSNotifier>)notifierClass;
73
74 - (CKKSKeychainView*)findView:(NSString*)viewName;
75 - (CKKSKeychainView*)findOrCreateView:(NSString*)viewName;
76 - (void)setView:(CKKSKeychainView*)obj;
77 - (void)clearView:(NSString*)viewName;
78
79 - (NSDictionary<NSString*, NSString*>*)activeTLKs;
80
81 // Call this to bring zones up (and to do so automatically in the future)
82 - (void)initializeZones;
83
84 - (NSString*)viewNameForItem:(SecDbItemRef)item;
85
86 - (void)handleKeychainEventDbConnection:(SecDbConnectionRef)dbconn
87 source:(SecDbTransactionSource)txionSource
88 added:(SecDbItemRef _Nullable)added
89 deleted:(SecDbItemRef _Nullable)deleted;
90
91 - (void)setCurrentItemForAccessGroup:(NSData* _Nonnull)newItemPersistentRef
92 hash:(NSData*)newItemSHA1
93 accessGroup:(NSString*)accessGroup
94 identifier:(NSString*)identifier
95 viewHint:(NSString*)viewHint
96 replacing:(NSData* _Nullable)oldCurrentItemPersistentRef
97 hash:(NSData* _Nullable)oldItemSHA1
98 complete:(void (^)(NSError* operror))complete;
99
100 - (void)getCurrentItemForAccessGroup:(NSString*)accessGroup
101 identifier:(NSString*)identifier
102 viewHint:(NSString*)viewHint
103 fetchCloudValue:(bool)fetchCloudValue
104 complete:(void (^)(NSString* uuid, NSError* operror))complete;
105
106 - (NSString*)viewNameForAttributes:(NSDictionary*)item;
107
108 - (void)registerSyncStatusCallback:(NSString*)uuid callback:(SecBoolNSErrorCallback)callback;
109
110 // Cancels pending operations owned by this view manager
111 - (void)cancelPendingOperations;
112
113 // Use these to acquire (and set) the singleton
114 + (instancetype)manager;
115 + (instancetype _Nullable)resetManager:(bool)reset setTo:(CKKSViewManager* _Nullable)obj;
116
117 // Called by XPC every 24 hours
118 - (void)xpc24HrNotification;
119
120 /* White-box testing only */
121 - (CKKSKeychainView*)restartZone:(NSString*)viewName;
122
123 // Returns the viewList for a CKKSViewManager
124 - (NSSet*)viewList;
125
126 // Notify sbd to re-backup.
127 - (void)notifyNewTLKsInKeychain;
128 - (void)syncBackupAndNotifyAboutSync;
129
130 // Fetch peers from SOS
131 - (CKKSSelves* _Nullable)fetchSelfPeers:(NSError* __autoreleasing*)error;
132 - (NSSet<id<CKKSPeer>>* _Nullable)fetchTrustedPeers:(NSError* __autoreleasing*)error;
133
134 // For mocking purposes
135 - (id<CKKSSelfPeer> _Nullable)currentSOSSelf:(NSError**)error;
136 - (NSSet<id<CKKSSelfPeer>>*)pastSelves:(NSError**)error;
137 - (NSArray<NSDictionary*>* _Nullable)loadRestoredBottledKeysOfType:(OctagonKeyType)keyType error:(NSError**)error;
138
139 - (void)sendSelfPeerChangedUpdate;
140 - (void)sendTrustedPeerSetChangedUpdate;
141
142 @end
143 NS_ASSUME_NONNULL_END
144
145 #else
146 @interface CKKSViewManager : NSObject
147 @end
148 #endif // OCTAGON