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 #include "keychain/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
);
59 CFArrayRef
SOSCCCopyGenerationPeerInfo_Server(CFErrorRef
* error
);
60 CFArrayRef
SOSCCCopyApplicantPeerInfo_Server(CFErrorRef
* error
);
61 CFArrayRef
SOSCCCopyValidPeerPeerInfo_Server(CFErrorRef
* error
);
62 bool SOSCCValidateUserPublic_Server(CFErrorRef
* error
);
64 CFArrayRef
SOSCCCopyNotValidPeerPeerInfo_Server(CFErrorRef
* error
);
65 CFArrayRef
SOSCCCopyRetirementPeerInfo_Server(CFErrorRef
* error
);
66 CFArrayRef
SOSCCCopyViewUnawarePeerInfo_Server(CFErrorRef
* error
);
67 bool SOSCCRejectApplicants_Server(CFArrayRef applicants
, CFErrorRef
* error
);
68 bool SOSCCAcceptApplicants_Server(CFArrayRef applicants
, CFErrorRef
* error
);
70 SOSPeerInfoRef
SOSCCCopyMyPeerInfo_Server(CFErrorRef
* error
);
71 CFArrayRef
SOSCCCopyEngineState_Server(CFErrorRef
* error
);
73 CFArrayRef
SOSCCCopyPeerPeerInfo_Server(CFErrorRef
* error
);
74 CFArrayRef
SOSCCCopyConcurringPeerPeerInfo_Server(CFErrorRef
* error
);
75 bool SOSCCAccountSetToNew_Server(CFErrorRef
*error
);
76 bool SOSCCResetToOffering_Server(CFErrorRef
* error
);
77 bool SOSCCResetToEmpty_Server(CFErrorRef
* error
);
78 bool SOSCCResetToEmptyWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
80 CFBooleanRef
SOSCCPeersHaveViewsEnabled_Server(CFArrayRef viewNames
, CFErrorRef
*error
);
82 SOSViewResultCode
SOSCCView_Server(CFStringRef view
, SOSViewActionCode action
, CFErrorRef
*error
);
83 bool SOSCCViewSetWithAnalytics_Server(CFSetRef enabledViews
, CFSetRef disabledViews
, CFDataRef parentEvent
);
84 bool SOSCCViewSet_Server(CFSetRef enabledViews
, CFSetRef disabledViews
);
86 enum DepartureReason
SOSCCGetLastDepartureReason_Server(CFErrorRef
* error
);
87 bool SOSCCSetLastDepartureReason_Server(enum DepartureReason reason
, CFErrorRef
*error
);
89 bool SOSCCProcessEnsurePeerRegistration_Server(CFErrorRef
* error
);
91 CF_RETURNS_RETAINED CFSetRef
SOSCCProcessSyncWithPeers_Server(CFSetRef peers
, CFSetRef backupPeers
, CFErrorRef
*error
);
92 SyncWithAllPeersReason
SOSCCProcessSyncWithAllPeers_Server(CFErrorRef
* error
);
94 SOSPeerInfoRef
SOSCCSetNewPublicBackupKey_Server(CFDataRef newPublicBackup
, CFErrorRef
*error
);
95 bool SOSCCRegisterSingleRecoverySecret_Server(CFDataRef backupSlice
, bool setupV0Only
, CFErrorRef
*error
);
97 bool SOSCCWaitForInitialSync_Server(CFErrorRef
*);
98 bool SOSCCWaitForInitialSyncWithAnalytics_Server(CFDataRef parentEvent
, CFErrorRef
* error
);
101 // MARK: Internal kicks.
103 CF_RETURNS_RETAINED CFArrayRef
SOSCCHandleUpdateMessage(CFDictionaryRef updates
);
106 // Expected to be called when the data source changes.
107 void SOSCCRequestSyncWithPeer(CFStringRef peerID
);
108 void SOSCCRequestSyncWithPeers(CFSetRef
/*SOSPeerInfoRef/CFStringRef*/ peerIDs
);
109 void SOSCCRequestSyncWithPeersList(CFArrayRef
/*CFStringRef*/ peerIDs
);
110 void SOSCCRequestSyncWithBackupPeerList(CFArrayRef
/* CFStringRef */ backupPeerIDs
);
111 bool SOSCCIsSyncPendingFor(CFStringRef peerID
, CFErrorRef
*error
);
113 void SOSCCAccountTriggerSyncWithBackupPeer_server(CFStringRef peer
);
115 void SOSCCEnsurePeerRegistration(void);
116 typedef void (^SOSAccountSyncablePeersBlock
)(CFArrayRef trustedPeers
, CFArrayRef addedPeers
, CFArrayRef removedPeers
);
118 dispatch_queue_t
SOSCCGetAccountQueue(void);
120 CFTypeRef
GetSharedAccountRef(void); // returns SOSAccount* but this header is imported by C files, so we cast through CFTypeRef
123 // MARK: Internal access to local account for tests.
125 CFTypeRef
SOSKeychainAccountGetSharedAccount(void);
127 // MARK: Internal SPIs for testing
130 void SOSCCSetGestalt_Server(CFStringRef name
, CFStringRef version
, CFStringRef model
, CFStringRef serial
);
131 CFStringRef
SOSCCCopyOSVersion(void);
134 // MARK: Testing operations, dangerous to call in normal operation.
136 bool SOSKeychainSaveAccountDataAndPurge(CFErrorRef
*error
);
139 // MARK: Constants for where we store persistent information in the keychain
142 extern CFStringRef kSOSAccountLabel
;
143 extern CFStringRef kSOSPeerDataLabel
;
145 CFDataRef
SOSItemCopy(CFStringRef label
, CFErrorRef
* error
);
146 bool SOSItemUpdateOrAdd(CFStringRef label
, CFStringRef accessibility
, CFDataRef data
, CFErrorRef
*error
);
148 bool SOSCCRegisterRecoveryPublicKey_Server(CFDataRef recovery_key
, CFErrorRef
*error
);
149 CFDataRef
SOSCCCopyRecoveryPublicKey_Server(CFErrorRef
*error
);
151 SOSPeerInfoRef
SOSCCCopyApplication_Server(CFErrorRef
*error
);
152 CFDataRef
SOSCCCopyCircleJoiningBlob_Server(SOSPeerInfoRef applicant
, CFErrorRef
*error
);
153 bool SOSCCJoinWithCircleJoiningBlob_Server(CFDataRef joiningBlob
, PiggyBackProtocolVersion version
, CFErrorRef
*error
);
154 CFDataRef
SOSCCCopyInitialSyncData_Server(uint32_t flags
, CFErrorRef
*error
);
155 bool SOSCCCleanupKVSKeys_Server(CFErrorRef
*error
);
157 bool SOSCCAccountHasPublicKey_Server(CFErrorRef
*error
);
159 void sync_the_last_data_to_kvs(CFTypeRef account
, bool waitForeverForSynchronization
);
161 bool SOSCCMessageFromPeerIsPending_Server(SOSPeerInfoRef peer
, CFErrorRef
*error
);
162 bool SOSCCSendToPeerIsPending_Server(SOSPeerInfoRef peer
, CFErrorRef
*error
);
164 void SOSCCPerformWithOctagonSigningKey(void (^action
)(SecKeyRef octagonPrivKey
, CFErrorRef error
));
165 void SOSCCPerformWithOctagonSigningPublicKey(void (^action
)(SecKeyRef octagonPublicKey
, CFErrorRef error
));
166 void SOSCCPerformWithOctagonEncryptionKey(void (^action
)(SecKeyRef octagonPrivEncryptionKey
, CFErrorRef error
));
167 void SOSCCPerformWithOctagonEncryptionPublicKey(void (^action
)(SecKeyRef octagonPublicEncryptionKey
, CFErrorRef error
));
168 void SOSCCPerformWithAllOctagonKeys(void (^action
)(SecKeyRef octagonEncryptionKey
, SecKeyRef octagonSigningKey
, CFErrorRef error
));
169 void SOSCCPerformWithTrustedPeers(void (^action
)(CFSetRef sosPeerInfoRefs
, CFErrorRef error
));
170 void SOSCCPerformWithPeerID(void (^action
)(CFStringRef peerID
, CFErrorRef error
));
171 void SOSCCPerformUpdateOfAllOctagonKeys(CFDataRef octagonSigningFullKey
, CFDataRef octagonEncryptionFullKey
,
172 CFDataRef signingPublicKey
, CFDataRef encryptionPublicKey
,
173 SecKeyRef octagonSigningPublicKeyRef
, SecKeyRef octagonEncryptionPublicKeyRef
,
174 void (^action
)(CFErrorRef error
));
176 void SOSCCResetOTRNegotiation_Server(CFStringRef peerid
);
177 void SOSCCPeerRateLimiterSendNextMessage_Server(CFStringRef peerid
, CFStringRef accessGroup
);