]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSViewManager.h
Security-59306.101.1.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 "keychain/securityd/SecDbItem.h"
30 #import "keychain/ckks/CKKS.h"
31 #import "keychain/ckks/OctagonAPSReceiver.h"
32 #import "keychain/ckks/CKKSAccountStateTracker.h"
33 #import "keychain/ckks/CKKSCloudKitClassDependencies.h"
34 #import "keychain/ckks/CKKSCondition.h"
35 #import "keychain/ckks/CKKSControlProtocol.h"
36 #import "keychain/ckks/CKKSLockStateTracker.h"
37 #import "keychain/ckks/CKKSReachabilityTracker.h"
38 #import "keychain/ckks/CKKSNotifier.h"
39 #import "keychain/ckks/CKKSPeer.h"
40 #import "keychain/ckks/CKKSRateLimiter.h"
41 #import "keychain/ckks/CloudKitDependencies.h"
42 #import "keychain/ckks/CKKSZoneChangeFetcher.h"
43 #import "keychain/ckks/CKKSZoneModifier.h"
44
45 #import "keychain/ot/OTSOSAdapter.h"
46 #import "keychain/ot/OTDefines.h"
47
48 NS_ASSUME_NONNULL_BEGIN
49
50 @class CKKSKeychainView, CKKSRateLimiter, TPPolicy;
51
52 @interface CKKSViewManager : NSObject <CKKSControlProtocol>
53
54 @property CKContainer* container;
55 @property CKKSAccountStateTracker* accountTracker;
56 @property CKKSLockStateTracker* lockStateTracker;
57 @property CKKSReachabilityTracker *reachabilityTracker;
58 @property CKKSZoneChangeFetcher* zoneChangeFetcher;
59 @property CKKSZoneModifier* zoneModifier;
60
61 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
62 @property CKKSCondition* completedSecCKKSInitialize;
63
64 @property CKKSRateLimiter* globalRateLimiter;
65
66 @property id<OTSOSAdapter> sosPeerAdapter;
67
68 @property (readonly, nullable) TPPolicy* policy;
69
70 @property (readonly) NSMutableDictionary<NSString*, CKKSKeychainView*>* views;
71
72 - (instancetype)initWithContainer:(CKContainer*)container
73 sosAdapter:(id<OTSOSAdapter> _Nullable)sosAdapter
74 accountStateTracker:(CKKSAccountStateTracker*)accountTracker
75 lockStateTracker:(CKKSLockStateTracker*)lockStateTracker
76 cloudKitClassDependencies:(CKKSCloudKitClassDependencies*)cloudKitClassDependencies;
77
78 - (CKKSKeychainView*)findView:(NSString*)viewName;
79 - (CKKSKeychainView*)findOrCreateView:(NSString*)viewName;
80 - (void)setView:(CKKSKeychainView*)obj;
81 - (void)clearView:(NSString*)viewName;
82
83 - (NSSet<CKKSKeychainView*>*)currentViews;
84
85 - (NSDictionary<NSString*, NSString*>*)activeTLKs;
86
87 - (void)setupAnalytics;
88
89 - (NSString* _Nullable)viewNameForItem:(SecDbItemRef)item;
90
91 - (void)handleKeychainEventDbConnection:(SecDbConnectionRef)dbconn
92 source:(SecDbTransactionSource)txionSource
93 added:(SecDbItemRef _Nullable)added
94 deleted:(SecDbItemRef _Nullable)deleted;
95
96 - (void)setCurrentItemForAccessGroup:(NSData* _Nonnull)newItemPersistentRef
97 hash:(NSData*)newItemSHA1
98 accessGroup:(NSString*)accessGroup
99 identifier:(NSString*)identifier
100 viewHint:(NSString*)viewHint
101 replacing:(NSData* _Nullable)oldCurrentItemPersistentRef
102 hash:(NSData* _Nullable)oldItemSHA1
103 complete:(void (^)(NSError* operror))complete;
104
105 - (void)getCurrentItemForAccessGroup:(NSString*)accessGroup
106 identifier:(NSString*)identifier
107 viewHint:(NSString*)viewHint
108 fetchCloudValue:(bool)fetchCloudValue
109 complete:(void (^)(NSString* uuid, NSError* operror))complete;
110
111 - (void)registerSyncStatusCallback:(NSString*)uuid callback:(SecBoolNSErrorCallback)callback;
112
113 // Cancels pending operations owned by this view manager
114 - (void)cancelPendingOperations;
115
116 + (instancetype)manager;
117
118 // Called by XPC every 24 hours
119 - (void)xpc24HrNotification;
120
121 // Returns the current set of views
122 - (NSSet<NSString*>*)viewList;
123
124 - (NSSet<NSString*>*)defaultViewList;
125
126 // Call this to set the syncing views+policy that this manager will use.
127 // If beginCloudKitOperationOfAllViews has previously been called, then any new views created
128 // as a result of this call will begin CK operation.
129 - (void)setSyncingViews:(NSSet<NSString*>* _Nullable)viewNames sortingPolicy:(TPPolicy* _Nullable)policy;
130
131 - (void)clearAllViews;
132
133 // Create all views, but don't begin CK/network operations
134 // Remove as part of <rdar://problem/57768740> CKKS: ensure we collect keychain changes made before policy is loaded from disk
135 - (void)createViews;
136
137 // Call this to begin CK operation of all views
138 // This bit will be 'sticky', in that any new views created with also begin cloudkit operation immediately.
139 // (clearAllViews will reset this bit.)
140 - (void)beginCloudKitOperationOfAllViews;
141
142 // Notify sbd to re-backup.
143 - (void)notifyNewTLKsInKeychain;
144 - (void)syncBackupAndNotifyAboutSync;
145
146 // allow user blocking operation to block on trust status trying to sort it-self out the
147 // first time after launch, only waits the the initial call
148 - (BOOL)waitForTrustReady;
149
150 // Helper function to make CK containers
151 + (CKContainer*)makeCKContainer:(NSString*)containerName
152 usePCS:(bool)usePCS;
153
154 // Checks featureflags to return whether we should use policy-based views, or use the hardcoded list
155 - (BOOL)useCKKSViewsFromPolicy;
156
157 // Interfaces to examine sync callbacks
158 - (SecBoolNSErrorCallback _Nullable)claimCallbackForUUID:(NSString*)uuid;
159 - (NSSet<NSString*>*)pendingCallbackUUIDs;
160 + (void)callSyncCallbackWithErrorNoAccount:(SecBoolNSErrorCallback)syncCallback;
161 @end
162
163 @interface CKKSViewManager (Testing)
164 - (void)setOverrideCKKSViewsFromPolicy:(BOOL)value;
165 - (void)resetSyncingPolicy;
166
167 - (void)haltAll;
168 - (CKKSKeychainView*)restartZone:(NSString*)viewName;
169 - (void)haltZone:(NSString*)viewName;
170
171 // If set, any set passed to setSyncingViews will be intersected with this set
172 - (void)setSyncingViewsAllowList:(NSSet<NSString*>* _Nullable)viewNames;
173 @end
174 NS_ASSUME_NONNULL_END
175
176 #else
177 @interface CKKSViewManager : NSObject
178 @end
179 #endif // OCTAGON