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"
39 @
class CKKSKeychainView
, CKKSRateLimiter
;
42 @interface CKKSViewManager
: NSObject
44 @interface CKKSViewManager
: NSObject
<CKKSControlProtocol
>
46 @property CKContainer
* container
;
47 @property CKKSCKAccountStateTracker
* accountTracker
;
48 @property CKKSLockStateTracker
* lockStateTracker
;
49 @property
bool initializeNewZones
;
51 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
52 @property CKKSCondition
* completedSecCKKSInitialize
;
54 @property CKKSRateLimiter
* globalRateLimiter
;
56 // Set this and all newly-created zones will wait to do setup until it completes.
57 // this gives you a bit more control than initializedNewZones above.
58 @property NSOperation
* zoneStartupDependency
;
60 - (instancetype
)initCloudKitWithContainerName
: (NSString
*) containerName usePCS
:(bool)usePCS
;
61 - (instancetype
)initWithContainerName
: (NSString
*) containerNamee
63 fetchRecordZoneChangesOperationClass
: (Class
<CKKSFetchRecordZoneChangesOperation
>) fetchRecordZoneChangesOperationClass
64 modifySubscriptionsOperationClass
: (Class
<CKKSModifySubscriptionsOperation
>) modifySubscriptionsOperationClass
65 modifyRecordZonesOperationClass
: (Class
<CKKSModifyRecordZonesOperation
>) modifyRecordZonesOperationClass
66 apsConnectionClass
: (Class
<CKKSAPSConnection
>) apsConnectionClass
67 nsnotificationCenterClass
: (Class
<CKKSNSNotificationCenter
>) nsnotificationCenterClass
68 notifierClass
: (Class
<CKKSNotifier
>) notifierClass
69 setupHold
:(NSOperation
*) setupHold
;
71 - (CKKSKeychainView
*)findView
:(NSString
*)viewName
;
72 - (CKKSKeychainView
*)findOrCreateView
:(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 source
:(SecDbTransactionSource
)txionSource added
: (SecDbItemRef
) added deleted
: (SecDbItemRef
) deleted
;
86 -(void)setCurrentItemForAccessGroup
:(SecDbItemRef
)newItem
87 hash
:(NSData
*)newItemSHA1
88 accessGroup
:(NSString
*)accessGroup
89 identifier
:(NSString
*)identifier
90 viewHint
:(NSString
*)viewHint
91 replacing
:(SecDbItemRef
)oldItem
92 hash
:(NSData
*)oldItemSHA1
93 complete
:(void (^) (NSError
* operror
)) complete
;
95 -(void)getCurrentItemForAccessGroup
:(NSString
*)accessGroup
96 identifier
:(NSString
*)identifier
97 viewHint
:(NSString
*)viewHint
98 fetchCloudValue
:(bool)fetchCloudValue
99 complete
:(void (^) (NSString
* uuid
, NSError
* operror
)) complete
;
101 - (NSString
*)viewNameForAttributes
: (NSDictionary
*) item
;
103 - (void)registerSyncStatusCallback
: (NSString
*) uuid callback
: (SecBoolNSErrorCallback
) callback
;
105 // Cancels pending operations owned by this view manager
106 - (void)cancelPendingOperations
;
108 // Use these to acquire (and set) the singleton
109 + (instancetype
) manager
;
110 + (instancetype
) resetManager
: (bool) reset setTo
: (CKKSViewManager
*) obj
;
112 // Called by XPC every 24 hours
113 -(void)xpc24HrNotification
;
115 /* Interface to CCKS control channel */
116 - (xpc_endpoint_t
)xpcControlEndpoint
;
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
;