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
39 bool SOSCCTryUserCredentials_Server(CFStringRef user_label
, CFDataRef user_password
, CFStringRef dsid
, CFErrorRef
*error
);
40 bool SOSCCSetUserCredentials_Server(CFStringRef user_label
, CFDataRef user_password
, CFErrorRef
*error
);
41 bool SOSCCSetUserCredentialsAndDSID_Server(CFStringRef user_label
, CFDataRef user_password
, CFStringRef dsid
, 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 SOSCCRequestToJoinCircleAfterRestore_Server(CFErrorRef
* error
);
50 bool SOSCCRemoveThisDeviceFromCircle_Server(CFErrorRef
* error
);
51 bool SOSCCRemovePeersFromCircle_Server(CFArrayRef peers
, CFErrorRef
* error
);
53 // This will async off the notification, so it does not return a value.
54 void SOSCCNotifyLoggedIntoAccount_Server(void);
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
);
79 CFBooleanRef
SOSCCPeersHaveViewsEnabled_Server(CFArrayRef viewNames
, CFErrorRef
*error
);
81 SOSViewResultCode
SOSCCView_Server(CFStringRef view
, SOSViewActionCode action
, CFErrorRef
*error
);
82 bool SOSCCViewSet_Server(CFSetRef enabledViews
, CFSetRef disabledViews
);
84 enum DepartureReason
SOSCCGetLastDepartureReason_Server(CFErrorRef
* error
);
85 bool SOSCCSetLastDepartureReason_Server(enum DepartureReason reason
, CFErrorRef
*error
);
87 bool SOSCCProcessEnsurePeerRegistration_Server(CFErrorRef
* error
);
89 CF_RETURNS_RETAINED CFSetRef
SOSCCProcessSyncWithPeers_Server(CFSetRef peers
, CFSetRef backupPeers
, CFErrorRef
*error
);
90 SyncWithAllPeersReason
SOSCCProcessSyncWithAllPeers_Server(CFErrorRef
* error
);
92 SOSPeerInfoRef
SOSCCSetNewPublicBackupKey_Server(CFDataRef newPublicBackup
, CFErrorRef
*error
);
93 bool SOSCCRegisterSingleRecoverySecret_Server(CFDataRef backupSlice
, bool setupV0Only
, CFErrorRef
*error
);
95 bool SOSCCWaitForInitialSync_Server(CFErrorRef
*);
98 // MARK: Internal kicks.
100 CF_RETURNS_RETAINED CFArrayRef
SOSCCHandleUpdateMessage(CFDictionaryRef updates
);
103 // Expected to be called when the data source changes.
104 void SOSCCRequestSyncWithPeer(CFStringRef peerID
);
105 void SOSCCRequestSyncWithPeers(CFSetRef
/*SOSPeerInfoRef/CFStringRef*/ peerIDs
);
106 void SOSCCRequestSyncWithPeersList(CFArrayRef
/*CFStringRef*/ peerIDs
);
107 void SOSCCRequestSyncWithBackupPeerList(CFArrayRef
/* CFStringRef */ backupPeerIDs
);
108 bool SOSCCIsSyncPendingFor(CFStringRef peerID
, CFErrorRef
*error
);
110 void SOSCCAccountTriggerSyncWithBackupPeer_server(CFStringRef peer
);
112 void SOSCCEnsurePeerRegistration(void);
113 typedef void (^SOSAccountSyncablePeersBlock
)(CFArrayRef trustedPeers
, CFArrayRef addedPeers
, CFArrayRef removedPeers
);
115 dispatch_queue_t
SOSCCGetAccountQueue(void);
117 CFTypeRef
GetSharedAccountRef(void); // returns SOSAccount* but this header is imported by C files, so we cast through CFTypeRef
120 // MARK: Internal access to local account for tests.
122 CFTypeRef
SOSKeychainAccountGetSharedAccount(void);
124 // MARK: Internal SPIs for testing
127 void SOSCCSetGestalt_Server(CFStringRef name
, CFStringRef version
, CFStringRef model
, CFStringRef serial
);
128 CFStringRef
SOSCCCopyOSVersion(void);
131 // MARK: Testing operations, dangerous to call in normal operation.
133 bool SOSKeychainSaveAccountDataAndPurge(CFErrorRef
*error
);
136 // MARK: Constants for where we store persistent information in the keychain
139 extern CFStringRef kSOSAccountLabel
;
140 extern CFStringRef kSOSPeerDataLabel
;
142 CFDataRef
SOSItemCopy(CFStringRef label
, CFErrorRef
* error
);
143 bool SOSItemUpdateOrAdd(CFStringRef label
, CFStringRef accessibility
, CFDataRef data
, CFErrorRef
*error
);
145 bool SOSCCRegisterRecoveryPublicKey_Server(CFDataRef recovery_key
, CFErrorRef
*error
);
146 CFDataRef
SOSCCCopyRecoveryPublicKey_Server(CFErrorRef
*error
);
148 SOSPeerInfoRef
SOSCCCopyApplication_Server(CFErrorRef
*error
);
149 CFDataRef
SOSCCCopyCircleJoiningBlob_Server(SOSPeerInfoRef applicant
, CFErrorRef
*error
);
150 bool SOSCCJoinWithCircleJoiningBlob_Server(CFDataRef joiningBlob
, PiggyBackProtocolVersion version
, CFErrorRef
*error
);
151 CFDataRef
SOSCCCopyInitialSyncData_Server(uint32_t flags
, CFErrorRef
*error
);
152 bool SOSCCCleanupKVSKeys_Server(CFErrorRef
*error
);
154 bool SOSCCAccountHasPublicKey_Server(CFErrorRef
*error
);
156 void sync_the_last_data_to_kvs(CFTypeRef account
, bool waitForeverForSynchronization
);
158 bool SOSCCMessageFromPeerIsPending_Server(SOSPeerInfoRef peer
, CFErrorRef
*error
);
159 bool SOSCCSendToPeerIsPending_Server(SOSPeerInfoRef peer
, CFErrorRef
*error
);
161 void SOSCCPerformWithOctagonSigningKey(void (^action
)(SecKeyRef octagonPrivKey
, CFErrorRef error
));
162 void SOSCCPerformWithOctagonSigningPublicKey(void (^action
)(SecKeyRef octagonPublicKey
, CFErrorRef error
));
163 void SOSCCPerformWithOctagonEncryptionKey(void (^action
)(SecKeyRef octagonPrivEncryptionKey
, CFErrorRef error
));
164 void SOSCCPerformWithOctagonEncryptionPublicKey(void (^action
)(SecKeyRef octagonPublicEncryptionKey
, CFErrorRef error
));
165 void SOSCCPerformWithAllOctagonKeys(void (^action
)(SecKeyRef octagonEncryptionKey
, SecKeyRef octagonSigningKey
, CFErrorRef error
));
166 void SOSCCPerformWithTrustedPeers(void (^action
)(CFSetRef sosPeerInfoRefs
, CFErrorRef error
));
167 void SOSCCPerformWithPeerID(void (^action
)(CFStringRef peerID
, CFErrorRef error
));
168 void SOSCCPerformUpdateOfAllOctagonKeys(CFDataRef octagonSigningFullKey
, CFDataRef octagonEncryptionFullKey
,
169 CFDataRef signingPublicKey
, CFDataRef encryptionPublicKey
,
170 SecKeyRef octagonSigningPublicKeyRef
, SecKeyRef octagonEncryptionPublicKeyRef
,
171 void (^action
)(CFErrorRef error
));
172 void SOSCCPerformPreloadOfAllOctagonKeys(CFDataRef octagonSigningFullKey
, CFDataRef octagonEncryptionFullKey
,
173 SecKeyRef octagonSigningFullKeyRef
, SecKeyRef octagonEncryptionFullKeyRef
,
174 SecKeyRef octagonSigningPublicKeyRef
, SecKeyRef octagonEncryptionPublicKeyRef
,
175 void (^action
)(CFErrorRef error
));
177 bool SOSCCSetCKKS4AllStatus(bool status
, CFErrorRef
* error
);
179 void SOSCCResetOTRNegotiation_Server(CFStringRef peerid
);
180 void SOSCCPeerRateLimiterSendNextMessage_Server(CFStringRef peerid
, CFStringRef accessGroup
);
183 bool SOSCCSaveOctagonKeysToKeychain(NSString
* keyLabel
, NSData
* keyDataToSave
, __unused
int keySize
, SecKeyRef octagonPublicKey
, NSError
** error
);
184 void SOSCCEnsureAccessGroupOfKey(SecKeyRef publicKey
, NSString
* oldAgrp
, NSString
* newAgrp
);