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