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@
24 #import <Foundation/Foundation.h>
25 #include <securityd/SecDbItem.h>
26 #import "keychain/ckks/CKKS.h"
28 #import "keychain/ckks/CKKSControlProtocol.h"
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"
40 @
class CKKSKeychainView
, CKKSRateLimiter
;
43 @interface CKKSViewManager
: NSObject
45 @interface CKKSViewManager
: NSObject
<CKKSControlProtocol
, CKKSPeerProvider
>
47 @property CKContainer
* container
;
48 @property CKKSCKAccountStateTracker
* accountTracker
;
49 @property CKKSLockStateTracker
* lockStateTracker
;
50 @property
bool initializeNewZones
;
52 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
53 @property CKKSCondition
* completedSecCKKSInitialize
;
55 @property CKKSRateLimiter
* globalRateLimiter
;
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
;
61 - (instancetype
)initCloudKitWithContainerName
: (NSString
*) containerName usePCS
:(bool)usePCS
;
62 - (instancetype
)initWithContainerName
: (NSString
*) containerName
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
;
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
;
80 - (NSDictionary
<NSString
*,NSString
*>*)activeTLKs
;
82 // Call this to bring zones up (and to do so automatically in the future)
83 - (void)initializeZones
;
85 - (NSString
*)viewNameForItem
: (SecDbItemRef
) item
;
87 - (void) handleKeychainEventDbConnection
: (SecDbConnectionRef
) dbconn source
:(SecDbTransactionSource
)txionSource added
: (SecDbItemRef
) added deleted
: (SecDbItemRef
) deleted
;
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
;
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
) resetManager
: (bool) reset setTo
: (CKKSViewManager
*) obj
;
115 // Called by XPC every 24 hours
116 -(void)xpc24HrNotification
;
118 /* Interface to CCKS control channel */
119 - (xpc_endpoint_t
)xpcControlEndpoint
;
121 /* White-box testing only */
122 - (CKKSKeychainView
*)restartZone
:(NSString
*)viewName
;
124 // Returns the viewList for a CKKSViewManager
127 // Notify sbd to re-backup.
128 -(void)notifyNewTLKsInKeychain
;
129 -(void)syncBackupAndNotifyAboutSync
;
131 // Fetch peers from SOS
132 - (CKKSSelves
*)fetchSelfPeers
:(NSError
* __autoreleasing
*)error
;
133 - (NSSet
<id
<CKKSPeer
>>*)fetchTrustedPeers
:(NSError
* __autoreleasing
*)error
;
135 - (void)sendSelfPeerChangedUpdate
;
136 - (void)sendTrustedPeerSetChangedUpdate
;