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 <SecureObjectSync/SOSCircle.h>
41 #include <SecureObjectSync/SOSFullPeerInfo.h>
42 #include <SecureObjectSync/SOSCloudCircle.h>
43 #include <SecureObjectSync/SOSCloudCircleInternal.h>
44 #include <SecureObjectSync/SOSTransportKeyParameter.h>
45 #include <SecureObjectSync/SOSTransportCircle.h>
46 #include <SecureObjectSync/SOSTransportMessage.h>
48 #include <dispatch/dispatch.h>
52 #define RETIREMENT_FINALIZATION_SECONDS (24*60*60)
55 typedef void (^SOSAccountCircleMembershipChangeBlock
)(SOSCircleRef new_circle
,
56 CFSetRef added_peers
, CFSetRef removed_peers
,
57 CFSetRef added_applicants
, CFSetRef removed_applicants
);
58 typedef void (^SOSAccountSyncablePeersBlock
)(CFArrayRef trustedPeers
, CFArrayRef addedPeers
, CFArrayRef removedPeers
);
60 SOSAccountRef
SOSAccountGetShared(void);
61 SOSAccountRef
SOSAccountCreate(CFAllocatorRef allocator
,
62 CFDictionaryRef gestalt
,
63 SOSDataSourceFactoryRef factory
);
64 SOSAccountRef
SOSAccountCreateBasic(CFAllocatorRef allocator
,
65 CFDictionaryRef gestalt
,
66 SOSDataSourceFactoryRef factory
);
69 // MARK: Persistent Encode decode
72 SOSAccountRef
SOSAccountCreateFromDER(CFAllocatorRef allocator
, SOSDataSourceFactoryRef factory
,
74 const uint8_t** der_p
, const uint8_t *der_end
);
76 SOSAccountRef
SOSAccountCreateFromDER_V3(CFAllocatorRef allocator
,
77 SOSDataSourceFactoryRef factory
,
79 const uint8_t** der_p
, const uint8_t *der_end
);
81 SOSAccountRef
SOSAccountCreateFromData(CFAllocatorRef allocator
, CFDataRef circleData
,
82 SOSDataSourceFactoryRef factory
,
85 size_t SOSAccountGetDEREncodedSize(SOSAccountRef cir
, CFErrorRef
*error
);
86 uint8_t* SOSAccountEncodeToDER(SOSAccountRef cir
, CFErrorRef
* error
, const uint8_t* der
, uint8_t* der_end
);
87 size_t SOSAccountGetDEREncodedSize_V3(SOSAccountRef cir
, CFErrorRef
*error
);
88 uint8_t* SOSAccountEncodeToDER_V3(SOSAccountRef cir
, CFErrorRef
* error
, const uint8_t* der
, uint8_t* der_end
);
89 CFDataRef
SOSAccountCopyEncodedData(SOSAccountRef circle
, CFAllocatorRef allocator
, CFErrorRef
*error
);
92 CFStringRef
SOSAccountGetDeviceID(SOSAccountRef account
, CFErrorRef
*error
);
93 bool SOSAccountSetMyDSID(SOSAccountRef account
, CFStringRef IDS
, CFErrorRef
* errror
);
97 // MARK: Local Peer finding
99 SOSPeerInfoRef
SOSAccountGetMyPeerInCircle(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
* error
);
100 SOSPeerInfoRef
SOSAccountGetMyPeerInCircleNamed(SOSAccountRef account
, CFStringRef circle
, CFErrorRef
* error
);
102 SOSFullPeerInfoRef
SOSAccountGetMyFullPeerInCircle(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
* error
);
103 SOSFullPeerInfoRef
SOSAccountGetMyFullPeerInCircleNamed(SOSAccountRef account
, CFStringRef name
, CFErrorRef
*error
);
106 // MARK: Credential management
109 SecKeyRef
SOSAccountGetPrivateCredential(SOSAccountRef account
, CFErrorRef
* error
);
110 void SOSAccountPurgePrivateCredential(SOSAccountRef account
);
112 bool SOSAccountTryUserCredentials(SOSAccountRef account
,
113 CFStringRef user_account
, CFDataRef user_password
,
116 bool SOSAccountAssertUserCredentials(SOSAccountRef account
,
117 CFStringRef user_account
, CFDataRef user_password
,
122 // MARK: Circle management
124 int SOSAccountCountCircles(SOSAccountRef a
);
126 void SOSAccountForEachCircle(SOSAccountRef account
, void (^process
)(SOSCircleRef circle
));
128 SOSCircleRef
SOSAccountFindCircle(SOSAccountRef a
, CFStringRef name
, CFErrorRef
*error
);
129 SOSCircleRef
SOSAccountEnsureCircle(SOSAccountRef a
, CFStringRef name
, CFErrorRef
*error
);
131 bool SOSAccountUpdateCircle(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
*error
);
132 void SOSTransportEachMessage(SOSAccountRef account
, CFDictionaryRef updates
, CFErrorRef
*error
);
135 SOSCCStatus
SOSAccountIsInCircles(SOSAccountRef account
, CFErrorRef
* error
);
136 bool SOSAccountJoinCircles(SOSAccountRef account
, CFErrorRef
* error
);
137 bool SOSAccountJoinCirclesAfterRestore(SOSAccountRef account
, CFErrorRef
* error
);
138 bool SOSAccountLeaveCircles(SOSAccountRef account
,CFErrorRef
* error
);
139 bool SOSAccountBail(SOSAccountRef account
, uint64_t limit_in_seconds
, CFErrorRef
* error
);
140 bool SOSAccountAcceptApplicants(SOSAccountRef account
, CFArrayRef applicants
, CFErrorRef
* error
);
141 bool SOSAccountRejectApplicants(SOSAccountRef account
, CFArrayRef applicants
, CFErrorRef
* error
);
143 bool SOSAccountResetToOffering(SOSAccountRef account
, CFErrorRef
* error
);
144 bool SOSAccountResetToEmpty(SOSAccountRef account
, CFErrorRef
* error
);
145 bool SOSValidateUserPublic(SOSAccountRef account
, CFErrorRef
* error
);
147 CFArrayRef
SOSAccountCopyApplicants(SOSAccountRef account
, CFErrorRef
*error
);
148 CFArrayRef
SOSAccountCopyGeneration(SOSAccountRef account
, CFErrorRef
*error
);
149 CFArrayRef
SOSAccountCopyValidPeers(SOSAccountRef account
, CFErrorRef
*error
);
150 CFArrayRef
SOSAccountCopyNotValidPeers(SOSAccountRef account
, CFErrorRef
*error
);
151 CFArrayRef
SOSAccountCopyRetired(SOSAccountRef account
, CFErrorRef
*error
);
152 CFArrayRef
SOSAccountCopyPeers(SOSAccountRef account
, CFErrorRef
*error
);
153 CFArrayRef
SOSAccountCopyActivePeers(SOSAccountRef account
, CFErrorRef
*error
);
154 CFArrayRef
SOSAccountCopyActiveValidPeers(SOSAccountRef account
, CFErrorRef
*error
);
155 CFArrayRef
SOSAccountCopyConcurringPeers(SOSAccountRef account
, CFErrorRef
*error
);
157 CFArrayRef
SOSAccountCopyAccountIdentityPeerInfos(SOSAccountRef account
, CFAllocatorRef allocator
, CFErrorRef
* error
);
158 bool SOSAccountIsAccountIdentity(SOSAccountRef account
, SOSPeerInfoRef peer_info
, CFErrorRef
*error
);
160 enum DepartureReason
SOSAccountGetLastDepartureReason(SOSAccountRef account
, CFErrorRef
* error
);
163 // MARK: Change blocks
165 void SOSAccountAddChangeBlock(SOSAccountRef a
, SOSAccountCircleMembershipChangeBlock changeBlock
);
166 void SOSAccountRemoveChangeBlock(SOSAccountRef a
, SOSAccountCircleMembershipChangeBlock changeBlock
);
168 void SOSAccountAddSyncablePeerBlock(SOSAccountRef a
,
170 SOSAccountSyncablePeersBlock changeBlock
);
173 // MARK: Local device gestalt change.
175 bool SOSAccountUpdateGestalt(SOSAccountRef account
, CFDictionaryRef new_gestalt
);
177 bool SOSAccountHandleParametersChange(SOSAccountRef account
, CFDataRef updates
, CFErrorRef
*error
);
179 bool SOSAccountSyncWithPeer(SOSAccountRef account
, SOSCircleRef circle
, SOSPeerInfoRef thisPeer
, bool* didSendData
, CFErrorRef
* error
);
180 bool SOSAccountSyncWithAllPeers(SOSAccountRef account
, CFErrorRef
*error
);
182 bool SOSAccountCleanupAfterPeer(SOSAccountRef account
, size_t seconds
, SOSCircleRef circle
,
183 SOSPeerInfoRef cleanupPeer
, CFErrorRef
* error
);
185 bool SOSAccountCleanupRetirementTickets(SOSAccountRef account
, size_t seconds
, CFErrorRef
* error
);
187 bool SOSAccountScanForRetired(SOSAccountRef account
, SOSCircleRef circle
, CFErrorRef
*error
);
189 SOSCircleRef
SOSAccountCloneCircleWithRetirement(SOSAccountRef account
, SOSCircleRef starting_circle
, CFErrorRef
*error
);
192 // MARK: Version incompatibility Functions
194 CFStringRef
SOSAccountCopyIncompatibilityInfo(SOSAccountRef account
, CFErrorRef
* error
);
197 // MARK: Private functions
201 dispatch_queue_t
SOSAccountGetQueue(SOSAccountRef account
);
203 typedef bool (^SOSAccountSendBlock
)(CFStringRef key
, CFDataRef message
, CFErrorRef
*error
);
206 // MARK: Utility functions
209 CFStringRef
SOSInterestListCopyDescription(CFArrayRef interests
);
214 #endif /* !_SOSACCOUNT_H_ */