]> git.saurik.com Git - apple/security.git/blob - KVSKeychainSyncingProxy/CKDKVSProxy.h
Security-58286.270.3.0.1.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 @property (atomic) dispatch_source_t penaltyTimer;
93 @property (atomic) bool penaltyTimerScheduled;
94 @property (retain, atomic) NSMutableDictionary *monitor;
95 @property (retain, atomic) NSDictionary *queuedMessages;
96
97 @property (copy, atomic) dispatch_block_t shadowFlushBlock;
98
99
100 - (NSString *)description;
101 - (instancetype)init NS_UNAVAILABLE;
102
103 + (instancetype)withAccount:(NSObject<CKDAccount>*) account
104 store:(NSObject<CKDStore>*) store
105 lockMonitor:(NSObject<CKDLockMonitor>*) lockMonitor
106 persistence:(NSURL*) localPersistence;
107
108 - (instancetype)initWithAccount:(NSObject<CKDAccount>*) account
109 store:(NSObject<CKDStore>*) store
110 lockMonitor:(NSObject<CKDLockMonitor>*) lockMonitor
111 persistence:(NSURL*) localPersistence NS_DESIGNATED_INITIALIZER;
112
113 // Requests:
114
115 - (void)clearStore;
116 - (void)synchronizeStore;
117 - (id) objectForKey: (NSString*) key;
118 - (NSDictionary<NSString *, id>*) copyAsDictionary;
119 - (void)setObjectsFromDictionary:(NSDictionary<NSString*, NSObject*> *)otherDictionary;
120 - (void)waitForSynchronization:(void (^)(NSDictionary<NSString*, NSObject*> *results, NSError *err))handler;
121
122
123 // Callbacks from stores when things happen
124 - (void)storeKeysChanged: (NSSet<NSString*>*) changedKeys initial: (bool) initial;
125 - (void)storeAccountChanged;
126
127 - (void)requestEnsurePeerRegistration;
128
129 - (void)requestSyncWithPeerIDs: (NSArray<NSString*>*) peerIDs backupPeerIDs: (NSArray<NSString*>*) backupPeerIDs;
130 - (BOOL)hasSyncPendingFor: (NSString*) peerID;
131 - (BOOL)hasPendingKey: (NSString*) keyName;
132
133 - (void)registerAtTimeKeys:(NSDictionary*)keyparms;
134
135 - (NSSet*) keysForCurrentLockState;
136 - (void) intersectWithCurrentLockState: (NSMutableSet*) set;
137
138 - (NSMutableSet*) pendKeysAndGetNewlyPended: (NSSet*) keysToPend;
139
140 - (NSMutableSet*) pendingKeysForCurrentLockState;
141 - (NSMutableSet*) pendKeysAndGetPendingForCurrentLockState: (NSSet*) startingSet;
142
143 - (void)processPendingKeysForCurrentLockState;
144
145 - (void)registerKeys: (NSDictionary*)keys forAccount: (NSString*) accountUUID;
146 - (void)removeKeys: (NSArray*)keys forAccount: (NSString*) accountUUID;
147
148 - (void)processKeyChangedEvent:(NSDictionary *)keysChangedInCloud;
149 - (NSMutableDictionary *)copyValues:(NSSet *)keysOfInterest;
150
151 - (void) doAfterFlush: (dispatch_block_t) block;
152 - (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;
153 - (void) sendKeysCallout: (NSSet *(^)(NSSet* pending, NSError **error)) handleKeys;
154
155 - (void)perfCounters:(void(^)(NSDictionary *counters))callback;
156
157 @end