]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/SecureObjectSync/SOSAccount.h
Security-57740.31.2.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / SOSAccount.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 /*!
26 @header SOSAccount.h
27 The functions provided in SOSCircle.h provide an interface to a
28 secure object syncing circle for a single class
29 */
30
31 #ifndef _SOSACCOUNT_H_
32 #define _SOSACCOUNT_H_
33
34 /* Forward declarations of SOS types. */
35 typedef struct __OpaqueSOSAccount *SOSAccountRef;
36
37 #include <CoreFoundation/CoreFoundation.h>
38
39 #include <Security/SecureObjectSync/SOSAccountTransaction.h>
40 #include <Security/SecureObjectSync/SOSCircle.h>
41 #include <Security/SecureObjectSync/SOSFullPeerInfo.h>
42 #include <Security/SecureObjectSync/SOSCloudCircle.h>
43 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
44 #include <Security/SecureObjectSync/SOSTransportKeyParameter.h>
45 #include <Security/SecureObjectSync/SOSTransportCircle.h>
46 #include <Security/SecureObjectSync/SOSTransportMessage.h>
47 #include <Security/SecureObjectSync/SOSRing.h>
48 #include <Security/SecureObjectSync/SOSPeerInfoSecurityProperties.h>
49
50 #include <dispatch/dispatch.h>
51
52 __BEGIN_DECLS
53
54 #define RETIREMENT_FINALIZATION_SECONDS (24*60*60)
55
56
57 typedef void (^SOSAccountCircleMembershipChangeBlock)(SOSCircleRef new_circle,
58 CFSetRef added_peers, CFSetRef removed_peers,
59 CFSetRef added_applicants, CFSetRef removed_applicants);
60 typedef void (^SOSAccountSyncablePeersBlock)(CFArrayRef trustedPeers, CFArrayRef addedPeers, CFArrayRef removedPeers);
61 typedef bool (^SOSAccountWaitForInitialSyncBlock)(SOSAccountRef account);
62 typedef void (^SOSAccountSaveBlock)(CFDataRef flattenedAccount, CFErrorRef flattenFailError);
63
64 SOSAccountRef SOSAccountCreate(CFAllocatorRef allocator,
65 CFDictionaryRef gestalt,
66 SOSDataSourceFactoryRef factory);
67 SOSAccountRef SOSAccountCreateBasic(CFAllocatorRef allocator,
68 CFDictionaryRef gestalt,
69 SOSDataSourceFactoryRef factory);
70
71
72 CFTypeID SOSAccountGetTypeID(void);
73
74 //
75 // MARK: Persistent Encode decode
76 //
77
78 SOSAccountRef SOSAccountCreateFromDER(CFAllocatorRef allocator, SOSDataSourceFactoryRef factory,
79 CFErrorRef* error,
80 const uint8_t** der_p, const uint8_t *der_end);
81
82 SOSAccountRef SOSAccountCreateFromDER_V3(CFAllocatorRef allocator,
83 SOSDataSourceFactoryRef factory,
84 CFErrorRef* error,
85 const uint8_t** der_p, const uint8_t *der_end);
86
87 SOSAccountRef SOSAccountCreateFromData(CFAllocatorRef allocator, CFDataRef circleData,
88 SOSDataSourceFactoryRef factory,
89 CFErrorRef* error);
90
91 size_t SOSAccountGetDEREncodedSize(SOSAccountRef cir, CFErrorRef *error);
92 uint8_t* SOSAccountEncodeToDER(SOSAccountRef cir, CFErrorRef* error, const uint8_t* der, uint8_t* der_end);
93 size_t SOSAccountGetDEREncodedSize_V3(SOSAccountRef cir, CFErrorRef *error);
94 uint8_t* SOSAccountEncodeToDER_V3(SOSAccountRef cir, CFErrorRef* error, const uint8_t* der, uint8_t* der_end);
95 CFDataRef SOSAccountCopyEncodedData(SOSAccountRef circle, CFAllocatorRef allocator, CFErrorRef *error);
96 //
97 //MARK: IDS Device ID
98 CFStringRef SOSAccountCopyDeviceID(SOSAccountRef account, CFErrorRef *error);
99 bool SOSAccountSetMyDSID(SOSAccountRef account, CFStringRef IDS, CFErrorRef* errror);
100 bool SOSAccountSendIDSTestMessage(SOSAccountRef account, CFStringRef message, CFErrorRef *error);
101 bool SOSAccountStartPingTest(SOSAccountRef account, CFStringRef message, CFErrorRef *error);
102 bool SOSAccountRetrieveDeviceIDFromIDSKeychainSyncingProxy(SOSAccountRef account, CFErrorRef *error);
103
104 //
105 // MARK: Credential management
106 //
107
108 SecKeyRef SOSAccountGetTrustedPublicCredential(SOSAccountRef account, CFErrorRef* error);
109
110 SecKeyRef SOSAccountGetPrivateCredential(SOSAccountRef account, CFErrorRef* error);
111 CFDataRef SOSAccountGetCachedPassword(SOSAccountRef account, CFErrorRef* error);
112
113 void SOSAccountSetParameters(SOSAccountRef account, CFDataRef parameters);
114
115 void SOSAccountPurgePrivateCredential(SOSAccountRef account);
116
117 bool SOSAccountTryUserCredentials(SOSAccountRef account,
118 CFStringRef user_account, CFDataRef user_password,
119 CFErrorRef *error);
120
121 bool SOSAccountAssertUserCredentials(SOSAccountRef account,
122 CFStringRef user_account, CFDataRef user_password,
123 CFErrorRef *error);
124
125 bool SOSAccountRetryUserCredentials(SOSAccountRef account);
126 void SOSAccountSetUnTrustedUserPublicKey(SOSAccountRef account, SecKeyRef publicKey);
127
128 bool SOSAccountGenerationSignatureUpdate(SOSAccountRef account, CFErrorRef *error);
129
130 //
131 // MARK: Circle management
132 //
133
134 bool SOSAccountUpdateCircle(SOSAccountRef account, SOSCircleRef circle, CFErrorRef *error);
135 void SOSTransportEachMessage(SOSAccountRef account, CFDictionaryRef updates, CFErrorRef *error);
136
137
138 SOSCCStatus SOSAccountGetCircleStatus(SOSAccountRef account, CFErrorRef* error);
139 CFStringRef SOSAccountGetSOSCCStatusString(SOSCCStatus status);
140 bool SOSAccountIsInCircle(SOSAccountRef account, CFErrorRef *error);
141 bool SOSAccountJoinCircles(SOSAccountTransactionRef aTxn, CFErrorRef* error);
142 bool SOSAccountJoinCirclesAfterRestore(SOSAccountTransactionRef aTxn, CFErrorRef* error);
143 bool SOSAccountLeaveCircle(SOSAccountRef account,CFErrorRef* error);
144 bool SOSAccountRemovePeersFromCircle(SOSAccountRef account, CFArrayRef peers, CFErrorRef* error);
145 bool SOSAccountBail(SOSAccountRef account, uint64_t limit_in_seconds, CFErrorRef* error);
146 bool SOSAccountAcceptApplicants(SOSAccountRef account, CFArrayRef applicants, CFErrorRef* error);
147 bool SOSAccountRejectApplicants(SOSAccountRef account, CFArrayRef applicants, CFErrorRef* error);
148
149 bool SOSAccountResetToOffering(SOSAccountTransactionRef aTxn, CFErrorRef* error);
150 bool SOSAccountResetToEmpty(SOSAccountRef account, CFErrorRef* error);
151 bool SOSValidateUserPublic(SOSAccountRef account, CFErrorRef* error);
152
153 void SOSAccountForEachCirclePeerExceptMe(SOSAccountRef account, void (^action)(SOSPeerInfoRef peer));
154
155 CFArrayRef SOSAccountCopyApplicants(SOSAccountRef account, CFErrorRef *error);
156 CFArrayRef SOSAccountCopyGeneration(SOSAccountRef account, CFErrorRef *error);
157 CFArrayRef SOSAccountCopyValidPeers(SOSAccountRef account, CFErrorRef *error);
158 CFArrayRef SOSAccountCopyPeersToListenTo(SOSAccountRef account, CFErrorRef *error);
159 CFArrayRef SOSAccountCopyNotValidPeers(SOSAccountRef account, CFErrorRef *error);
160 CFArrayRef SOSAccountCopyRetired(SOSAccountRef account, CFErrorRef *error);
161 CFArrayRef SOSAccountCopyViewUnaware(SOSAccountRef account, CFErrorRef *error);
162 CFArrayRef SOSAccountCopyPeers(SOSAccountRef account, CFErrorRef *error);
163 CFArrayRef SOSAccountCopyActivePeers(SOSAccountRef account, CFErrorRef *error);
164 CFArrayRef SOSAccountCopyActiveValidPeers(SOSAccountRef account, CFErrorRef *error);
165 CFArrayRef SOSAccountCopyConcurringPeers(SOSAccountRef account, CFErrorRef *error);
166
167 SOSFullPeerInfoRef SOSAccountCopyAccountIdentityPeerInfo(SOSAccountRef account, CFAllocatorRef allocator, CFErrorRef* error);
168 bool SOSAccountIsAccountIdentity(SOSAccountRef account, SOSPeerInfoRef peer_info, CFErrorRef *error);
169
170 enum DepartureReason SOSAccountGetLastDepartureReason(SOSAccountRef account, CFErrorRef* error);
171
172 //
173 // MARK: iCloud Identity
174 //
175 bool SOSAccountAddiCloudIdentity(SOSAccountRef account, SOSCircleRef circle, SecKeyRef user_key, CFErrorRef *error);
176 bool SOSAccountRemoveIncompleteiCloudIdentities(SOSAccountRef account, SOSCircleRef circle, SecKeyRef privKey, CFErrorRef *error);
177
178 //
179 // MARK: Save Block
180 //
181
182 void SOSAccountSetSaveBlock(SOSAccountRef account, SOSAccountSaveBlock saveBlock);
183 void SOSAccountFlattenToSaveBlock(SOSAccountRef account);
184
185 //
186 // MARK: Change blocks
187 //
188 void SOSAccountAddChangeBlock(SOSAccountRef a, SOSAccountCircleMembershipChangeBlock changeBlock);
189 void SOSAccountRemoveChangeBlock(SOSAccountRef a, SOSAccountCircleMembershipChangeBlock changeBlock);
190
191 void SOSAccountAddSyncablePeerBlock(SOSAccountRef a,
192 CFStringRef ds_name,
193 SOSAccountSyncablePeersBlock changeBlock);
194
195 //
196 // MARK: Local device gestalt change.
197 //
198 bool SOSAccountUpdateGestalt(SOSAccountRef account, CFDictionaryRef new_gestalt);
199
200 bool SOSAccountUpdateFullPeerInfo(SOSAccountRef account, CFSetRef minimumViews, CFSetRef excludedViews);
201
202 SOSViewResultCode SOSAccountUpdateView(SOSAccountRef account, CFStringRef viewname, SOSViewActionCode actionCode, CFErrorRef *error);
203
204 SOSViewResultCode SOSAccountViewStatus(SOSAccountRef account, CFStringRef viewname, CFErrorRef *error);
205
206 bool SOSAccountUpdateViewSets(SOSAccountRef account, CFSetRef enabledViews, CFSetRef disabledViews);
207
208 void SOSAccountPendEnableViewSet(SOSAccountRef account, CFSetRef enabledViews);
209 void SOSAccountPendDisableViewSet(SOSAccountRef account, CFSetRef disabledViews);
210
211
212 SOSSecurityPropertyResultCode SOSAccountUpdateSecurityProperty(SOSAccountRef account, CFStringRef property, SOSSecurityPropertyActionCode actionCode, CFErrorRef *error);
213
214 SOSSecurityPropertyResultCode SOSAccountSecurityPropertyStatus(SOSAccountRef account, CFStringRef property, CFErrorRef *error);
215
216
217 bool SOSAccountHandleParametersChange(SOSAccountRef account, CFDataRef updates, CFErrorRef *error);
218
219 bool SOSAccountSendIKSPSyncList(SOSAccountRef account, CFErrorRef *error);
220 bool SOSAccountSyncWithAllKVSPeers(SOSAccountRef account, CFErrorRef *error);
221
222 bool SOSAccountSyncWithKVSPeer(SOSAccountRef account, CFStringRef peerID, CFErrorRef *error);
223 bool SOSAccountSyncWithKVSUsingIDSID(SOSAccountRef account, CFStringRef deviceID, CFErrorRef *error);
224
225 bool SOSAccountSyncWithIDSPeer(SOSAccountRef account, CFStringRef peerID, CFErrorRef *error);
226
227 bool SOSAccountCleanupAfterPeer(SOSAccountRef account, size_t seconds, SOSCircleRef circle,
228 SOSPeerInfoRef cleanupPeer, CFErrorRef* error);
229
230 bool SOSAccountCleanupRetirementTickets(SOSAccountRef account, size_t seconds, CFErrorRef* error);
231
232 bool SOSAccountScanForRetired(SOSAccountRef account, SOSCircleRef circle, CFErrorRef *error);
233
234 SOSCircleRef SOSAccountCloneCircleWithRetirement(SOSAccountRef account, SOSCircleRef starting_circle, CFErrorRef *error);
235
236 bool SOSAccountPostDebugScope(SOSAccountRef account, CFTypeRef scope, CFErrorRef *error);
237
238 //
239 // MARK: Version incompatibility Functions
240 //
241 CFStringRef SOSAccountCopyIncompatibilityInfo(SOSAccountRef account, CFErrorRef* error);
242
243 //
244 // MARK: Backup functions
245 //
246
247 bool SOSAccountIsBackupRingEmpty(SOSAccountRef account, CFStringRef viewName);
248 bool SOSAccountNewBKSBForView(SOSAccountRef account, CFStringRef viewName, CFErrorRef *error);
249
250 bool SOSAccountSetBackupPublicKey(SOSAccountTransactionRef aTxn, CFDataRef backupKey, CFErrorRef *error);
251 bool SOSAccountRemoveBackupPublickey(SOSAccountTransactionRef aTxn, CFErrorRef *error);
252 bool SOSAccountSetBSKBagForAllSlices(SOSAccountRef account, CFDataRef backupSlice, bool setupV0Only, CFErrorRef *error);
253
254 SOSBackupSliceKeyBagRef SOSAccountBackupSliceKeyBagForView(SOSAccountRef account, CFStringRef viewName, CFErrorRef* error);
255
256 bool SOSAccountIsLastBackupPeer(SOSAccountRef account, CFErrorRef *error);
257
258 //
259 // MARK: Private functions
260 //
261
262 dispatch_queue_t SOSAccountGetQueue(SOSAccountRef account);
263
264 typedef bool (^SOSAccountSendBlock)(CFStringRef key, CFDataRef message, CFErrorRef *error);
265
266 //
267 // MARK: Utility functions
268 //
269
270 CFStringRef SOSAccountCreateCompactDescription(SOSAccountRef a);
271 CFStringRef SOSInterestListCopyDescription(CFArrayRef interests);
272
273 //
274 // MARK: View Funcitons
275 //
276
277 // Use these to tell the engine what views are common to myPeer and other circle peers
278 CFArrayRef SOSCreateActiveViewIntersectionArrayForPeerID(SOSAccountRef account, CFStringRef peerID);
279 CFDictionaryRef SOSViewsCreateActiveViewMatrixDictionary(SOSAccountRef account, SOSCircleRef circle, CFErrorRef *error);
280
281 const uint8_t* der_decode_cloud_parameters(CFAllocatorRef allocator,
282 CFIndex algorithmID, SecKeyRef* publicKey,
283 CFDataRef *parameters,
284 CFErrorRef* error,
285 const uint8_t* der, const uint8_t* der_end);
286
287 /* CFSet <-> XPC functions */
288 CFSetRef CreateCFSetRefFromXPCObject(xpc_object_t xpcSetDER, CFErrorRef* error);
289 xpc_object_t CreateXPCObjectWithCFSetRef(CFSetRef setref, CFErrorRef *error);
290
291
292 //
293 // MARK: HSA2 Piggyback Support Functions
294 //
295
296 SOSPeerInfoRef SOSAccountCopyApplication(SOSAccountRef account, CFErrorRef*);
297 CFDataRef SOSAccountCopyCircleJoiningBlob(SOSAccountRef account, SOSPeerInfoRef applicant, CFErrorRef *error);
298 bool SOSAccountJoinWithCircleJoiningBlob(SOSAccountRef account, CFDataRef joiningBlob, CFErrorRef *error);
299
300 //
301 // MARK: Initial-Sync
302 //
303 bool SOSAccountHasCompletedInitialSync(SOSAccountRef account);
304 CFMutableSetRef SOSAccountCopyUnsyncedInitialViews(SOSAccountRef account);
305 bool SOSAccountHasCompletedRequiredBackupSync(SOSAccountRef account);
306
307 //
308 // MARK: State Logging
309 //
310 void SOSAccountLogState(SOSAccountRef account);
311 void SOSAccountLogViewState(SOSAccountRef account);
312
313 //
314 // MARK: Checking other peer views
315 //
316
317 CFBooleanRef SOSAccountPeersHaveViewsEnabled(SOSAccountRef account, CFArrayRef viewNames, CFErrorRef *error);
318
319 __END_DECLS
320
321 #endif /* !_SOSACCOUNT_H_ */