]> git.saurik.com Git - apple/security.git/blob - KVSKeychainSyncingProxy/CKDKVSProxy.h
Security-57740.1.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
41 #define XPROXYSCOPE "proxy"
42
43 typedef void (^FreshnessResponseBlock)(bool success, NSError *err);
44
45 @interface UbiqitousKVSProxy : NSObject
46 {
47 id currentiCloudToken;
48 int callbackMethod;
49 }
50
51 @property (readonly) NSObject<CKDStore>* store;
52 @property (readonly) NSObject<CKDAccount>* account;
53
54
55 @property (retain, nonatomic) NSMutableSet *alwaysKeys;
56 @property (retain, nonatomic) NSMutableSet *firstUnlockKeys;
57 @property (retain, nonatomic) NSMutableSet *unlockedKeys;
58
59 @property (atomic) bool unlockedSinceBoot;
60 @property (atomic) bool isLocked;
61 @property (atomic) bool seenKVSStoreChange;
62
63
64 @property (retain, nonatomic) NSMutableSet *pendingKeys;
65 @property (retain, nonatomic) NSMutableSet *shadowPendingKeys;
66
67 @property (retain, nonatomic) NSString *dsid;
68
69 @property (atomic) bool syncWithPeersPending;
70 @property (atomic) bool shadowSyncWithPeersPending;
71
72 @property (atomic) bool ensurePeerRegistration;
73 @property (atomic) bool shadowEnsurePeerRegistration;
74
75 @property (atomic) bool inCallout;
76
77 @property (retain, nonatomic) NSMutableArray<FreshnessResponseBlock> *freshnessCompletions;
78 @property (atomic) dispatch_time_t nextFreshnessTime;
79
80 @property (atomic) dispatch_source_t syncTimer;
81 @property (atomic) bool syncTimerScheduled;
82
83 @property (atomic) dispatch_time_t deadline;
84 @property (atomic) dispatch_time_t lastSyncTime;
85
86
87 @property (atomic) dispatch_queue_t calloutQueue;
88
89 @property (atomic) dispatch_queue_t ckdkvsproxy_queue;
90 @property (atomic) dispatch_source_t penaltyTimer;
91 @property (atomic) bool penaltyTimerScheduled;
92 @property (retain, atomic) NSMutableDictionary *monitor;
93 @property (retain, atomic) NSDictionary *queuedMessages;
94
95 @property (copy, atomic) dispatch_block_t shadowFlushBlock;
96
97
98 + (UbiqitousKVSProxy *) sharedKVSProxy;
99 - (NSString *)description;
100 - (id)init NS_UNAVAILABLE;
101 - (id)initWithAccount:(NSObject<CKDAccount>*) account
102 store:(NSObject<CKDStore>*) store NS_DESIGNATED_INITIALIZER;
103
104 // Requests:
105
106 - (void)clearStore;
107 - (void)synchronizeStore;
108 - (id) objectForKey: (NSString*) key;
109 - (NSDictionary<NSString *, id>*) copyAsDictionary;
110 - (void)setObjectsFromDictionary:(NSDictionary<NSString*, NSObject*> *)otherDictionary;
111 - (void)waitForSynchronization:(void (^)(NSDictionary<NSString*, NSObject*> *results, NSError *err))handler;
112
113
114 // Callbacks from stores when things happen
115 - (void)storeKeysChanged: (NSSet<NSString*>*) changedKeys initial: (bool) initial;
116 - (void)storeAccountChanged;
117
118 - (void)streamEvent:(xpc_object_t)notification;
119
120 - (void)processAllItems;
121 - (void)requestSyncWithAllPeers;
122 - (void)requestEnsurePeerRegistration;
123
124 - (void)registerAtTimeKeys:(NSDictionary*)keyparms;
125
126 - (NSSet*) keysForCurrentLockState;
127 - (void) intersectWithCurrentLockState: (NSMutableSet*) set;
128
129 - (NSMutableSet*) pendKeysAndGetNewlyPended: (NSSet*) keysToPend;
130
131 - (NSMutableSet*) pendingKeysForCurrentLockState;
132 - (NSMutableSet*) pendKeysAndGetPendingForCurrentLockState: (NSSet*) startingSet;
133
134 - (void)processPendingKeysForCurrentLockState;
135
136 - (void)registerKeys: (NSDictionary*)keys;
137
138 - (void)processKeyChangedEvent:(NSDictionary *)keysChangedInCloud;
139 - (NSMutableDictionary *)copyValues:(NSSet *)keysOfInterest;
140
141 - (void) doAfterFlush: (dispatch_block_t) block;
142 - (void) calloutWith: (void(^)(NSSet *pending, bool syncWithPeersPending, bool ensurePeerRegistration, dispatch_queue_t queue, void(^done)(NSSet *handledKeys, bool handledSyncWithPeers, bool handledEnsurePeerRegistration))) callout;
143 - (void) sendKeysCallout: (NSSet *(^)(NSSet* pending, NSError **error)) handleKeys;
144
145 - (void)recordWriteToKVS:(NSDictionary *)values;
146 - (NSDictionary*)recordHaltedValuesAndReturnValuesToSafelyWrite:(NSDictionary *)values;
147
148 @end