]> git.saurik.com Git - apple/security.git/blob - KeychainSyncingOverIDSProxy/IDSProxy.h
Security-58286.20.16.tar.gz
[apple/security.git] / KeychainSyncingOverIDSProxy / IDSProxy.h
1 /*
2 * Copyright (c) 2012-2017 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 #import <Foundation/Foundation.h>
25 #import <dispatch/queue.h>
26 #import <xpc/xpc.h>
27 #import <IDS/IDS.h>
28 #import "SOSCloudKeychainClient.h"
29 #import <utilities/debugging.h>
30 #import <Security/SecureObjectSync/SOSInternal.h>
31
32 typedef enum {
33 kIDSStartPingTestMessage = 1,
34 kIDSEndPingTestMessage= 2,
35 kIDSSendOneMessage = 3,
36 kIDSPeerReceivedACK = 4,
37 kIDSPeerAvailability = 6,
38 kIDSPeerAvailabilityDone = 7,
39 kIDSKeychainSyncIDSFragmentation = 8,
40 } idsOperation;
41
42 @interface KeychainSyncingOverIDSProxy : NSObject <IDSServiceDelegate>
43 {
44 IDSService *_service;
45 NSString *deviceID;
46 NSMutableDictionary *deviceIDFromAuthToken;
47 }
48
49 @property (retain, nonatomic) NSMutableDictionary *deviceIDFromAuthToken;
50 @property (retain, nonatomic) NSString *deviceID;
51 @property (retain, nonatomic) NSMutableDictionary *shadowPendingMessages;
52 @property (retain, nonatomic) NSMutableDictionary *allFragmentedMessages;
53 @property (retain, atomic) NSMutableDictionary *pingTimers;
54 @property (retain, nonatomic) NSMutableDictionary *peerNextSendCache; //dictionary of device ID -> time stamp of when to send next
55
56 // Only touch these three dictionaries from the dataQueue or you will crash, eventually.
57 @property (retain, nonatomic) NSMutableDictionary *messagesInFlight;
58 @property (retain, nonatomic) NSMutableDictionary *unhandledMessageBuffer;
59 @property (retain, nonatomic) NSMutableDictionary *monitor;
60
61 @property (retain, nonatomic) NSArray* listOfDevices;
62
63 @property (atomic) dispatch_source_t penaltyTimer;
64 @property (atomic) bool penaltyTimerScheduled;
65 @property (retain, atomic) NSDictionary *queuedMessages;
66
67 @property (retain, atomic) NSMutableDictionary *counterValues;
68 @property (atomic) NSInteger outgoingMessages;
69 @property (atomic) NSInteger incomingMessages;
70
71 @property (atomic) bool isIDSInitDone;
72 @property (atomic) bool shadowDoInitializeIDSService;
73 @property (atomic) bool isSecDRunningAsRoot;
74 @property (atomic) bool doesSecDHavePeer;
75
76 @property (atomic) dispatch_queue_t calloutQueue;
77 @property (atomic) dispatch_queue_t pingQueue;
78 @property dispatch_queue_t dataQueue;
79
80 @property (atomic) bool isLocked;
81 @property (atomic) bool unlockedSinceBoot;
82 @property (atomic) dispatch_source_t retryTimer;
83 @property (atomic) bool retryTimerScheduled;
84 @property (atomic) bool inCallout;
85 @property (atomic) bool setIDSDeviceID;
86 @property (atomic) bool shadowDoSetIDSDeviceID;
87
88 @property (atomic) bool handleAllPendingMessages;
89 @property (atomic) bool shadowHandleAllPendingMessages;
90 @property (atomic) bool sendRestoredMessages;
91
92 + (KeychainSyncingOverIDSProxy *) idsProxy;
93
94 - (id)init;
95
96 - (void) doSetIDSDeviceID;
97 - (void) doIDSInitialization;
98 - (void) calloutWith: (void(^)(NSMutableDictionary *pending,
99 bool handlePendingMesssages,
100 bool doSetDeviceID,
101 dispatch_queue_t queue,
102 void(^done)(NSMutableDictionary *handledMessages,
103 bool handledPendingMessage,
104 bool handledSettingDeviceID))) callout;
105 - (void) sendKeysCallout: (NSMutableDictionary *(^)(NSMutableDictionary* pending, NSError** error)) handleMessages;
106 - (void) persistState;
107 - (void) sendPersistedMessagesAgain;
108 - (NSDictionary*) retrievePendingMessages;
109 - (NSDictionary*) collectStats;
110 - (void) scheduleRetryRequestTimer;
111 - (BOOL) haveMessagesInFlight;
112 @end
113
114 NSString* createErrorString(NSString* format, ...)
115 NS_FORMAT_FUNCTION(1, 2);