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