2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
27 The functions provided in SOSCircle.h provide an interface to a
28 secure object syncing circle for a single class
31 #ifndef _SOSACCOUNT_H_
32 #define _SOSACCOUNT_H_
34 /* Forward declarations of SOS types. */
35 typedef struct __OpaqueSOSAccount
*SOSAccountRef
;
38 #include <CoreFoundation/CoreFoundation.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>
50 #include <dispatch/dispatch.h>
54 #define RETIREMENT_FINALIZATION_SECONDS (24*60*60)
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
);
63 SOSAccountRef
SOSAccountCreate(CFAllocatorRef allocator
,
64 CFDictionaryRef gestalt
,
65 SOSDataSourceFactoryRef factory
);
66 SOSAccountRef
SOSAccountCreateBasic(CFAllocatorRef allocator
,
67 CFDictionaryRef gestalt
,
68 SOSDataSourceFactoryRef factory
);
71 CFTypeID
SOSAccountGetTypeID(void);
74 // MARK: Persistent Encode decode
77 SOSAccountRef
SOSAccountCreateFromDER(CFAllocatorRef allocator
, SOSDataSourceFactoryRef factory
,
79 const uint8_t** der_p
, const uint8_t *der_end
);
81 SOSAccountRef
SOSAccountCreateFromDER_V3(CFAllocatorRef allocator
,
82 SOSDataSourceFactoryRef factory
,
84 const uint8_t** der_p
, const uint8_t *der_end
);
86 SOSAccountRef
SOSAccountCreateFromData(CFAllocatorRef allocator
, CFDataRef circleData
,
87 SOSDataSourceFactoryRef factory
,
90 size_t SOSAccountGetDEREncodedSize(SOSAccountRef cir
, CFErrorRef
*error
);
91 uint8_t* SOSAccountEncodeToDER(SOSAccountRef cir
, CFErrorRef
* error
, const uint8_t* der
, uint8_t* der_end
);
92 size_t SOSAccountGetDEREncodedSize_V3(SOSAccountRef cir
, CFErrorRef
*error
);
93 uint8_t* SOSAccountEncodeToDER_V3(SOSAccountRef cir
, CFErrorRef
* error
, const uint8_t* der
, uint8_t* der_end
);
94 CFDataRef
SOSAccountCopyEncodedData(SOSAccountRef circle
, CFAllocatorRef allocator
, CFErrorRef
*error
);
97 CFStringRef
SOSAccountCopyDeviceID(SOSAccountRef account
, CFErrorRef
*error
);
98 bool SOSAccountSetMyDSID(SOSAccountRef account
, CFStringRef IDS
, CFErrorRef
* errror
);
99 bool SOSAccountSendIDSTestMessage(SOSAccountRef account
, CFStringRef message
, CFErrorRef
*error
);
100 bool SOSAccountStartPingTest(SOSAccountRef account
, CFStringRef message
, CFErrorRef
*error
);
101 bool SOSAccountRetrieveDeviceIDFromIDSKeychainSyncingProxy(SOSAccountRef account
, CFErrorRef
*error
);
104 // MARK: Credential management
107 SecKeyRef
SOSAccountGetPrivateCredential(SOSAccountRef account
, CFErrorRef
* error
);
108 CFDataRef
SOSAccountGetCachedPassword(SOSAccountRef account
, CFErrorRef
* error
);
110 void SOSAccountSetParameters(SOSAccountRef account
, CFDataRef parameters
);
112 void SOSAccountPurgePrivateCredential(SOSAccountRef account
);
114 bool SOSAccountTryUserCredentials(SOSAccountRef account
,
115 CFStringRef user_account
, CFDataRef user_password
,
118 bool SOSAccountAssertUserCredentials(SOSAccountRef account
,
119 CFStringRef user_account
, CFDataRef user_password
,
122 bool SOSAccountRetryUserCredentials(SOSAccountRef account
);
123 void SOSAccountSetUnTrustedUserPublicKey(SOSAccountRef account
, SecKeyRef publicKey
);
125 bool SOSAccountGenerationSignatureUpdate(SOSAccountRef account
, CFErrorRef
*error
);
128 // MARK: Circle management
131 bool SOSAccountUpdateCircle(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
*error
);
132 void SOSTransportEachMessage(SOSAccountRef account
, CFDictionaryRef updates
, CFErrorRef
*error
);
135 SOSCCStatus
SOSAccountGetCircleStatus(SOSAccountRef account
, CFErrorRef
* error
);
136 bool SOSAccountIsInCircle(SOSAccountRef account
, CFErrorRef
*error
);
137 bool SOSAccountJoinCircles(SOSAccountRef account
, CFErrorRef
* error
);
138 bool SOSAccountJoinCirclesAfterRestore(SOSAccountRef account
, CFErrorRef
* error
);
139 bool SOSAccountLeaveCircle(SOSAccountRef account
,CFErrorRef
* error
);
140 bool SOSAccountRemovePeersFromCircle(SOSAccountRef account
, CFArrayRef peers
, CFErrorRef
* error
);
141 bool SOSAccountBail(SOSAccountRef account
, uint64_t limit_in_seconds
, CFErrorRef
* error
);
142 bool SOSAccountAcceptApplicants(SOSAccountRef account
, CFArrayRef applicants
, CFErrorRef
* error
);
143 bool SOSAccountRejectApplicants(SOSAccountRef account
, CFArrayRef applicants
, CFErrorRef
* error
);
145 bool SOSAccountResetToOffering(SOSAccountRef account
, CFErrorRef
* error
);
146 bool SOSAccountResetToEmpty(SOSAccountRef account
, CFErrorRef
* error
);
147 bool SOSValidateUserPublic(SOSAccountRef account
, CFErrorRef
* error
);
149 void SOSAccountForEachCirclePeerExceptMe(SOSAccountRef account
, void (^action
)(SOSPeerInfoRef peer
));
151 CFArrayRef
SOSAccountCopyApplicants(SOSAccountRef account
, CFErrorRef
*error
);
152 CFArrayRef
SOSAccountCopyGeneration(SOSAccountRef account
, CFErrorRef
*error
);
153 CFArrayRef
SOSAccountCopyValidPeers(SOSAccountRef account
, CFErrorRef
*error
);
154 CFArrayRef
SOSAccountCopyPeersToListenTo(SOSAccountRef account
, CFErrorRef
*error
);
155 CFArrayRef
SOSAccountCopyNotValidPeers(SOSAccountRef account
, CFErrorRef
*error
);
156 CFArrayRef
SOSAccountCopyRetired(SOSAccountRef account
, CFErrorRef
*error
);
157 CFArrayRef
SOSAccountCopyViewUnaware(SOSAccountRef account
, CFErrorRef
*error
);
158 CFArrayRef
SOSAccountCopyPeers(SOSAccountRef account
, CFErrorRef
*error
);
159 CFArrayRef
SOSAccountCopyActivePeers(SOSAccountRef account
, CFErrorRef
*error
);
160 CFArrayRef
SOSAccountCopyActiveValidPeers(SOSAccountRef account
, CFErrorRef
*error
);
161 CFArrayRef
SOSAccountCopyConcurringPeers(SOSAccountRef account
, CFErrorRef
*error
);
163 SOSFullPeerInfoRef
SOSAccountCopyAccountIdentityPeerInfo(SOSAccountRef account
, CFAllocatorRef allocator
, CFErrorRef
* error
);
164 bool SOSAccountIsAccountIdentity(SOSAccountRef account
, SOSPeerInfoRef peer_info
, CFErrorRef
*error
);
166 enum DepartureReason
SOSAccountGetLastDepartureReason(SOSAccountRef account
, CFErrorRef
* error
);
169 // MARK: Change blocks
171 void SOSAccountAddChangeBlock(SOSAccountRef a
, SOSAccountCircleMembershipChangeBlock changeBlock
);
172 void SOSAccountRemoveChangeBlock(SOSAccountRef a
, SOSAccountCircleMembershipChangeBlock changeBlock
);
174 void SOSAccountAddSyncablePeerBlock(SOSAccountRef a
,
176 SOSAccountSyncablePeersBlock changeBlock
);
179 // MARK: Local device gestalt change.
181 bool SOSAccountUpdateGestalt(SOSAccountRef account
, CFDictionaryRef new_gestalt
);
183 bool SOSAccountUpdateFullPeerInfo(SOSAccountRef account
, CFSetRef minimumViews
, CFSetRef excludedViews
);
185 SOSViewResultCode
SOSAccountUpdateView(SOSAccountRef account
, CFStringRef viewname
, SOSViewActionCode actionCode
, CFErrorRef
*error
);
187 SOSViewResultCode
SOSAccountViewStatus(SOSAccountRef account
, CFStringRef viewname
, CFErrorRef
*error
);
189 bool SOSAccountUpdateViewSets(SOSAccountRef account
, CFSetRef enabledViews
, CFSetRef disabledViews
);
191 SOSSecurityPropertyResultCode
SOSAccountUpdateSecurityProperty(SOSAccountRef account
, CFStringRef property
, SOSSecurityPropertyActionCode actionCode
, CFErrorRef
*error
);
193 SOSSecurityPropertyResultCode
SOSAccountSecurityPropertyStatus(SOSAccountRef account
, CFStringRef property
, CFErrorRef
*error
);
196 bool SOSAccountHandleParametersChange(SOSAccountRef account
, CFDataRef updates
, CFErrorRef
*error
);
198 bool SOSAccountSyncWithAllPeers(SOSAccountRef account
, CFErrorRef
*error
);
200 bool SOSAccountCleanupAfterPeer(SOSAccountRef account
, size_t seconds
, SOSCircleRef circle
,
201 SOSPeerInfoRef cleanupPeer
, CFErrorRef
* error
);
203 bool SOSAccountCleanupRetirementTickets(SOSAccountRef account
, size_t seconds
, CFErrorRef
* error
);
205 bool SOSAccountScanForRetired(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
*error
);
207 SOSCircleRef
SOSAccountCloneCircleWithRetirement(SOSAccountRef account
, SOSCircleRef starting_circle
, CFErrorRef
*error
);
209 bool SOSAccountPostDebugScope(SOSAccountRef account
, CFTypeRef scope
, CFErrorRef
*error
);
212 // MARK: Version incompatibility Functions
214 CFStringRef
SOSAccountCopyIncompatibilityInfo(SOSAccountRef account
, CFErrorRef
* error
);
217 // MARK: Backup functions
220 bool SOSAccountIsBackupRingEmpty(SOSAccountRef account
, CFStringRef viewName
);
221 bool SOSAccountStartNewBackup(SOSAccountRef account
, CFStringRef viewName
, CFErrorRef
*error
);
223 bool SOSAccountSetBackupPublicKey(SOSAccountRef account
, CFDataRef backupKey
, CFErrorRef
*error
);
224 bool SOSAccountRemoveBackupPublickey(SOSAccountRef account
, CFErrorRef
*error
);
225 bool SOSAccountSetBSKBagForAllSlices(SOSAccountRef account
, CFDataRef backupSlice
, bool setupV0Only
, CFErrorRef
*error
);
227 SOSBackupSliceKeyBagRef
SOSAccountBackupSliceKeyBagForView(SOSAccountRef account
, CFStringRef viewName
, CFErrorRef
* error
);
230 // MARK: Private functions
233 dispatch_queue_t
SOSAccountGetQueue(SOSAccountRef account
);
235 typedef bool (^SOSAccountSendBlock
)(CFStringRef key
, CFDataRef message
, CFErrorRef
*error
);
238 // MARK: Utility functions
241 CFStringRef
SOSAccountCreateCompactDescription(SOSAccountRef a
);
242 CFStringRef
SOSInterestListCopyDescription(CFArrayRef interests
);
245 // MARK: View Funcitons
248 // Use these to tell the engine what views are common to myPeer and other circle peers
249 CFArrayRef
SOSCreateActiveViewIntersectionArrayForPeerID(SOSAccountRef account
, CFStringRef peerID
);
250 CFDictionaryRef
SOSViewsCreateActiveViewMatrixDictionary(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
*error
);
253 // MARK: Transactional functions
256 void SOSAccountFinishTransaction(SOSAccountRef account
);
258 const uint8_t* der_decode_cloud_parameters(CFAllocatorRef allocator
,
259 CFIndex algorithmID
, SecKeyRef
* publicKey
,
260 CFDataRef
*parameters
,
262 const uint8_t* der
, const uint8_t* der_end
);
264 /* CFSet <-> XPC functions */
265 CFSetRef
CreateCFSetRefFromXPCObject(xpc_object_t xpcSetDER
, CFErrorRef
* error
);
266 xpc_object_t
CreateXPCObjectWithCFSetRef(CFSetRef setref
, CFErrorRef
*error
);
271 #endif /* !_SOSACCOUNT_H_ */