]> git.saurik.com Git - apple/security.git/blob - KVSKeychainSyncingProxy/CKDKVSProxy.h
Security-57740.60.18.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 shadowEnsurePeerRegistration;
80
81 @property (atomic) bool inCallout;
82
83 @property (retain, nonatomic) NSMutableArray<FreshnessResponseBlock> *freshnessCompletions;
84 @property (atomic) dispatch_time_t nextFreshnessTime;
85
86 @property (atomic) dispatch_queue_t calloutQueue;
87
88 @property (atomic) dispatch_queue_t ckdkvsproxy_queue;
89 @property (atomic) dispatch_source_t penaltyTimer;
90 @property (atomic) bool penaltyTimerScheduled;
91 @property (retain, atomic) NSMutableDictionary *monitor;
92 @property (retain, atomic) NSDictionary *queuedMessages;
93
94 @property (copy, atomic) dispatch_block_t shadowFlushBlock;
95
96
97 - (NSString *)description;
98 - (instancetype)init NS_UNAVAILABLE;
99
100 + (instancetype)withAccount:(NSObject<CKDAccount>*) account
101 store:(NSObject<CKDStore>*) store
102 lockMonitor:(NSObject<CKDLockMonitor>*) lockMonitor
103 persistence:(NSURL*) localPersistence;
104
105 - (instancetype)initWithAccount:(NSObject<CKDAccount>*) account
106 store:(NSObject<CKDStore>*) store
107 lockMonitor:(NSObject<CKDLockMonitor>*) lockMonitor
108 persistence:(NSURL*) localPersistence NS_DESIGNATED_INITIALIZER;
109
110 // Requests:
111
112 - (void)clearStore;
113 - (void)synchronizeStore;
114 - (id) objectForKey: (NSString*) key;
115 - (NSDictionary<NSString *, id>*) copyAsDictionary;
116 - (void)setObjectsFromDictionary:(NSDictionary<NSString*, NSObject*> *)otherDictionary;
117 - (void)waitForSynchronization:(void (^)(NSDictionary<NSString*, NSObject*> *results, NSError *err))handler;
118
119
120 // Callbacks from stores when things happen
121 - (void)storeKeysChanged: (NSSet<NSString*>*) changedKeys initial: (bool) initial;
122 - (void)storeAccountChanged;
123
124 - (void)requestEnsurePeerRegistration;
125
126 - (void)requestSyncWithPeerIDs: (NSArray<NSString*>*) peerIDs backupPeerIDs: (NSArray<NSString*>*) backupPeerIDs;
127 - (BOOL)hasSyncPendingFor: (NSString*) peerID;
128 - (BOOL)hasPendingKey: (NSString*) keyName;
129
130 - (void)registerAtTimeKeys:(NSDictionary*)keyparms;
131
132 - (NSSet*) keysForCurrentLockState;
133 - (void) intersectWithCurrentLockState: (NSMutableSet*) set;
134
135 - (NSMutableSet*) pendKeysAndGetNewlyPended: (NSSet*) keysToPend;
136
137 - (NSMutableSet*) pendingKeysForCurrentLockState;
138 - (NSMutableSet*) pendKeysAndGetPendingForCurrentLockState: (NSSet*) startingSet;
139
140 - (void)processPendingKeysForCurrentLockState;
141
142 - (void)registerKeys: (NSDictionary*)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)recordWriteToKVS:(NSDictionary *)values;
152 - (NSDictionary*)recordHaltedValuesAndReturnValuesToSafelyWrite:(NSDictionary *)values;
153
154 @end