]> git.saurik.com Git - apple/security.git/blame - keychain/SecureObjectSync/SOSAccount.h
Security-59754.80.3.tar.gz
[apple/security.git] / keychain / 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
34#include <CoreFoundation/CoreFoundation.h>
866f8763 35#include <Foundation/Foundation.h>
b54c578e
A
36#include "keychain/SecureObjectSync/SOSAccountPriv.h"
37#include "keychain/SecureObjectSync/SOSCircle.h"
38#include "keychain/SecureObjectSync/SOSFullPeerInfo.h"
5c19dc3a
A
39#include <Security/SecureObjectSync/SOSCloudCircle.h>
40#include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
b54c578e
A
41#include "keychain/SecureObjectSync/SOSTransportCircle.h"
42#include "keychain/SecureObjectSync/SOSRing.h"
43#include "keychain/SecureObjectSync/SOSRecoveryKeyBag.h"
44#import "keychain/SecureObjectSync/SOSAccountTransaction.h"
427c49bc
A
45#include <dispatch/dispatch.h>
46
d64be36e
A
47extern NSString* const kSOSIdentityStatusCompleteIdentity;
48extern NSString* const kSOSIdentityStatusKeyOnly;
49extern NSString* const kSOSIdentityStatusPeerOnly;
50
866f8763
A
51@class SOSAccount;
52
427c49bc
A
53__BEGIN_DECLS
54
55#define RETIREMENT_FINALIZATION_SECONDS (24*60*60)
56
79b9da22
A
57typedef void (^SOSAccountCircleMembershipChangeBlock)(SOSAccount* account,
58 SOSCircleRef new_circle,
d8f41ccd
A
59 CFSetRef added_peers, CFSetRef removed_peers,
60 CFSetRef added_applicants, CFSetRef removed_applicants);
427c49bc 61
866f8763
A
62CFTypeID SOSAccountGetTypeID(void);
63
64SOSAccount* SOSAccountCreate(CFAllocatorRef allocator,
d8f41ccd
A
65 CFDictionaryRef gestalt,
66 SOSDataSourceFactoryRef factory);
427c49bc 67
427c49bc
A
68//
69// MARK: Credential management
70//
71
866f8763
A
72SecKeyRef SOSAccountGetTrustedPublicCredential(SOSAccount* account, CFErrorRef* error);
73
74SecKeyRef SOSAccountGetPrivateCredential(SOSAccount* account, CFErrorRef* error);
75CFDataRef SOSAccountGetCachedPassword(SOSAccount* account, CFErrorRef* error);
76void SOSAccountStashAccountKey(SOSAccount* account);
77SecKeyRef SOSAccountCopyStashedUserPrivateKey(SOSAccount* account, CFErrorRef *error);
fa7225c8 78
866f8763 79void SOSAccountSetParameters(SOSAccount* account, CFDataRef parameters);
5c19dc3a 80
866f8763 81void SOSAccountPurgePrivateCredential(SOSAccount* account);
e0e0d90e 82
866f8763 83void SOSAccountRestartPrivateCredentialTimer(SOSAccount* account);
427c49bc 84
866f8763 85bool SOSAccountTryUserCredentials(SOSAccount* account,
427c49bc
A
86 CFStringRef user_account, CFDataRef user_password,
87 CFErrorRef *error);
88
866f8763
A
89bool SOSAccountTryUserPrivateKey(SOSAccount* account, SecKeyRef user_private, CFErrorRef *error);
90
91bool SOSAccountValidateAccountCredential(SOSAccount* account, SecKeyRef accountPrivateKey, CFErrorRef *error);
92bool SOSAccountAssertStashedAccountCredential(SOSAccount* account, CFErrorRef *error);
93bool SOSAccountAssertUserCredentials(SOSAccount* account,
427c49bc
A
94 CFStringRef user_account, CFDataRef user_password,
95 CFErrorRef *error);
96
866f8763
A
97bool SOSAccountRetryUserCredentials(SOSAccount* account);
98void SOSAccountSetUnTrustedUserPublicKey(SOSAccount* account, SecKeyRef publicKey);
5c19dc3a 99
866f8763 100bool SOSAccountGenerationSignatureUpdate(SOSAccount* account, CFErrorRef *error);
427c49bc
A
101
102//
103// MARK: Circle management
104//
427c49bc 105
866f8763
A
106bool SOSAccountUpdateCircle(SOSAccount* account, SOSCircleRef circle, CFErrorRef *error);
107void SOSTransportEachMessage(SOSAccount* account, CFDictionaryRef updates, CFErrorRef *error);
427c49bc
A
108
109
fa7225c8 110CFStringRef SOSAccountGetSOSCCStatusString(SOSCCStatus status);
866f8763 111SOSCCStatus SOSAccountGetSOSCCStatusFromString(CFStringRef status);
d64be36e
A
112bool SOSAccountJoinCircles(SOSAccountTransaction* aTxn, CFErrorRef* error);
113bool SOSAccountJoinCirclesAfterRestore(SOSAccountTransaction* aTxn, CFErrorRef* error);
114bool SOSAccountRemovePeersFromCircle(SOSAccount* account, CFArrayRef peers, CFErrorRef* error);
866f8763
A
115bool SOSAccountBail(SOSAccount* account, uint64_t limit_in_seconds, CFErrorRef* error);
116bool SOSAccountAcceptApplicants(SOSAccount* account, CFArrayRef applicants, CFErrorRef* error);
117bool SOSAccountRejectApplicants(SOSAccount* account, CFArrayRef applicants, CFErrorRef* error);
427c49bc 118
866f8763
A
119bool SOSValidateUserPublic(SOSAccount* account, CFErrorRef* error);
120
121void SOSAccountForEachCirclePeerExceptMe(SOSAccount* account, void (^action)(SOSPeerInfoRef peer));
122
123CFArrayRef SOSAccountCopyApplicants(SOSAccount* account, CFErrorRef *error);
124CFArrayRef SOSAccountCopyGeneration(SOSAccount* account, CFErrorRef *error);
125CFArrayRef SOSAccountCopyValidPeers(SOSAccount* account, CFErrorRef *error);
126CFArrayRef SOSAccountCopyPeersToListenTo(SOSAccount* account, CFErrorRef *error);
127CFArrayRef SOSAccountCopyNotValidPeers(SOSAccount* account, CFErrorRef *error);
128CFArrayRef SOSAccountCopyRetired(SOSAccount* account, CFErrorRef *error);
129CFArrayRef SOSAccountCopyViewUnaware(SOSAccount* account, CFErrorRef *error);
130CFArrayRef SOSAccountCopyPeers(SOSAccount* account, CFErrorRef *error);
131CFArrayRef SOSAccountCopyActivePeers(SOSAccount* account, CFErrorRef *error);
ecaf5866 132CFArrayRef CF_RETURNS_RETAINED SOSAccountCopyActiveValidPeers(SOSAccount* account, CFErrorRef *error);
866f8763
A
133CFArrayRef SOSAccountCopyConcurringPeers(SOSAccount* account, CFErrorRef *error);
134
135bool SOSAccountIsAccountIdentity(SOSAccount* account, SOSPeerInfoRef peer_info, CFErrorRef *error);
136
137enum DepartureReason SOSAccountGetLastDepartureReason(SOSAccount* account, CFErrorRef* error);
fa7225c8
A
138
139//
866f8763 140// MARK: iCloud Identity
fa7225c8 141//
866f8763 142bool SOSAccountRemoveIncompleteiCloudIdentities(SOSAccount* account, SOSCircleRef circle, SecKeyRef privKey, CFErrorRef *error);
fa7225c8 143
427c49bc
A
144//
145// MARK: Change blocks
146//
866f8763
A
147void SOSAccountAddChangeBlock(SOSAccount* a, SOSAccountCircleMembershipChangeBlock changeBlock);
148void SOSAccountRemoveChangeBlock(SOSAccount* a, SOSAccountCircleMembershipChangeBlock changeBlock);
427c49bc 149
d8f41ccd 150
427c49bc
A
151//
152// MARK: Local device gestalt change.
153//
866f8763 154CFDictionaryRef SOSAccountCopyGestalt(SOSAccount* account);
6b200bc3 155
866f8763 156CFDictionaryRef SOSAccountCopyV2Dictionary(SOSAccount* account);
6b200bc3 157
866f8763 158void SOSAccountPendDisableViewSet(SOSAccount* account, CFSetRef disabledViews);
6b200bc3 159
866f8763
A
160void SOSAccountUpdateOutOfSyncViews(SOSAccountTransaction* aTxn, CFSetRef viewsInSync);
161void SOSAccountPeerGotInSync(SOSAccountTransaction* aTxn, CFStringRef peerID, CFSetRef views);
5c19dc3a 162
866f8763 163bool SOSAccountHandleParametersChange(SOSAccount* account, CFDataRef updates, CFErrorRef *error);
427c49bc 164
d64be36e
A
165//
166// MARK: Local device key access from account object - can call without lock without endangering peerinfo.
167//
168SecKeyRef SOSAccountCopyDevicePrivateKey(SOSAccount* account, CFErrorRef *error);
169SecKeyRef SOSAccountCopyDevicePublicKey(SOSAccount* account, CFErrorRef *error);
170
6b200bc3
A
171//
172// MARK: Requests for syncing later
173//
866f8763
A
174bool SOSAccountRequestSyncWithAllPeers(SOSAccountTransaction* txn, CFErrorRef *error);
175CF_RETURNS_RETAINED CFMutableSetRef SOSAccountSyncWithPeers(SOSAccountTransaction* txn, CFSetRef /* CFStringRef */ peerIDs, CFErrorRef *error);
866f8763
A
176CFSetRef SOSAccountSyncWithPeersOverKVS(SOSAccountTransaction* txn, CFSetRef peers);
177bool SOSAccountInflateTransports(SOSAccount* account, CFStringRef circleName, CFErrorRef *error);
6b200bc3 178
805875f8
A
179void
180SOSAccountTriggerSyncWithBackupPeer(CFStringRef peer);
181
6b200bc3
A
182//
183// MARK: Outgoing/Sync functions
184//
185
866f8763 186bool SOSAccountSyncWithKVSPeerWithMessage(SOSAccountTransaction* txn, CFStringRef peerid, CFDataRef message, CFErrorRef *error);
6b200bc3 187
866f8763
A
188CF_RETURNS_RETAINED CFSetRef SOSAccountProcessSyncWithPeers(SOSAccountTransaction* txn, CFSetRef /* CFStringRef */ peers, CFSetRef /* CFStringRef */ backupPeers, CFErrorRef *error);
189CF_RETURNS_RETAINED CFSetRef SOSAccountCopyBackupPeersAndForceSync(SOSAccountTransaction* txn, CFErrorRef *error);
fa7225c8 190
6b200bc3
A
191//
192// MARK: Cleanup functions
193//
427c49bc 194
866f8763 195bool SOSAccountScanForRetired(SOSAccount* account, SOSCircleRef circle, CFErrorRef *error);
ecaf5866 196CF_RETURNS_RETAINED SOSCircleRef SOSAccountCloneCircleWithRetirement(SOSAccount* account, SOSCircleRef starting_circle, CFErrorRef *error);
5c19dc3a 197
427c49bc 198//
5c19dc3a 199// MARK: Backup functions
427c49bc
A
200//
201
866f8763
A
202bool SOSAccountIsBackupRingEmpty(SOSAccount* account, CFStringRef viewName);
203bool SOSAccountNewBKSBForView(SOSAccount* account, CFStringRef viewName, CFErrorRef *error);
5c19dc3a 204
d64be36e 205void SOSAccountProcessBackupRings(SOSAccount* account);
b54c578e 206bool SOSAccountValidateBackupRingForView(SOSAccount* account, CFStringRef viewName, CFErrorRef *error);
866f8763
A
207bool SOSAccountSetBackupPublicKey(SOSAccountTransaction* aTxn, CFDataRef backupKey, CFErrorRef *error);
208bool SOSAccountRemoveBackupPublickey(SOSAccountTransaction* aTxn, CFErrorRef *error);
79b9da22 209bool SOSAccountBackupUpdateBackupPublicKey(SOSAccount *account, CFDataRef backupKey);
866f8763 210bool SOSAccountSetBSKBagForAllSlices(SOSAccount* account, CFDataRef backupSlice, bool setupV0Only, CFErrorRef *error);
5c19dc3a 211
ecaf5866 212CF_RETURNS_RETAINED SOSBackupSliceKeyBagRef SOSAccountBackupSliceKeyBagForView(SOSAccount* account, CFStringRef viewName, CFErrorRef* error);
e3d460c9 213
6b200bc3
A
214//
215// MARK: Recovery Public Key Functions
216//
866f8763
A
217bool SOSAccountRegisterRecoveryPublicKey(SOSAccountTransaction* txn, CFDataRef recovery_key, CFErrorRef *error);
218CFDataRef SOSAccountCopyRecoveryPublicKey(SOSAccountTransaction* txn, CFErrorRef *error);
219bool SOSAccountClearRecoveryPublicKey(SOSAccountTransaction* txn, CFDataRef recovery_key, CFErrorRef *error);
b54c578e
A
220
221
222// Internal calls that sets or clears Recovery Keys for the Account Object Provided by Clients
866f8763
A
223bool SOSAccountSetRecoveryKey(SOSAccount* account, CFDataRef pubData, CFErrorRef *error);
224bool SOSAccountRemoveRecoveryKey(SOSAccount* account, CFErrorRef *error);
b54c578e
A
225
226
866f8763
A
227CFDataRef SOSAccountCopyRecoveryPublic(CFAllocatorRef allocator, SOSAccount* account, CFErrorRef *error);
228bool SOSAccountRecoveryKeyIsInBackupAndCurrentInView(SOSAccount* account, CFStringRef viewname);
229bool SOSAccountSetRecoveryKeyBagEntry(CFAllocatorRef allocator, SOSAccount* account, SOSRecoveryKeyBagRef rkbg, CFErrorRef *error);
230SOSRecoveryKeyBagRef SOSAccountCopyRecoveryKeyBagEntry(CFAllocatorRef allocator, SOSAccount* account, CFErrorRef *error);
231void SOSAccountEnsureRecoveryRing(SOSAccount* account);
6b200bc3 232
5c19dc3a
A
233//
234// MARK: Private functions
235//
427c49bc 236
866f8763 237dispatch_queue_t SOSAccountGetQueue(SOSAccount* account);
427c49bc 238
d8f41ccd 239typedef bool (^SOSAccountSendBlock)(CFStringRef key, CFDataRef message, CFErrorRef *error);
427c49bc
A
240
241//
242// MARK: Utility functions
243//
244
245CFStringRef SOSInterestListCopyDescription(CFArrayRef interests);
246
fa7225c8
A
247//
248// MARK: HSA2 Piggyback Support Functions
249//
866f8763
A
250SOSPeerInfoRef SOSAccountCopyApplication(SOSAccount* account, CFErrorRef*);
251CFDataRef SOSAccountCopyCircleJoiningBlob(SOSAccount* account, SOSPeerInfoRef applicant, CFErrorRef *error);
252bool SOSAccountJoinWithCircleJoiningBlob(SOSAccount* account, CFDataRef joiningBlob, PiggyBackProtocolVersion version, CFErrorRef *error);
7fb2cbd2 253CFDataRef SOSAccountCopyInitialSyncData(SOSAccount* account, SOSInitialSyncFlags flags, CFErrorRef *error);
866f8763 254
fa7225c8
A
255//
256// MARK: Initial-Sync
257//
866f8763 258CFMutableSetRef SOSAccountCopyUnsyncedInitialViews(SOSAccount* account);
fa7225c8
A
259
260//
261// MARK: State Logging
262//
866f8763
A
263void SOSAccountLogState(SOSAccount* account);
264void SOSAccountLogViewState(SOSAccount* account);
265void SOSAccountConsiderLoggingEngineState(SOSAccountTransaction* txn);
fa7225c8
A
266
267//
268// MARK: Checking other peer views
269//
270
866f8763 271CFBooleanRef SOSAccountPeersHaveViewsEnabled(SOSAccount* account, CFArrayRef viewNames, CFErrorRef *error);
fa7225c8 272
866f8763
A
273void SOSAccountSetTestSerialNumber(SOSAccount* account, CFStringRef serial);
274SOSViewResultCode SOSAccountVirtualV0Behavior(SOSAccount* account, SOSViewActionCode actionCode);
275
276
277bool SOSAccountIsPeerRetired(SOSAccount* account, CFSetRef peers);
278void SOSAccountNotifyOfChange(SOSAccount* account, SOSCircleRef oldCircle, SOSCircleRef newCircle);
6b200bc3
A
279
280
281//
282// MARK: Syncing status functions
283//
866f8763
A
284bool SOSAccountMessageFromPeerIsPending(SOSAccountTransaction* txn, SOSPeerInfoRef peer, CFErrorRef *error);
285bool SOSAccountSendToPeerIsPending(SOSAccountTransaction* txn, SOSPeerInfoRef peer, CFErrorRef *error);
286
287//
288// MARK: OTR
289//
ecaf5866 290void SOSAccountResetOTRNegotiationCoder(SOSAccount* account, CFStringRef peerid);
866f8763
A
291void SOSAccountTimerFiredSendNextMessage(SOSAccountTransaction* txn, NSString* peerid, NSString* accessGroup);
292
7fb2cbd2 293NSArray<NSDictionary *>* SOSAccountGetAllTLKs(void);
d64be36e
A
294NSArray<NSDictionary *>* SOSAccountGetSelectedTLKs(void);
295
ecaf5866 296CF_RETURNS_RETAINED CFMutableArrayRef SOSAccountCopyiCloudIdentities(SOSAccount* account);
6b200bc3 297
650c69f3
A
298bool SOSAccountEvaluateKeysAndCircle(SOSAccountTransaction *txn, CFErrorRef *block_error);
299
427c49bc
A
300__END_DECLS
301
302#endif /* !_SOSACCOUNT_H_ */