2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #import <Foundation/Foundation.h>
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"
43 NS_ASSUME_NONNULL_BEGIN
45 @
class CKKSKeychainView
, CKKSRateLimiter
;
47 @interface CKKSViewManager
: NSObject
<CKKSControlProtocol
, CKKSPeerProvider
>
49 @property CKContainer
* container
;
50 @property CKKSCKAccountStateTracker
* accountTracker
;
51 @property CKKSLockStateTracker
* lockStateTracker
;
52 @property CKKSReachabilityTracker
*reachabilityTracker
;
53 @property
bool initializeNewZones
;
55 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
56 @property CKKSCondition
* completedSecCKKSInitialize
;
58 @property CKKSRateLimiter
* globalRateLimiter
;
60 - (instancetype
)initCloudKitWithContainerName
:(NSString
*)containerName usePCS
:(bool)usePCS
;
61 - (instancetype
)initWithContainerName
:(NSString
*)containerName
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
;
72 - (CKKSKeychainView
*)findView
:(NSString
*)viewName
;
73 - (CKKSKeychainView
*)findOrCreateView
:(NSString
*)viewName
;
74 - (void)setView
:(CKKSKeychainView
*)obj
;
75 - (void)clearView
:(NSString
*)viewName
;
77 - (NSDictionary
<NSString
*, NSString
*>*)activeTLKs
;
79 // Call this to bring zones up (and to do so automatically in the future)
80 - (void)initializeZones
;
82 - (NSString
*)viewNameForItem
:(SecDbItemRef
)item
;
84 - (void)handleKeychainEventDbConnection
:(SecDbConnectionRef
)dbconn
85 source
:(SecDbTransactionSource
)txionSource
86 added
:(SecDbItemRef _Nullable
)added
87 deleted
:(SecDbItemRef _Nullable
)deleted
;
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
;
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
;
104 - (NSString
*)viewNameForAttributes
:(NSDictionary
*)item
;
106 - (void)registerSyncStatusCallback
:(NSString
*)uuid callback
:(SecBoolNSErrorCallback
)callback
;
108 // Cancels pending operations owned by this view manager
109 - (void)cancelPendingOperations
;
111 // Use these to acquire (and set) the singleton
112 + (instancetype
)manager
;
113 + (instancetype _Nullable
)resetManager
:(bool)reset setTo
:(CKKSViewManager
* _Nullable
)obj
;
115 // Called by XPC every 24 hours
116 - (void)xpc24HrNotification
;
118 /* White-box testing only */
119 - (CKKSKeychainView
*)restartZone
:(NSString
*)viewName
;
121 // Returns the viewList for a CKKSViewManager
124 // Notify sbd to re-backup.
125 - (void)notifyNewTLKsInKeychain
;
126 - (void)syncBackupAndNotifyAboutSync
;
128 // Fetch peers from SOS
129 - (CKKSSelves
* _Nullable
)fetchSelfPeers
:(NSError
* __autoreleasing
*)error
;
130 - (NSSet
<id
<CKKSPeer
>>* _Nullable
)fetchTrustedPeers
:(NSError
* __autoreleasing
*)error
;
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
;
137 - (void)sendSelfPeerChangedUpdate
;
138 - (void)sendTrustedPeerSetChangedUpdate
;
141 NS_ASSUME_NONNULL_END
144 @interface CKKSViewManager
: NSObject