]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSViewManager.h
Security-58286.31.2.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 #import <Foundation/Foundation.h>
25 #include <securityd/SecDbItem.h>
26 #import "keychain/ckks/CKKS.h"
27
28 #import "keychain/ckks/CKKSControlProtocol.h"
29 #if OCTAGON
30 #import "keychain/ckks/CloudKitDependencies.h"
31 #import "keychain/ckks/CKKSAPSReceiver.h"
32 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
33 #import "keychain/ckks/CKKSLockStateTracker.h"
34 #import "keychain/ckks/CKKSRateLimiter.h"
35 #import "keychain/ckks/CKKSNotifier.h"
36 #import "keychain/ckks/CKKSCondition.h"
37 #import "keychain/ckks/CKKSPeer.h"
38 #endif
39
40 @class CKKSKeychainView, CKKSRateLimiter;
41
42 #if !OCTAGON
43 @interface CKKSViewManager : NSObject
44 #else
45 @interface CKKSViewManager : NSObject <CKKSControlProtocol, CKKSPeerProvider>
46
47 @property CKContainer* container;
48 @property CKKSCKAccountStateTracker* accountTracker;
49 @property CKKSLockStateTracker* lockStateTracker;
50 @property bool initializeNewZones;
51
52 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
53 @property CKKSCondition* completedSecCKKSInitialize;
54
55 @property CKKSRateLimiter* globalRateLimiter;
56
57 // Set this and all newly-created zones will wait to do setup until it completes.
58 // this gives you a bit more control than initializedNewZones above.
59 @property NSOperation* zoneStartupDependency;
60
61 - (instancetype)initCloudKitWithContainerName: (NSString*) containerName usePCS:(bool)usePCS;
62 - (instancetype)initWithContainerName: (NSString*) containerName
63 usePCS: (bool)usePCS
64 fetchRecordZoneChangesOperationClass: (Class<CKKSFetchRecordZoneChangesOperation>) fetchRecordZoneChangesOperationClass
65 fetchRecordsOperationClass: (Class<CKKSFetchRecordsOperation>)fetchRecordsOperationClass
66 queryOperationClass:(Class<CKKSQueryOperation>)queryOperationClass
67 modifySubscriptionsOperationClass: (Class<CKKSModifySubscriptionsOperation>) modifySubscriptionsOperationClass
68 modifyRecordZonesOperationClass: (Class<CKKSModifyRecordZonesOperation>) modifyRecordZonesOperationClass
69 apsConnectionClass: (Class<CKKSAPSConnection>) apsConnectionClass
70 nsnotificationCenterClass: (Class<CKKSNSNotificationCenter>) nsnotificationCenterClass
71 notifierClass: (Class<CKKSNotifier>) notifierClass
72 setupHold:(NSOperation*) setupHold;
73
74 - (CKKSKeychainView*)findView:(NSString*)viewName;
75 - (CKKSKeychainView*)findOrCreateView:(NSString*)viewName;
76 + (CKKSKeychainView*)findOrCreateView:(NSString*)viewName;
77 - (void)setView: (CKKSKeychainView*) obj;
78 - (void)clearView:(NSString*) viewName;
79
80 - (NSDictionary<NSString *,NSString *>*)activeTLKs;
81
82 // Call this to bring zones up (and to do so automatically in the future)
83 - (void)initializeZones;
84
85 - (NSString*)viewNameForItem: (SecDbItemRef) item;
86
87 - (void) handleKeychainEventDbConnection: (SecDbConnectionRef) dbconn source:(SecDbTransactionSource)txionSource added: (SecDbItemRef) added deleted: (SecDbItemRef) deleted;
88
89 -(void)setCurrentItemForAccessGroup:(SecDbItemRef)newItem
90 hash:(NSData*)newItemSHA1
91 accessGroup:(NSString*)accessGroup
92 identifier:(NSString*)identifier
93 viewHint:(NSString*)viewHint
94 replacing:(SecDbItemRef)oldItem
95 hash:(NSData*)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) resetManager: (bool) reset setTo: (CKKSViewManager*) obj;
114
115 // Called by XPC every 24 hours
116 -(void)xpc24HrNotification;
117
118 /* Interface to CCKS control channel */
119 - (xpc_endpoint_t)xpcControlEndpoint;
120
121 /* White-box testing only */
122 - (CKKSKeychainView*)restartZone:(NSString*)viewName;
123
124 // Returns the viewList for a CKKSViewManager
125 -(NSSet*)viewList;
126
127 // Notify sbd to re-backup.
128 -(void)notifyNewTLKsInKeychain;
129 -(void)syncBackupAndNotifyAboutSync;
130
131 // Fetch peers from SOS
132 - (CKKSSelves*)fetchSelfPeers:(NSError* __autoreleasing *)error;
133 - (NSSet<id<CKKSPeer>>*)fetchTrustedPeers:(NSError* __autoreleasing *)error;
134
135 - (void)sendSelfPeerChangedUpdate;
136 - (void)sendTrustedPeerSetChangedUpdate;
137
138 #endif // OCTAGON
139 @end