]> git.saurik.com Git - apple/security.git/blob - KVSKeychainSyncingProxy/CKDKVSProxy.h
Security-59306.11.20.tar.gz
[apple/security.git] / KVSKeychainSyncingProxy / CKDKVSProxy.h
1 /*
2 * Copyright (c) 2012-2014 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 // CKDKVSProxy.h
26 // ckd-xpc
27
28 #import <Foundation/Foundation.h>
29 #import <dispatch/queue.h>
30 #import <xpc/xpc.h>
31 #import <IDS/IDS.h>
32
33 #import <utilities/debugging.h>
34
35 #import "SOSCloudKeychainConstants.h"
36 #import "SOSCloudKeychainClient.h"
37
38 #import "CKDStore.h"
39 #import "CKDAccount.h"
40 #import "CKDLockMonitor.h"
41 #import "XPCNotificationDispatcher.h"
42
43 #define XPROXYSCOPE "proxy"
44
45 typedef void (^FreshnessResponseBlock)(bool success, NSError *err);
46
47 @interface UbiqitousKVSProxy : NSObject<XPCNotificationListener, CKDLockListener>
48 {
49 id currentiCloudToken;
50 int callbackMethod;
51 }
52
53 @property (readonly) NSObject<CKDStore>* store;
54 @property (readonly) NSObject<CKDAccount>* account;
55 @property (readonly) NSObject<CKDLockMonitor>* lockMonitor;
56
57 @property (readonly) NSURL* persistenceURL;
58
59 @property (retain, nonatomic) NSMutableSet *alwaysKeys;
60 @property (retain, nonatomic) NSMutableSet *firstUnlockKeys;
61 @property (retain, nonatomic) NSMutableSet *unlockedKeys;
62
63 @property (atomic) bool seenKVSStoreChange;
64
65
66 @property (retain, nonatomic) NSMutableSet *pendingKeys;
67 @property (retain, nonatomic) NSMutableSet *shadowPendingKeys;
68
69 @property (retain, nonatomic) NSString *dsid;
70 @property (retain, nonatomic) NSString *accountUUID;
71
72 @property (retain, nonatomic) NSMutableSet<NSString*>* pendingSyncPeerIDs;
73 @property (retain, nonatomic) NSMutableSet<NSString*>* shadowPendingSyncPeerIDs;
74
75 @property (retain, nonatomic) NSMutableSet<NSString*>* pendingSyncBackupPeerIDs;
76 @property (retain, nonatomic) NSMutableSet<NSString*>* shadowPendingSyncBackupPeerIDs;
77
78 @property (atomic) bool ensurePeerRegistration;
79 @property (atomic) bool ensurePeerRegistrationEnqueuedButNotStarted;
80
81 // Another version of ensurePeerRegistration due to legacy code structure
82 @property (atomic) bool shadowEnsurePeerRegistration;
83
84 @property (atomic) bool inCallout;
85
86 @property (retain, nonatomic) NSMutableArray<FreshnessResponseBlock> *freshnessCompletions;
87 @property (atomic) dispatch_time_t nextFreshnessTime;
88
89 @property (atomic) dispatch_queue_t calloutQueue;
90
91 @property (atomic) dispatch_queue_t ckdkvsproxy_queue;
92
93 @property (copy, atomic) dispatch_block_t shadowFlushBlock;
94
95
96 - (NSString *)description;
97 - (instancetype)init NS_UNAVAILABLE;
98
99 + (instancetype)withAccount:(NSObject<CKDAccount>*) account
100 store:(NSObject<CKDStore>*) store
101 lockMonitor:(NSObject<CKDLockMonitor>*) lockMonitor
102 persistence:(NSURL*) localPersistence;
103
104 - (instancetype)initWithAccount:(NSObject<CKDAccount>*) account
105 store:(NSObject<CKDStore>*) store
106 lockMonitor:(NSObject<CKDLockMonitor>*) lockMonitor
107 persistence:(NSURL*) localPersistence NS_DESIGNATED_INITIALIZER;
108
109 // Requests:
110
111 - (void)clearStore;
112 - (void)synchronizeStore;
113 - (id) objectForKey: (NSString*) key;
114 - (NSDictionary<NSString *, id>*) copyAsDictionary;
115 - (void)setObjectsFromDictionary:(NSDictionary<NSString*, NSObject*> *)otherDictionary;
116 - (void)waitForSynchronization:(void (^)(NSDictionary<NSString*, NSObject*> *results, NSError *err))handler;
117
118
119 // Callbacks from stores when things happen
120 - (void)storeKeysChanged: (NSSet<NSString*>*) changedKeys initial: (bool) initial;
121 - (void)storeAccountChanged;
122
123 - (void)requestEnsurePeerRegistration;
124
125 - (void)requestSyncWithPeerIDs: (NSArray<NSString*>*) peerIDs backupPeerIDs: (NSArray<NSString*>*) backupPeerIDs;
126 - (BOOL)hasSyncPendingFor: (NSString*) peerID;
127 - (BOOL)hasPendingKey: (NSString*) keyName;
128
129 - (void)registerAtTimeKeys:(NSDictionary*)keyparms;
130
131 - (NSSet*) keysForCurrentLockState;
132 - (void) intersectWithCurrentLockState: (NSMutableSet*) set;
133
134 - (NSMutableSet*) pendKeysAndGetNewlyPended: (NSSet*) keysToPend;
135
136 - (NSMutableSet*) pendingKeysForCurrentLockState;
137 - (NSMutableSet*) pendKeysAndGetPendingForCurrentLockState: (NSSet*) startingSet;
138
139 - (void)processPendingKeysForCurrentLockState;
140
141 - (void)registerKeys: (NSDictionary*)keys forAccount: (NSString*) accountUUID;
142 - (void)removeKeys: (NSArray*)keys forAccount: (NSString*) accountUUID;
143
144 - (void)processKeyChangedEvent:(NSDictionary *)keysChangedInCloud;
145 - (NSMutableDictionary *)copyValues:(NSSet *)keysOfInterest;
146
147 - (void) doAfterFlush: (dispatch_block_t) block;
148 - (void) calloutWith: (void(^)(NSSet *pending, NSSet* pendingSyncIDs, NSSet* pendingBackupSyncIDs, bool ensurePeerRegistration, dispatch_queue_t queue, void(^done)(NSSet *handledKeys, NSSet *handledSyncs, bool handledEnsurePeerRegistration, NSError* error))) callout;
149 - (void) sendKeysCallout: (NSSet *(^)(NSSet* pending, NSError **error)) handleKeys;
150
151 - (void)perfCounters:(void(^)(NSDictionary *counters))callback;
152
153 @end