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. */ 35typedef struct __OpaqueSOSAccount *SOSAccountRef; 36 37 38#include <CoreFoundation/CoreFoundation.h> 39 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> 47 48#include <dispatch/dispatch.h> 49 50__BEGIN_DECLS 51 52#define RETIREMENT_FINALIZATION_SECONDS (24*60*60) 53 54 55typedef void (^SOSAccountCircleMembershipChangeBlock)(SOSCircleRef new_circle, 56 CFSetRef added_peers, CFSetRef removed_peers, 57 CFSetRef added_applicants, CFSetRef removed_applicants); 58typedef void (^SOSAccountSyncablePeersBlock)(CFArrayRef trustedPeers, CFArrayRef addedPeers, CFArrayRef removedPeers); 59 60SOSAccountRef SOSAccountGetShared(void); 61SOSAccountRef SOSAccountCreate(CFAllocatorRef allocator, 62 CFDictionaryRef gestalt, 63 SOSDataSourceFactoryRef factory); 64SOSAccountRef SOSAccountCreateBasic(CFAllocatorRef allocator, 65 CFDictionaryRef gestalt, 66 SOSDataSourceFactoryRef factory); 67 68// 69// MARK: Persistent Encode decode 70// 71 72SOSAccountRef SOSAccountCreateFromDER(CFAllocatorRef allocator, SOSDataSourceFactoryRef factory, 73 CFErrorRef* error, 74 const uint8_t** der_p, const uint8_t *der_end); 75 76SOSAccountRef SOSAccountCreateFromDER_V3(CFAllocatorRef allocator, 77 SOSDataSourceFactoryRef factory, 78 CFErrorRef* error, 79 const uint8_t** der_p, const uint8_t *der_end); 80 81SOSAccountRef SOSAccountCreateFromData(CFAllocatorRef allocator, CFDataRef circleData, 82 SOSDataSourceFactoryRef factory, 83 CFErrorRef* error); 84 85size_t SOSAccountGetDEREncodedSize(SOSAccountRef cir, CFErrorRef *error); 86uint8_t* SOSAccountEncodeToDER(SOSAccountRef cir, CFErrorRef* error, const uint8_t* der, uint8_t* der_end); 87size_t SOSAccountGetDEREncodedSize_V3(SOSAccountRef cir, CFErrorRef *error); 88uint8_t* SOSAccountEncodeToDER_V3(SOSAccountRef cir, CFErrorRef* error, const uint8_t* der, uint8_t* der_end); 89CFDataRef SOSAccountCopyEncodedData(SOSAccountRef circle, CFAllocatorRef allocator, CFErrorRef *error); 90// 91//MARK: IDS Device ID 92CFStringRef SOSAccountGetDeviceID(SOSAccountRef account, CFErrorRef *error); 93bool SOSAccountSetMyDSID(SOSAccountRef account, CFStringRef IDS, CFErrorRef* errror); 94 95// 96// 97// MARK: Local Peer finding 98// 99SOSPeerInfoRef SOSAccountGetMyPeerInCircle(SOSAccountRef account, SOSCircleRef circle, CFErrorRef* error); 100SOSPeerInfoRef SOSAccountGetMyPeerInCircleNamed(SOSAccountRef account, CFStringRef circle, CFErrorRef* error); 101 102SOSFullPeerInfoRef SOSAccountGetMyFullPeerInCircle(SOSAccountRef account, SOSCircleRef circle, CFErrorRef* error); 103SOSFullPeerInfoRef SOSAccountGetMyFullPeerInCircleNamed(SOSAccountRef account, CFStringRef name, CFErrorRef *error); 104 105// 106// MARK: Credential management 107// 108 109SecKeyRef SOSAccountGetPrivateCredential(SOSAccountRef account, CFErrorRef* error); 110void SOSAccountPurgePrivateCredential(SOSAccountRef account); 111 112bool SOSAccountTryUserCredentials(SOSAccountRef account, 113 CFStringRef user_account, CFDataRef user_password, 114 CFErrorRef *error); 115 116bool SOSAccountAssertUserCredentials(SOSAccountRef account, 117 CFStringRef user_account, CFDataRef user_password, 118 CFErrorRef *error); 119 120 121// 122// MARK: Circle management 123// 124int SOSAccountCountCircles(SOSAccountRef a); 125 126void SOSAccountForEachCircle(SOSAccountRef account, void (^process)(SOSCircleRef circle)); 127 128SOSCircleRef SOSAccountFindCircle(SOSAccountRef a, CFStringRef name, CFErrorRef *error); 129SOSCircleRef SOSAccountEnsureCircle(SOSAccountRef a, CFStringRef name, CFErrorRef *error); 130 131bool SOSAccountUpdateCircle(SOSAccountRef account, SOSCircleRef circle, CFErrorRef *error); 132void SOSTransportEachMessage(SOSAccountRef account, CFDictionaryRef updates, CFErrorRef *error); 133 134 135SOSCCStatus SOSAccountIsInCircles(SOSAccountRef account, CFErrorRef* error); 136bool SOSAccountJoinCircles(SOSAccountRef account, CFErrorRef* error); 137bool SOSAccountJoinCirclesAfterRestore(SOSAccountRef account, CFErrorRef* error); 138bool SOSAccountLeaveCircles(SOSAccountRef account,CFErrorRef* error); 139bool SOSAccountBail(SOSAccountRef account, uint64_t limit_in_seconds, CFErrorRef* error); 140bool SOSAccountAcceptApplicants(SOSAccountRef account, CFArrayRef applicants, CFErrorRef* error); 141bool SOSAccountRejectApplicants(SOSAccountRef account, CFArrayRef applicants, CFErrorRef* error); 142 143bool SOSAccountResetToOffering(SOSAccountRef account, CFErrorRef* error); 144bool SOSAccountResetToEmpty(SOSAccountRef account, CFErrorRef* error); 145bool SOSValidateUserPublic(SOSAccountRef account, CFErrorRef* error); 146 147CFArrayRef SOSAccountCopyApplicants(SOSAccountRef account, CFErrorRef *error); 148CFArrayRef SOSAccountCopyGeneration(SOSAccountRef account, CFErrorRef *error); 149CFArrayRef SOSAccountCopyValidPeers(SOSAccountRef account, CFErrorRef *error); 150CFArrayRef SOSAccountCopyNotValidPeers(SOSAccountRef account, CFErrorRef *error); 151CFArrayRef SOSAccountCopyRetired(SOSAccountRef account, CFErrorRef *error); 152CFArrayRef SOSAccountCopyPeers(SOSAccountRef account, CFErrorRef *error); 153CFArrayRef SOSAccountCopyActivePeers(SOSAccountRef account, CFErrorRef *error); 154CFArrayRef SOSAccountCopyActiveValidPeers(SOSAccountRef account, CFErrorRef *error); 155CFArrayRef SOSAccountCopyConcurringPeers(SOSAccountRef account, CFErrorRef *error); 156 157CFArrayRef SOSAccountCopyAccountIdentityPeerInfos(SOSAccountRef account, CFAllocatorRef allocator, CFErrorRef* error); 158bool SOSAccountIsAccountIdentity(SOSAccountRef account, SOSPeerInfoRef peer_info, CFErrorRef *error); 159 160enum DepartureReason SOSAccountGetLastDepartureReason(SOSAccountRef account, CFErrorRef* error); 161 162// 163// MARK: Change blocks 164// 165void SOSAccountAddChangeBlock(SOSAccountRef a, SOSAccountCircleMembershipChangeBlock changeBlock); 166void SOSAccountRemoveChangeBlock(SOSAccountRef a, SOSAccountCircleMembershipChangeBlock changeBlock); 167 168void SOSAccountAddSyncablePeerBlock(SOSAccountRef a, 169 CFStringRef ds_name, 170 SOSAccountSyncablePeersBlock changeBlock); 171 172// 173// MARK: Local device gestalt change. 174// 175bool SOSAccountUpdateGestalt(SOSAccountRef account, CFDictionaryRef new_gestalt); 176 177bool SOSAccountHandleParametersChange(SOSAccountRef account, CFDataRef updates, CFErrorRef *error); 178 179bool SOSAccountSyncWithPeer(SOSAccountRef account, SOSCircleRef circle, SOSPeerInfoRef thisPeer, bool* didSendData, CFErrorRef* error); 180bool SOSAccountSyncWithAllPeers(SOSAccountRef account, CFErrorRef *error); 181 182bool SOSAccountCleanupAfterPeer(SOSAccountRef account, size_t seconds, SOSCircleRef circle, 183 SOSPeerInfoRef cleanupPeer, CFErrorRef* error); 184 185bool SOSAccountCleanupRetirementTickets(SOSAccountRef account, size_t seconds, CFErrorRef* error); 186 187bool SOSAccountScanForRetired(SOSAccountRef account, SOSCircleRef circle, CFErrorRef *error); 188 189SOSCircleRef SOSAccountCloneCircleWithRetirement(SOSAccountRef account, SOSCircleRef starting_circle, CFErrorRef *error); 190 191// 192// MARK: Version incompatibility Functions 193// 194CFStringRef SOSAccountCopyIncompatibilityInfo(SOSAccountRef account, CFErrorRef* error); 195 196// 197// MARK: Private functions 198// 199 200 201dispatch_queue_t SOSAccountGetQueue(SOSAccountRef account); 202 203typedef bool (^SOSAccountSendBlock)(CFStringRef key, CFDataRef message, CFErrorRef *error); 204 205// 206// MARK: Utility functions 207// 208 209CFStringRef SOSInterestListCopyDescription(CFArrayRef interests); 210 211 212__END_DECLS 213 214#endif /* !_SOSACCOUNT_H_ */ 215