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@
25 #ifndef _SECURITY_SOSCLOUDCIRCLESERVER_H_
26 #define _SECURITY_SOSCLOUDCIRCLESERVER_H_
28 #import <Security/SecureObjectSync/SOSCloudCircle.h>
29 #import <Security/SecureObjectSync/SOSRing.h>
30 #import <Security/SecKey.h>
36 // MARK: Server versions of our SPI
38 bool SOSCCTryUserCredentials_Server(CFStringRef user_label
, CFDataRef user_password
, CFStringRef dsid
, CFErrorRef
*error
);
39 bool SOSCCSetUserCredentials_Server(CFStringRef user_label
, CFDataRef user_password
, CFErrorRef
*error
);
40 bool SOSCCSetUserCredentialsAndDSID_Server(CFStringRef user_label
, CFDataRef user_password
, CFStringRef dsid
, CFErrorRef
*error
);
41 bool SOSCCSetUserCredentialsAndDSIDWithAnalytics_Server(CFStringRef user_label
, CFDataRef user_password
, CFStringRef dsid
, CFDataRef parentEvent
, CFErrorRef
*error
);
43 bool SOSCCCanAuthenticate_Server(CFErrorRef
*error
);
44 bool SOSCCPurgeUserCredentials_Server(CFErrorRef
*error
);
46 SOSCCStatus
SOSCCThisDeviceIsInCircle_Server(CFErrorRef
*error
);
47 bool SOSCCRequestToJoinCircle_Server(CFErrorRef
* error
);
48 bool SOSCCRequestToJoinCircleWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
49 bool SOSCCRequestToJoinCircleAfterRestore_Server(CFErrorRef
* error
);
50 bool SOSCCRequestToJoinCircleAfterRestoreWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
52 bool SOSCCRemoveThisDeviceFromCircle_Server(CFErrorRef
* error
);
53 bool SOSCCRemoveThisDeviceFromCircleWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
54 bool SOSCCRemovePeersFromCircle_Server(CFArrayRef peers
, CFErrorRef
* error
);
55 bool SOSCCRemovePeersFromCircleWithAnalytics_Server(CFArrayRef peers
, CFDataRef parentEvent
, CFErrorRef
* error
);
56 bool SOSCCLoggedOutOfAccount_Server(CFErrorRef
*error
);
57 bool SOSCCBailFromCircle_Server(uint64_t limit_in_seconds
, CFErrorRef
* error
);
58 bool SOSCCRequestEnsureFreshParameters_Server(CFErrorRef
* error
);
61 bool SOSCCApplyToARing_Server(CFStringRef ringName
, CFErrorRef
*error
);
62 bool SOSCCWithdrawlFromARing_Server(CFStringRef ringName
, CFErrorRef
*error
);
63 SOSRingStatus
SOSCCRingStatus_Server(CFStringRef ringName
, CFErrorRef
*error
);
64 CFStringRef
SOSCCGetAllTheRings_Server(CFErrorRef
*error
);
65 bool SOSCCEnableRing_Server(CFStringRef ringName
, CFErrorRef
*error
);
68 CFArrayRef
SOSCCCopyGenerationPeerInfo_Server(CFErrorRef
* error
);
69 CFArrayRef
SOSCCCopyApplicantPeerInfo_Server(CFErrorRef
* error
);
70 CFArrayRef
SOSCCCopyValidPeerPeerInfo_Server(CFErrorRef
* error
);
71 bool SOSCCValidateUserPublic_Server(CFErrorRef
* error
);
73 CFArrayRef
SOSCCCopyNotValidPeerPeerInfo_Server(CFErrorRef
* error
);
74 CFArrayRef
SOSCCCopyRetirementPeerInfo_Server(CFErrorRef
* error
);
75 CFArrayRef
SOSCCCopyViewUnawarePeerInfo_Server(CFErrorRef
* error
);
76 bool SOSCCRejectApplicants_Server(CFArrayRef applicants
, CFErrorRef
* error
);
77 bool SOSCCAcceptApplicants_Server(CFArrayRef applicants
, CFErrorRef
* error
);
79 SOSPeerInfoRef
SOSCCCopyMyPeerInfo_Server(CFErrorRef
* error
);
80 CFArrayRef
SOSCCCopyEngineState_Server(CFErrorRef
* error
);
82 CFArrayRef
SOSCCCopyPeerPeerInfo_Server(CFErrorRef
* error
);
83 CFArrayRef
SOSCCCopyConcurringPeerPeerInfo_Server(CFErrorRef
* error
);
84 bool SOSCCkSecXPCOpIsThisDeviceLastBackup_Server(CFErrorRef
*error
);
85 bool SOSCCkSecXPCOpIsThisDeviceLastBackup_Server(CFErrorRef
*error
);
86 bool SOSCCAccountSetToNew_Server(CFErrorRef
*error
);
87 bool SOSCCResetToOffering_Server(CFErrorRef
* error
);
88 bool SOSCCResetToEmpty_Server(CFErrorRef
* error
);
89 bool SOSCCResetToEmptyWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
91 CFBooleanRef
SOSCCPeersHaveViewsEnabled_Server(CFArrayRef viewNames
, CFErrorRef
*error
);
93 SOSViewResultCode
SOSCCView_Server(CFStringRef view
, SOSViewActionCode action
, CFErrorRef
*error
);
94 bool SOSCCViewSetWithAnalytics_Server(CFSetRef enabledViews
, CFSetRef disabledViews
, CFDataRef parentEvent
);
95 bool SOSCCViewSet_Server(CFSetRef enabledView
, CFSetRef disabledViews
);
97 CFStringRef
SOSCCCopyIncompatibilityInfo_Server(CFErrorRef
* error
);
98 enum DepartureReason
SOSCCGetLastDepartureReason_Server(CFErrorRef
* error
);
99 bool SOSCCSetLastDepartureReason_Server(enum DepartureReason reason
, CFErrorRef
*error
);
101 bool SOSCCProcessEnsurePeerRegistration_Server(CFErrorRef
* error
);
103 CF_RETURNS_RETAINED CFSetRef
SOSCCProcessSyncWithPeers_Server(CFSetRef peers
, CFSetRef backupPeers
, CFErrorRef
*error
);
104 SyncWithAllPeersReason
SOSCCProcessSyncWithAllPeers_Server(CFErrorRef
* error
);
106 SOSPeerInfoRef
SOSCCSetNewPublicBackupKey_Server(CFDataRef newPublicBackup
, CFErrorRef
*error
);
107 bool SOSCCRegisterSingleRecoverySecret_Server(CFDataRef backupSlice
, bool setupV0Only
, CFErrorRef
*error
);
109 bool SOSCCWaitForInitialSync_Server(CFErrorRef
*);
110 bool SOSCCWaitForInitialSyncWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
111 CFArrayRef
SOSCCCopyYetToSyncViewsList_Server(CFErrorRef
*);
113 bool SOSWrapToBackupSliceKeyBagForView_Server(CFStringRef viewName
, CFDataRef input
, CFDataRef
* output
, CFDataRef
* bskbEncoded
, CFErrorRef
* error
);
115 SOSBackupSliceKeyBagRef
SOSBackupSliceKeyBagForView(CFStringRef viewName
, CFErrorRef
* error
);
116 CF_RETURNS_RETAINED CFDataRef
SOSWrapToBackupSliceKeyBag(SOSBackupSliceKeyBagRef bskb
, CFDataRef input
, CFErrorRef
* error
);
119 // MARK: Internal kicks.
121 CF_RETURNS_RETAINED CFArrayRef
SOSCCHandleUpdateMessage(CFDictionaryRef updates
);
124 // Expected to be called when the data source changes.
125 void SOSCCRequestSyncWithPeer(CFStringRef peerID
);
126 void SOSCCRequestSyncWithPeers(CFSetRef
/*SOSPeerInfoRef/CFStringRef*/ peerIDs
);
127 void SOSCCRequestSyncWithPeersList(CFArrayRef
/*CFStringRef*/ peerIDs
);
128 void SOSCCRequestSyncWithBackupPeer(CFStringRef backupPeerId
);
129 bool SOSCCIsSyncPendingFor(CFStringRef peerID
, CFErrorRef
*error
);
131 void SOSCCEnsurePeerRegistration(void);
132 typedef void (^SOSAccountSyncablePeersBlock
)(CFArrayRef trustedPeers
, CFArrayRef addedPeers
, CFArrayRef removedPeers
);
134 dispatch_queue_t
SOSCCGetAccountQueue(void);
136 CFTypeRef
GetSharedAccountRef(void); // returns SOSAccount* but this header is imported by C files, so we cast through CFTypeRef
139 // MARK: Internal access to local account for tests.
141 CFTypeRef
SOSKeychainAccountGetSharedAccount(void);
143 // MARK: Internal SPIs for testing
146 void SOSCCSetGestalt_Server(CFStringRef name
, CFStringRef version
, CFStringRef model
, CFStringRef serial
);
147 CFStringRef
SOSCCCopyOSVersion(void);
148 CFDataRef
SOSCCCopyAccountState_Server(CFErrorRef
* error
);
149 CFDataRef
SOSCCCopyEngineData_Server(CFErrorRef
* error
);
150 bool SOSCCDeleteEngineState_Server(CFErrorRef
* error
);
151 bool SOSCCDeleteAccountState_Server(CFErrorRef
* error
);
155 // MARK: Testing operations, dangerous to call in normal operation.
157 bool SOSKeychainSaveAccountDataAndPurge(CFErrorRef
*error
);
160 // MARK: Constants for where we store persistent information in the keychain
163 extern CFStringRef kSOSAccountLabel
;
164 extern CFStringRef kSOSPeerDataLabel
;
166 CFDataRef
SOSItemCopy(CFStringRef label
, CFErrorRef
* error
);
167 bool SOSItemUpdateOrAdd(CFStringRef label
, CFStringRef accessibility
, CFDataRef data
, CFErrorRef
*error
);
169 bool SOSCCSetEscrowRecord_Server(CFStringRef escrow_label
, uint64_t tries
, CFErrorRef
*error
);
170 CFDictionaryRef
SOSCCCopyEscrowRecord_Server(CFErrorRef
*error
);
171 bool SOSCCRegisterRecoveryPublicKey_Server(CFDataRef recovery_key
, CFErrorRef
*error
);
172 CFDataRef
SOSCCCopyRecoveryPublicKey_Server(CFErrorRef
*error
);
174 CFDictionaryRef
SOSCCCopyBackupInformation_Server(CFErrorRef
*error
);
176 SOSPeerInfoRef
SOSCCCopyApplication_Server(CFErrorRef
*error
);
177 CFDataRef
SOSCCCopyCircleJoiningBlob_Server(SOSPeerInfoRef applicant
, CFErrorRef
*error
);
178 bool SOSCCJoinWithCircleJoiningBlob_Server(CFDataRef joiningBlob
, PiggyBackProtocolVersion version
, CFErrorRef
*error
);
179 CFDataRef
SOSCCCopyInitialSyncData_Server(CFErrorRef
*error
);
180 bool SOSCCCleanupKVSKeys_Server(CFErrorRef
*error
);
182 bool SOSCCAccountHasPublicKey_Server(CFErrorRef
*error
);
183 bool SOSCCAccountIsNew_Server(CFErrorRef
*error
);
184 bool SOSCCTestPopulateKVSWithBadKeys_Server(CFErrorRef
*error
);
186 void sync_the_last_data_to_kvs(CFTypeRef account
, bool waitForeverForSynchronization
);
188 bool SOSCCMessageFromPeerIsPending_Server(SOSPeerInfoRef peer
, CFErrorRef
*error
);
189 bool SOSCCSendToPeerIsPending_Server(SOSPeerInfoRef peer
, CFErrorRef
*error
);
191 void SOSCCPerformWithOctagonSigningKey(void (^action
)(SecKeyRef octagonPrivKey
, CFErrorRef error
));
192 void SOSCCPerformWithOctagonSigningPublicKey(void (^action
)(SecKeyRef octagonPublicKey
, CFErrorRef error
));
193 void SOSCCPerformWithOctagonEncryptionKey(void (^action
)(SecKeyRef octagonPrivEncryptionKey
, CFErrorRef error
));
194 void SOSCCPerformWithOctagonEncryptionPublicKey(void (^action
)(SecKeyRef octagonPublicEncryptionKey
, CFErrorRef error
));
195 void SOSCCPerformWithAllOctagonKeys(void (^action
)(SecKeyRef octagonEncryptionKey
, SecKeyRef octagonSigningKey
, CFErrorRef error
));
196 void SOSCCPerformWithTrustedPeers(void (^action
)(CFSetRef sosPeerInfoRefs
, CFErrorRef error
));
197 void SOSCCPerformWithPeerID(void (^action
)(CFStringRef peerID
, CFErrorRef error
));
199 void SOSCCResetOTRNegotiation_Server(CFStringRef peerid
);
200 void SOSCCPeerRateLimiterSendNextMessage_Server(CFStringRef peerid
, CFStringRef accessGroup
);