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/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"
45 #import "keychain/ot/OTSOSAdapter.h"
46 #import "keychain/ot/OTDefines.h"
48 NS_ASSUME_NONNULL_BEGIN
50 @
class CKKSKeychainView
, CKKSRateLimiter
, TPPolicy
;
52 @interface CKKSViewManager
: NSObject
<CKKSControlProtocol
>
54 @property CKContainer
* container
;
55 @property CKKSAccountStateTracker
* accountTracker
;
56 @property CKKSLockStateTracker
* lockStateTracker
;
57 @property CKKSReachabilityTracker
*reachabilityTracker
;
58 @property CKKSZoneChangeFetcher
* zoneChangeFetcher
;
59 @property CKKSZoneModifier
* zoneModifier
;
61 // Signaled when SecCKKSInitialize is complete, as it's async and likes to fire after tests are complete
62 @property CKKSCondition
* completedSecCKKSInitialize
;
64 @property CKKSRateLimiter
* globalRateLimiter
;
66 @property id
<OTSOSAdapter
> sosPeerAdapter
;
68 @
property (nullable
) TPPolicy
* policy
;
70 @property NSMutableDictionary
<NSString
*, CKKSKeychainView
*>* views
;
72 - (instancetype
)initWithContainerName
:(NSString
*)containerName
74 sosAdapter
:(id
<OTSOSAdapter
> _Nullable
)sosAdapter
75 cloudKitClassDependencies
:(CKKSCloudKitClassDependencies
*)cloudKitClassDependencies
;
77 - (CKKSKeychainView
*)findView
:(NSString
*)viewName
;
78 - (CKKSKeychainView
*)findOrCreateView
:(NSString
*)viewName
;
79 - (void)setView
:(CKKSKeychainView
*)obj
;
80 - (void)clearView
:(NSString
*)viewName
;
82 - (NSSet
<CKKSKeychainView
*>*)currentViews
;
84 - (NSDictionary
<NSString
*, NSString
*>*)activeTLKs
;
86 - (void)setupAnalytics
;
88 - (NSString
*)viewNameForItem
:(SecDbItemRef
)item
;
90 - (void)handleKeychainEventDbConnection
:(SecDbConnectionRef
)dbconn
91 source
:(SecDbTransactionSource
)txionSource
92 added
:(SecDbItemRef _Nullable
)added
93 deleted
:(SecDbItemRef _Nullable
)deleted
;
95 - (void)setCurrentItemForAccessGroup
:(NSData
* _Nonnull
)newItemPersistentRef
96 hash
:(NSData
*)newItemSHA1
97 accessGroup
:(NSString
*)accessGroup
98 identifier
:(NSString
*)identifier
99 viewHint
:(NSString
*)viewHint
100 replacing
:(NSData
* _Nullable
)oldCurrentItemPersistentRef
101 hash
:(NSData
* _Nullable
)oldItemSHA1
102 complete
:(void (^)(NSError
* operror
))complete
;
104 - (void)getCurrentItemForAccessGroup
:(NSString
*)accessGroup
105 identifier
:(NSString
*)identifier
106 viewHint
:(NSString
*)viewHint
107 fetchCloudValue
:(bool)fetchCloudValue
108 complete
:(void (^)(NSString
* uuid
, NSError
* operror
))complete
;
110 - (void)registerSyncStatusCallback
:(NSString
*)uuid callback
:(SecBoolNSErrorCallback
)callback
;
112 // Cancels pending operations owned by this view manager
113 - (void)cancelPendingOperations
;
115 // Use these to acquire (and set) the singleton
116 + (instancetype
)manager
;
117 + (instancetype _Nullable
)resetManager
:(bool)reset setTo
:(CKKSViewManager
* _Nullable
)obj
;
119 // Called by XPC every 24 hours
120 - (void)xpc24HrNotification
;
122 /* White-box testing only */
123 - (CKKSKeychainView
*)restartZone
:(NSString
*)viewName
;
125 // Returns the viewList for a CKKSViewManager
126 - (NSSet
<NSString
*>*)viewList
;
128 - (NSSet
<NSString
*>*)defaultViewList
;
130 - (void)setViewList
:(NSSet
<NSString
*>* _Nullable
)newViewList
;
132 - (void)clearAllViews
;
134 // Create all views, but don't begin CK/network operations
137 // Call this to begin CK operation of all views
138 - (void)beginCloudKitOperationOfAllViews
;
140 // Notify sbd to re-backup.
141 - (void)notifyNewTLKsInKeychain
;
142 - (void)syncBackupAndNotifyAboutSync
;
145 - (void)setOverrideCKKSViewsFromPolicy
:(BOOL
)value
;
146 - (BOOL
)useCKKSViewsFromPolicy
;
150 NS_ASSUME_NONNULL_END
153 @interface CKKSViewManager
: NSObject