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