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@
28 #import <Foundation/Foundation.h>
29 #import <Foundation/NSXPCConnection_Private.h>
32 #include <AssertMacros.h>
33 #include <Security/SecureObjectSync/SOSCloudCircle.h>
34 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
35 #include <Security/SecureObjectSync/SOSCircle.h>
36 #include <Security/SecureObjectSync/SOSAccount.h>
37 #include <Security/SecureObjectSync/SOSFullPeerInfo.h>
38 #include <Security/SecureObjectSync/SOSPeerInfoCollections.h>
39 #include <Security/SecureObjectSync/SOSInternal.h>
40 #include <Security/SecureObjectSync/SOSRing.h>
41 #include <Security/SecureObjectSync/SOSBackupSliceKeyBag.h>
42 #include <Security/SecureObjectSync/SOSViews.h>
43 #include <Security/SecureObjectSync/SOSControlHelper.h>
45 #include <Security/SecKeyPriv.h>
46 #include <Security/SecFramework.h>
47 #include <CoreFoundation/CFXPCBridge.h>
49 #include <securityd/SecItemServer.h>
51 #include <utilities/SecDispatchRelease.h>
52 #include <utilities/SecCFRelease.h>
53 #include <utilities/SecCFWrappers.h>
54 #include <utilities/SecXPCError.h>
56 #include <corecrypto/ccsha2.h>
58 #include <utilities/debugging.h>
60 #include <CoreFoundation/CoreFoundation.h>
63 #define MINIMIZE_INCLUDES MINIMIZE_INCLUDES
64 #include <ipc/securityd_client.h>
65 #include <securityd/spi.h>
67 #include <Security/SecuritydXPC.h>
68 #include "SOSPeerInfoDER.h"
70 const char * kSOSCCCircleChangedNotification = "com.apple.security.secureobjectsync.circlechanged";
71 const char * kSOSCCViewMembershipChangedNotification = "com.apple.security.secureobjectsync.viewschanged";
72 const char * kSOSCCInitialSyncChangedNotification = "com.apple.security.secureobjectsync.initialsyncchanged";
73 const char * kSOSCCHoldLockForInitialSync = "com.apple.security.secureobjectsync.holdlock";
74 const char * kSOSCCPeerAvailable = "com.apple.security.secureobjectsync.peeravailable";
75 const char * kSOSCCRecoveryKeyChanged = "com.apple.security.secureobjectsync.recoverykeychanged";
77 #define do_if_registered(sdp, ...) if (gSecurityd && gSecurityd->sdp) { return gSecurityd->sdp(__VA_ARGS__); }
79 static bool xpc_dictionary_entry_is_type(xpc_object_t dictionary, const char *key, xpc_type_t type)
81 xpc_object_t value = xpc_dictionary_get_value(dictionary, key);
83 return value && (xpc_get_type(value) == type);
86 SOSCCStatus SOSCCThisDeviceIsInCircle(CFErrorRef *error)
88 sec_trace_enter_api(NULL);
89 sec_trace_return_api(SOSCCStatus, ^{
90 SOSCCStatus result = kSOSCCError;
92 do_if_registered(soscc_ThisDeviceIsInCircle, error);
94 xpc_object_t message = securityd_create_message(kSecXPCOpDeviceInCircle, error);
96 xpc_object_t response = securityd_message_with_reply_sync(message, error);
98 if (response && xpc_dictionary_entry_is_type(response, kSecXPCKeyResult, XPC_TYPE_INT64)) {
99 result = (SOSCCStatus) xpc_dictionary_get_int64(response, kSecXPCKeyResult);
101 result = kSOSCCError;
105 if (response && securityd_message_no_error(response, error))
107 char *desc = xpc_copy_description(response);
108 SecCFCreateErrorWithFormat(0, sSecXPCErrorDomain, NULL, error, NULL, CFSTR("Remote error occurred/no info: %s"), desc);
115 }, CFSTR("SOSCCStatus=%d"))
118 static bool cfstring_to_error_request(enum SecXPCOperation op, CFStringRef string, CFErrorRef* error)
120 __block bool result = false;
122 secdebug("sosops","enter - operation: %d", op);
123 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
124 xpc_object_t xString = _CFXPCCreateXPCObjectFromCFObject(string);
125 bool success = false;
127 xpc_dictionary_set_value(message, kSecXPCKeyString, xString);
132 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
133 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
139 static bool deviceid_to_bool_error_request(enum SecXPCOperation op,
143 __block bool result = false;
145 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
146 CFStringPerformWithCString(IDS, ^(const char *utf8Str) {
147 xpc_dictionary_set_string(message, kSecXPCKeyDeviceID, utf8Str);
150 }, ^bool(xpc_object_t response, CFErrorRef *error) {
151 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
158 static SOSRingStatus cfstring_to_uint64_request(enum SecXPCOperation op, CFStringRef string, CFErrorRef* error)
160 __block bool result = false;
162 secdebug("sosops","enter - operation: %d", op);
163 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
164 xpc_object_t xString = _CFXPCCreateXPCObjectFromCFObject(string);
165 bool success = false;
167 xpc_dictionary_set_value(message, kSecXPCKeyString, xString);
172 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
173 result = xpc_dictionary_get_int64(response, kSecXPCKeyResult);
179 static CFStringRef simple_cfstring_error_request(enum SecXPCOperation op, CFErrorRef* error)
181 __block CFStringRef result = NULL;
183 secdebug("sosops","enter - operation: %d", op);
184 securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
185 const char *c_string = xpc_dictionary_get_string(response, kSecXPCKeyResult);
188 result = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)c_string, strlen(c_string), kCFStringEncodingUTF8, false);
191 return c_string != NULL;
196 static bool simple_bool_error_request(enum SecXPCOperation op, CFErrorRef* error)
198 __block bool result = false;
200 secdebug("sosops","enter - operation: %d", op);
201 securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
202 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
208 static bool SecXPCDictionarySetPeerInfoData(xpc_object_t message, const char *key, SOSPeerInfoRef peerInfo, CFErrorRef *error) {
209 bool success = false;
210 CFDataRef peerData = SOSPeerInfoCopyEncodedData(peerInfo, kCFAllocatorDefault, error);
212 success = SecXPCDictionarySetData(message, key, peerData, error);
214 CFReleaseNull(peerData);
218 static bool peer_info_to_bool_error_request(enum SecXPCOperation op, SOSPeerInfoRef peerInfo, CFErrorRef* error)
220 __block bool result = false;
222 secdebug("sosops","enter - operation: %d", op);
223 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
224 return SecXPCDictionarySetPeerInfoData(message, kSecXPCKeyPeerInfo, peerInfo, error);
225 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
226 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
232 static CFBooleanRef cfarray_to_cfboolean_error_request(enum SecXPCOperation op, CFArrayRef views, CFErrorRef* error)
234 __block bool result = false;
236 secdebug("sosops","enter - operation: %d", op);
237 bool noError = securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
238 return SecXPCDictionarySetPList(message, kSecXPCKeyArray, views, error);
239 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
240 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
243 return noError ? (result ? kCFBooleanTrue : kCFBooleanFalse) : NULL;
247 static CFSetRef cfset_cfset_to_cfset_error_request(enum SecXPCOperation op, CFSetRef set1, CFSetRef set2, CFErrorRef* error)
249 __block CFSetRef result = NULL;
251 secdebug("sosops","enter - operation: %d", op);
252 bool noError = securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
253 return SecXPCDictionarySetPList(message, kSecXPCKeySet, set1, error) && SecXPCDictionarySetPList(message, kSecXPCKeySet2, set2, error);
254 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
255 result = SecXPCDictionaryCopySet(response, kSecXPCKeyResult, error);
260 CFReleaseNull(result);
266 static bool escrow_to_bool_error_request(enum SecXPCOperation op, CFStringRef escrow_label, uint64_t tries, CFErrorRef* error)
268 __block bool result = false;
270 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
272 bool success = false;
273 xpc_object_t xEscrowLabel = _CFXPCCreateXPCObjectFromCFObject(escrow_label);
275 xpc_dictionary_set_value(message, kSecXPCKeyEscrowLabel, xEscrowLabel);
280 xpc_dictionary_set_int64(message, kSecXPCKeyTriesLabel, tries);
285 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
286 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
292 static CF_RETURNS_RETAINED CFArrayRef simple_array_error_request(enum SecXPCOperation op, CFErrorRef* error)
294 __block CFArrayRef result = NULL;
296 secdebug("sosops","enter - operation: %d", op);
297 if (securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, CFErrorRef *error) {
298 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCKeyResult);
299 result = _CFXPCCreateCFObjectFromXPCObject(temp_result);
300 return result != NULL;
302 if (!isArray(result)) {
303 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected array, got: %@"), result);
304 CFReleaseNull(result);
310 static CF_RETURNS_RETAINED CFArrayRef der_array_error_request(enum SecXPCOperation op, CFErrorRef* error)
312 __block CFArrayRef result = NULL;
314 secdebug("sosops","enter - operation: %d", op);
315 if (securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, CFErrorRef *error) {
317 const uint8_t* bytes = xpc_dictionary_get_data(response, kSecXPCKeyResult, &length);
318 der_decode_plist(kCFAllocatorDefault, 0, (CFPropertyListRef*) &result, error, bytes, bytes + length);
320 return result != NULL;
322 if (!isArray(result)) {
323 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected array, got: %@"), result);
324 CFReleaseNull(result);
330 static CFDictionaryRef strings_to_dictionary_error_request(enum SecXPCOperation op, CFErrorRef* error)
332 __block CFDictionaryRef result = NULL;
334 secdebug("sosops","enter - operation: %d", op);
336 if (securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, CFErrorRef *error) {
337 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCKeyResult);
339 result = _CFXPCCreateCFObjectFromXPCObject(temp_result);
340 return result != NULL;
343 if (!isDictionary(result)) {
344 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected dictionary, got: %@"), result);
345 CFReleaseNull(result);
352 static int simple_int_error_request(enum SecXPCOperation op, CFErrorRef* error)
354 __block int result = 0;
356 secdebug("sosops","enter - operation: %d", op);
357 securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
358 int64_t temp_result = xpc_dictionary_get_int64(response, kSecXPCKeyResult);
359 if ((temp_result >= INT32_MIN) && (temp_result <= INT32_MAX)) {
360 result = (int)temp_result;
367 static SOSPeerInfoRef peer_info_error_request(enum SecXPCOperation op, CFErrorRef* error)
369 SOSPeerInfoRef result = NULL;
370 __block CFDataRef data = NULL;
372 secdebug("sosops","enter - operation: %d", op);
373 securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, CFErrorRef *error) {
374 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCKeyResult);
375 if (response && (NULL != temp_result)) {
376 data = _CFXPCCreateCFObjectFromXPCObject(temp_result);
382 result = SOSPeerInfoCreateFromData(kCFAllocatorDefault, error, data);
384 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected CFData, got: %@"), data);
391 static CFDataRef data_to_error_request(enum SecXPCOperation op, CFErrorRef *error)
393 __block CFDataRef result = NULL;
395 secdebug("sosops", "enter -- operation: %d", op);
396 securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, CFErrorRef *error) {
397 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCKeyResult);
398 if (response && (NULL != temp_result)) {
399 result = _CFXPCCreateCFObjectFromXPCObject(temp_result);
401 return result != NULL;
404 if (!isData(result)) {
405 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected CFData, got: %@"), result);
412 static CFArrayRef array_of_info_error_request(enum SecXPCOperation op, CFErrorRef* error)
414 __block CFArrayRef result = NULL;
416 secdebug("sosops","enter - operation: %d", op);
417 securityd_send_sync_and_do(op, error, NULL, ^bool(xpc_object_t response, CFErrorRef *error) {
418 xpc_object_t encoded_array = xpc_dictionary_get_value(response, kSecXPCKeyResult);
419 if (response && (NULL != encoded_array)) {
420 result = CreateArrayOfPeerInfoWithXPCObject(encoded_array, error);
422 return result != NULL;
425 if (!isArray(result)) {
426 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected array, got: %@"), result);
427 CFReleaseNull(result);
432 static CF_RETURNS_RETAINED SOSPeerInfoRef data_to_peer_info_error_request(enum SecXPCOperation op, CFDataRef secret, CFErrorRef* error)
434 __block SOSPeerInfoRef result = false;
435 __block CFDataRef data = NULL;
437 secdebug("sosops", "enter - operation: %d", op);
438 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
439 xpc_object_t xsecretData = _CFXPCCreateXPCObjectFromCFObject(secret);
440 bool success = false;
442 xpc_dictionary_set_value(message, kSecXPCKeyNewPublicBackupKey, xsecretData);
447 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
448 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCKeyResult);
449 if (response && (NULL != temp_result)) {
450 data = _CFXPCCreateCFObjectFromXPCObject(temp_result);
456 result = SOSPeerInfoCreateFromData(kCFAllocatorDefault, error, data);
458 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected CFData, got: %@"), data);
465 static bool keybag_and_bool_to_bool_error_request(enum SecXPCOperation op, CFDataRef data, bool include, CFErrorRef* error)
467 secdebug("sosops", "enter - operation: %d", op);
468 return securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
469 xpc_object_t xData = _CFXPCCreateXPCObjectFromCFObject(data);
470 bool success = false;
472 xpc_dictionary_set_value(message, kSecXPCKeyKeybag, xData);
476 xpc_dictionary_set_bool(message, kSecXPCKeyIncludeV0, include);
478 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
479 return xpc_dictionary_get_bool(response, kSecXPCKeyResult);
483 static bool recovery_and_bool_to_bool_error_request(enum SecXPCOperation op, CFDataRef data, CFErrorRef* error)
485 secdebug("sosops", "enter - operation: %d", op);
486 return securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
487 xpc_object_t xData = _CFXPCCreateXPCObjectFromCFObject(data);
488 bool success = false;
490 xpc_dictionary_set_value(message, kSecXPCKeyRecoveryPublicKey, xData);
495 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
496 return xpc_dictionary_get_bool(response, kSecXPCKeyResult);
500 static bool info_array_to_bool_error_request(enum SecXPCOperation op, CFArrayRef peer_infos, CFErrorRef* error)
502 __block bool result = false;
504 secdebug("sosops", "enter - operation: %d", op);
505 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
506 xpc_object_t encoded_peers = CreateXPCObjectWithArrayOfPeerInfo(peer_infos, error);
508 xpc_dictionary_set_value(message, kSecXPCKeyPeerInfoArray, encoded_peers);
509 return encoded_peers != NULL;
510 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
511 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
517 static bool uint64_t_to_bool_error_request(enum SecXPCOperation op,
521 __block bool result = false;
523 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
524 xpc_dictionary_set_uint64(message, kSecXPCLimitInMinutes, number);
526 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
527 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
534 static bool cfstring_and_cfdata_to_cfdata_cfdata_error_request(enum SecXPCOperation op, CFStringRef viewName, CFDataRef input, CFDataRef* data, CFDataRef* data2, CFErrorRef* error) {
535 secdebug("sosops", "enter - operation: %d", op);
536 __block bool result = false;
537 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
538 xpc_object_t xviewname = _CFXPCCreateXPCObjectFromCFObject(viewName);
539 xpc_object_t xinput = _CFXPCCreateXPCObjectFromCFObject(input);
540 bool success = false;
541 if (xviewname && xinput){
542 xpc_dictionary_set_value(message, kSecXPCKeyViewName, xviewname);
543 xpc_dictionary_set_value(message, kSecXPCData, xinput);
549 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
550 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
552 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCData);
553 if (response && (NULL != temp_result) && data) {
554 *data = _CFXPCCreateCFObjectFromXPCObject(temp_result);
556 temp_result = xpc_dictionary_get_value(response, kSecXPCKeyKeybag);
557 if (response && (NULL != temp_result) && data2) {
558 *data2 = _CFXPCCreateCFObjectFromXPCObject(temp_result);
564 if (data &&!isData(*data)) {
565 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected CFData, got: %@"), *data);
567 if (data2 &&!isData(*data2)) {
568 SOSErrorCreate(kSOSErrorUnexpectedType, error, NULL, CFSTR("Expected CFData, got: %@"), *data2);
574 static bool cfdata_and_int_error_request_returns_bool(enum SecXPCOperation op, CFDataRef thedata,
575 PiggyBackProtocolVersion version, CFErrorRef *error) {
576 __block bool result = false;
578 sec_trace_enter_api(NULL);
579 securityd_send_sync_and_do(op, error, ^(xpc_object_t message, CFErrorRef *error) {
580 xpc_object_t xdata = _CFXPCCreateXPCObjectFromCFObject(thedata);
581 bool success = false;
583 xpc_dictionary_set_value(message, kSecXPCData, xdata);
584 xpc_dictionary_set_uint64(message, kSecXPCVersion, version);
590 }, ^(xpc_object_t response, __unused CFErrorRef *error) {
591 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
598 static CFDataRef cfdata_error_request_returns_cfdata(enum SecXPCOperation op, CFDataRef thedata, CFErrorRef *error) {
599 __block CFDataRef result = NULL;
601 sec_trace_enter_api(NULL);
602 securityd_send_sync_and_do(op, error, ^(xpc_object_t message, CFErrorRef *error) {
603 xpc_object_t xdata = _CFXPCCreateXPCObjectFromCFObject(thedata);
604 bool success = false;
606 xpc_dictionary_set_value(message, kSecXPCData, xdata);
611 }, ^(xpc_object_t response, __unused CFErrorRef *error) {
612 xpc_object_t temp_result = xpc_dictionary_get_value(response, kSecXPCKeyResult);
613 if (response && (NULL != temp_result)) {
614 CFTypeRef object = _CFXPCCreateCFObjectFromXPCObject(temp_result);
615 result = copyIfData(object, error);
616 CFReleaseNull(object);
618 return (bool) (result != NULL);
624 bool SOSCCRequestToJoinCircle(CFErrorRef* error)
626 sec_trace_enter_api(NULL);
627 sec_trace_return_bool_api(^{
628 do_if_registered(soscc_RequestToJoinCircle, error);
630 return simple_bool_error_request(kSecXPCOpRequestToJoin, error);
634 bool SOSCCRequestToJoinCircleAfterRestore(CFErrorRef* error)
636 sec_trace_enter_api(NULL);
637 sec_trace_return_bool_api(^{
638 do_if_registered(soscc_RequestToJoinCircleAfterRestore, error);
640 return simple_bool_error_request(kSecXPCOpRequestToJoinAfterRestore, error);
644 bool SOSCCAccountHasPublicKey(CFErrorRef *error)
647 sec_trace_enter_api(NULL);
648 sec_trace_return_bool_api(^{
649 do_if_registered(soscc_AccountHasPublicKey, error);
651 return simple_bool_error_request(kSecXPCOpAccountHasPublicKey, error);
656 bool SOSCCAccountIsNew(CFErrorRef *error)
658 sec_trace_enter_api(NULL);
659 sec_trace_return_bool_api(^{
660 do_if_registered(soscc_AccountIsNew, error);
662 return simple_bool_error_request(kSecXPCOpAccountIsNew, error);
666 bool SOSCCWaitForInitialSync(CFErrorRef* error)
668 sec_trace_enter_api(NULL);
669 sec_trace_return_bool_api(^{
670 do_if_registered(soscc_WaitForInitialSync, error);
672 return simple_bool_error_request(kSecXPCOpWaitForInitialSync, error);
676 CFArrayRef SOSCCCopyYetToSyncViewsList(CFErrorRef* error)
678 sec_trace_enter_api(NULL);
679 sec_trace_return_api(CFArrayRef, ^{
680 do_if_registered(soscc_CopyYetToSyncViewsList, error);
682 return simple_array_error_request(kSecXPCOpCopyYetToSyncViews, error);
686 bool SOSCCRequestEnsureFreshParameters(CFErrorRef* error)
688 sec_trace_enter_api(NULL);
689 sec_trace_return_bool_api(^{
690 do_if_registered(soscc_RequestEnsureFreshParameters, error);
692 return simple_bool_error_request(kSecXPCOpRequestEnsureFreshParameters, error);
696 CFStringRef SOSCCGetAllTheRings(CFErrorRef *error){
697 sec_trace_enter_api(NULL);
698 sec_trace_return_api(CFStringRef, ^{
699 do_if_registered(soscc_GetAllTheRings, error);
702 return simple_cfstring_error_request(kSecXPCOpGetAllTheRings, error);
705 bool SOSCCApplyToARing(CFStringRef ringName, CFErrorRef* error)
707 sec_trace_enter_api(NULL);
708 sec_trace_return_bool_api(^{
709 do_if_registered(soscc_ApplyToARing, ringName, error);
711 return cfstring_to_error_request(kSecXPCOpApplyToARing, ringName, error);
715 bool SOSCCWithdrawlFromARing(CFStringRef ringName, CFErrorRef* error)
717 sec_trace_enter_api(NULL);
718 sec_trace_return_bool_api(^{
719 do_if_registered(soscc_WithdrawlFromARing, ringName, error);
721 return cfstring_to_error_request(kSecXPCOpWithdrawlFromARing, ringName, error);
725 SOSRingStatus SOSCCRingStatus(CFStringRef ringName, CFErrorRef* error)
727 sec_trace_enter_api(NULL);
728 sec_trace_return_api(SOSRingStatus, ^{
729 do_if_registered(soscc_RingStatus, ringName, error);
731 return cfstring_to_uint64_request(kSecXPCOpRingStatus, ringName, error);
732 }, CFSTR("SOSCCStatus=%d"))
735 bool SOSCCEnableRing(CFStringRef ringName, CFErrorRef* error)
737 sec_trace_enter_api(NULL);
738 sec_trace_return_bool_api(^{
739 do_if_registered(soscc_EnableRing, ringName, error);
741 return cfstring_to_error_request(kSecXPCOpEnableRing, ringName, error);
745 bool SOSCCAccountSetToNew(CFErrorRef *error)
747 secwarning("SOSCCAccountSetToNew called");
748 sec_trace_enter_api(NULL);
749 sec_trace_return_bool_api(^{
750 do_if_registered(soscc_SetToNew, error);
751 return simple_bool_error_request(kSecXPCOpAccountSetToNew, error);
755 bool SOSCCResetToOffering(CFErrorRef* error)
757 secwarning("SOSCCResetToOffering called");
758 sec_trace_enter_api(NULL);
759 sec_trace_return_bool_api(^{
760 do_if_registered(soscc_ResetToOffering, error);
762 return simple_bool_error_request(kSecXPCOpResetToOffering, error);
766 bool SOSCCResetToEmpty(CFErrorRef* error)
768 secwarning("SOSCCResetToEmpty called");
769 sec_trace_enter_api(NULL);
770 sec_trace_return_bool_api(^{
771 do_if_registered(soscc_ResetToEmpty, error);
773 return simple_bool_error_request(kSecXPCOpResetToEmpty, error);
777 bool SOSCCRemovePeersFromCircle(CFArrayRef peers, CFErrorRef* error)
779 sec_trace_enter_api(NULL);
780 sec_trace_return_bool_api(^{
781 do_if_registered(soscc_RemovePeersFromCircle, peers, error);
783 return info_array_to_bool_error_request(kSecXPCOpRemovePeersFromCircle, peers, error);
787 bool SOSCCRemoveThisDeviceFromCircle(CFErrorRef* error)
789 sec_trace_enter_api(NULL);
790 sec_trace_return_bool_api(^{
791 do_if_registered(soscc_RemoveThisDeviceFromCircle, error);
793 return simple_bool_error_request(kSecXPCOpRemoveThisDeviceFromCircle, error);
797 bool SOSCCLoggedOutOfAccount(CFErrorRef* error)
799 sec_trace_enter_api(NULL);
800 sec_trace_return_bool_api(^{
801 do_if_registered(soscc_LoggedOutOfAccount, error);
803 return simple_bool_error_request(kSecXPCOpLoggedOutOfAccount, error);
807 bool SOSCCBailFromCircle_BestEffort(uint64_t limit_in_seconds, CFErrorRef* error)
809 sec_trace_enter_api(NULL);
810 sec_trace_return_bool_api(^{
811 do_if_registered(soscc_BailFromCircle, limit_in_seconds, error);
813 return uint64_t_to_bool_error_request(kSecXPCOpBailFromCircle, limit_in_seconds, error);
817 bool SOSCCSignedOut(bool immediate, CFErrorRef* error)
819 uint64_t limit = strtoul(optarg, NULL, 10);
822 return SOSCCRemoveThisDeviceFromCircle(error);
824 return SOSCCBailFromCircle_BestEffort(limit, error);
828 CFArrayRef SOSCCCopyPeerPeerInfo(CFErrorRef* error)
830 sec_trace_enter_api(NULL);
831 sec_trace_return_api(CFArrayRef, ^{
832 do_if_registered(soscc_CopyPeerInfo, error);
834 return array_of_info_error_request(kSecXPCOpCopyPeerPeerInfo, error);
835 }, CFSTR("return=%@"));
838 CFArrayRef SOSCCCopyConcurringPeerPeerInfo(CFErrorRef* error)
840 sec_trace_enter_api(NULL);
841 sec_trace_return_api(CFArrayRef, ^{
842 do_if_registered(soscc_CopyConcurringPeerInfo, error);
844 return array_of_info_error_request(kSecXPCOpCopyConcurringPeerPeerInfo, error);
845 }, CFSTR("return=%@"));
848 CFArrayRef SOSCCCopyGenerationPeerInfo(CFErrorRef* error)
850 sec_trace_enter_api(NULL);
851 sec_trace_return_api(CFArrayRef, ^{
852 do_if_registered(soscc_CopyGenerationPeerInfo, error);
854 return simple_array_error_request(kSecXPCOpCopyGenerationPeerInfo, error);
855 }, CFSTR("return=%@"));
858 CFArrayRef SOSCCCopyApplicantPeerInfo(CFErrorRef* error)
860 sec_trace_enter_api(NULL);
861 sec_trace_return_api(CFArrayRef, ^{
862 do_if_registered(soscc_CopyApplicantPeerInfo, error);
864 return array_of_info_error_request(kSecXPCOpCopyApplicantPeerInfo, error);
865 }, CFSTR("return=%@"));
868 bool SOSCCValidateUserPublic(CFErrorRef* error){
869 sec_trace_enter_api(NULL);
870 sec_trace_return_api(bool, ^{
871 do_if_registered(soscc_ValidateUserPublic, error);
873 return simple_bool_error_request(kSecXPCOpValidateUserPublic, error);
877 CFArrayRef SOSCCCopyValidPeerPeerInfo(CFErrorRef* error)
879 sec_trace_enter_api(NULL);
880 sec_trace_return_api(CFArrayRef, ^{
881 do_if_registered(soscc_CopyValidPeerPeerInfo, error);
883 return array_of_info_error_request(kSecXPCOpCopyValidPeerPeerInfo, error);
884 }, CFSTR("return=%@"));
887 CFArrayRef SOSCCCopyNotValidPeerPeerInfo(CFErrorRef* error)
889 sec_trace_enter_api(NULL);
890 sec_trace_return_api(CFArrayRef, ^{
891 do_if_registered(soscc_CopyNotValidPeerPeerInfo, error);
893 return array_of_info_error_request(kSecXPCOpCopyNotValidPeerPeerInfo, error);
894 }, CFSTR("return=%@"));
897 CFArrayRef SOSCCCopyRetirementPeerInfo(CFErrorRef* error)
899 sec_trace_enter_api(NULL);
900 sec_trace_return_api(CFArrayRef, ^{
901 do_if_registered(soscc_CopyRetirementPeerInfo, error);
903 return array_of_info_error_request(kSecXPCOpCopyRetirementPeerInfo, error);
904 }, CFSTR("return=%@"));
907 CFArrayRef SOSCCCopyViewUnawarePeerInfo(CFErrorRef* error)
909 sec_trace_enter_api(NULL);
910 sec_trace_return_api(CFArrayRef, ^{
911 do_if_registered(soscc_CopyViewUnawarePeerInfo, error);
913 return array_of_info_error_request(kSecXPCOpCopyViewUnawarePeerInfo, error);
914 }, CFSTR("return=%@"));
917 CFDataRef SOSCCCopyAccountState(CFErrorRef* error)
919 sec_trace_enter_api(NULL);
920 sec_trace_return_api(CFDataRef, ^{
921 do_if_registered(soscc_CopyAccountState, error);
923 return data_to_error_request(kSecXPCOpCopyAccountData, error);
924 }, CFSTR("return=%@"));
927 bool SOSCCDeleteAccountState(CFErrorRef *error)
929 sec_trace_enter_api(NULL);
930 sec_trace_return_api(bool, ^{
931 do_if_registered(soscc_DeleteAccountState, error);
932 return simple_bool_error_request(kSecXPCOpDeleteAccountData, error);
935 CFDataRef SOSCCCopyEngineData(CFErrorRef* error)
937 sec_trace_enter_api(NULL);
938 sec_trace_return_api(CFDataRef, ^{
939 do_if_registered(soscc_CopyEngineData, error);
941 return data_to_error_request(kSecXPCOpCopyEngineData, error);
942 }, CFSTR("return=%@"));
945 bool SOSCCDeleteEngineState(CFErrorRef *error)
947 sec_trace_enter_api(NULL);
948 sec_trace_return_api(bool, ^{
949 do_if_registered(soscc_DeleteEngineState, error);
950 return simple_bool_error_request(kSecXPCOpDeleteEngineData, error);
954 SOSPeerInfoRef SOSCCCopyMyPeerInfo(CFErrorRef *error)
956 sec_trace_enter_api(NULL);
957 sec_trace_return_api(SOSPeerInfoRef, ^{
958 do_if_registered(soscc_CopyMyPeerInfo, error);
960 return peer_info_error_request(kSecXPCOpCopyMyPeerInfo, error);
961 }, CFSTR("return=%@"));
964 static CFArrayRef SOSCCCopyEngineState(CFErrorRef* error)
966 sec_trace_enter_api(NULL);
967 sec_trace_return_api(CFArrayRef, ^{
968 do_if_registered(soscc_CopyEngineState, error);
970 return der_array_error_request(kSecXPCOpCopyEngineState, error);
971 }, CFSTR("return=%@"));
974 CFStringRef kSOSCCEngineStatePeerIDKey = CFSTR("PeerID");
975 CFStringRef kSOSCCEngineStateManifestCountKey = CFSTR("ManifestCount");
976 CFStringRef kSOSCCEngineStateSyncSetKey = CFSTR("SyncSet");
977 CFStringRef kSOSCCEngineStateCoderKey = CFSTR("CoderDump");
978 CFStringRef kSOSCCEngineStateManifestHashKey = CFSTR("ManifestHash");
980 void SOSCCForEachEngineStateAsStringFromArray(CFArrayRef states, void (^block)(CFStringRef oneStateString)) {
982 CFArrayForEach(states, ^(const void *value) {
983 CFDictionaryRef dict = asDictionary(value, NULL);
985 CFMutableStringRef description = CFStringCreateMutable(kCFAllocatorDefault, 0);
987 CFStringRef id = asString(CFDictionaryGetValue(dict, kSOSCCEngineStatePeerIDKey), NULL);
990 CFStringAppendFormat(description, NULL, CFSTR("remote %@ "), id);
992 CFStringAppendFormat(description, NULL, CFSTR("local "));
995 CFSetRef viewSet = asSet(CFDictionaryGetValue(dict, kSOSCCEngineStateSyncSetKey), NULL);
997 CFStringSetPerformWithDescription(viewSet, ^(CFStringRef setDescription) {
998 CFStringAppend(description, setDescription);
1001 CFStringAppendFormat(description, NULL, CFSTR("<Missing view set!>"));
1004 CFStringAppendFormat(description, NULL, CFSTR(" [%@]"),
1005 CFDictionaryGetValue(dict, kSOSCCEngineStateManifestCountKey));
1007 CFDataRef mainfestHash = asData(CFDictionaryGetValue(dict, kSOSCCEngineStateManifestHashKey), NULL);
1010 CFDataPerformWithHexString(mainfestHash, ^(CFStringRef dataString) {
1011 CFStringAppendFormat(description, NULL, CFSTR(" %@"), dataString);
1015 CFStringRef coderDescription = asString(CFDictionaryGetValue(dict, kSOSCCEngineStateCoderKey), NULL);
1016 if (coderDescription) {
1017 CFStringAppendFormat(description, NULL, CFSTR(" %@"), coderDescription);
1022 CFReleaseNull(description);
1027 bool SOSCCForEachEngineStateAsString(CFErrorRef* error, void (^block)(CFStringRef oneStateString)) {
1028 CFArrayRef states = SOSCCCopyEngineState(error);
1032 SOSCCForEachEngineStateAsStringFromArray(states, block);
1038 bool SOSCCAcceptApplicants(CFArrayRef applicants, CFErrorRef* error)
1040 sec_trace_enter_api(NULL);
1041 sec_trace_return_bool_api(^{
1042 do_if_registered(soscc_AcceptApplicants, applicants, error);
1044 return info_array_to_bool_error_request(kSecXPCOpAcceptApplicants, applicants, error);
1048 bool SOSCCRejectApplicants(CFArrayRef applicants, CFErrorRef *error)
1050 sec_trace_enter_api(CFSTR("applicants=%@"), applicants);
1051 sec_trace_return_bool_api(^{
1052 do_if_registered(soscc_RejectApplicants, applicants, error);
1054 return info_array_to_bool_error_request(kSecXPCOpRejectApplicants, applicants, error);
1058 static CF_RETURNS_RETAINED SOSPeerInfoRef SOSSetNewPublicBackupKey(CFDataRef pubKey, CFErrorRef *error)
1060 sec_trace_enter_api(NULL);
1061 sec_trace_return_api(SOSPeerInfoRef, ^{
1062 do_if_registered(soscc_SetNewPublicBackupKey, pubKey, error);
1064 return data_to_peer_info_error_request(kSecXPCOpSetNewPublicBackupKey, pubKey, error);
1065 }, CFSTR("return=%@"));
1068 SOSPeerInfoRef SOSCCCopyMyPeerWithNewDeviceRecoverySecret(CFDataRef secret, CFErrorRef *error){
1069 CFDataRef publicKeyData = SOSCopyDeviceBackupPublicKey(secret, error);
1070 SOSPeerInfoRef copiedPeer = publicKeyData ? SOSSetNewPublicBackupKey(publicKeyData, error) : NULL;
1071 CFReleaseNull(publicKeyData);
1075 bool SOSCCRegisterSingleRecoverySecret(CFDataRef aks_bag, bool forV0Only, CFErrorRef *error){
1076 sec_trace_enter_api(NULL);
1077 sec_trace_return_bool_api(^{
1078 do_if_registered(soscc_RegisterSingleRecoverySecret, aks_bag, forV0Only, error);
1079 return keybag_and_bool_to_bool_error_request(kSecXPCOpSetBagForAllSlices, aks_bag, forV0Only, error);
1084 bool SOSCCRegisterRecoveryPublicKey(CFDataRef recovery_key, CFErrorRef *error){
1085 sec_trace_enter_api(NULL);
1086 sec_trace_return_bool_api(^{
1087 bool retval = false;
1088 do_if_registered(soscc_RegisterRecoveryPublicKey, recovery_key, error);
1089 if(!recovery_key) { // this is used to clear the rk
1090 CFDataRef empty = CFDataCreate(kCFAllocatorDefault, 0, 0);
1091 retval = recovery_and_bool_to_bool_error_request(kSecXPCOpRegisterRecoveryPublicKey, empty, error);
1092 CFReleaseNull(empty);
1094 retval = recovery_and_bool_to_bool_error_request(kSecXPCOpRegisterRecoveryPublicKey, recovery_key, error);
1100 CFDataRef SOSCCCopyRecoveryPublicKey(CFErrorRef *error){
1101 sec_trace_enter_api(NULL);
1102 sec_trace_return_api(CFDataRef, ^{
1103 do_if_registered(soscc_CopyRecoveryPublicKey, error);
1104 return data_to_error_request(kSecXPCOpGetRecoveryPublicKey, error);
1105 }, CFSTR("return=%@"));
1107 static bool label_and_password_to_bool_error_request(enum SecXPCOperation op,
1108 CFStringRef user_label, CFDataRef user_password,
1111 __block bool result = false;
1113 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1114 CFStringPerformWithCString(user_label, ^(const char *utf8Str) {
1115 xpc_dictionary_set_string(message, kSecXPCKeyUserLabel, utf8Str);
1117 xpc_dictionary_set_data(message, kSecXPCKeyUserPassword, CFDataGetBytePtr(user_password), CFDataGetLength(user_password));
1119 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1120 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1127 static bool label_and_password_and_dsid_to_bool_error_request(enum SecXPCOperation op,
1128 CFStringRef user_label, CFDataRef user_password,
1129 CFStringRef dsid, CFErrorRef* error)
1131 __block bool result = false;
1133 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1134 CFStringPerformWithCString(user_label, ^(const char *utf8Str) {
1135 xpc_dictionary_set_string(message, kSecXPCKeyUserLabel, utf8Str);
1137 CFStringPerformWithCString(dsid, ^(const char *utr8StrDSID) {
1138 xpc_dictionary_set_string(message, kSecXPCKeyDSID, utr8StrDSID);
1140 xpc_dictionary_set_data(message, kSecXPCKeyUserPassword, CFDataGetBytePtr(user_password), CFDataGetLength(user_password));
1142 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1143 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1150 static bool cfstring_to_bool_error_request(enum SecXPCOperation op,
1154 __block bool result = false;
1156 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1157 CFStringPerformWithCString(string, ^(const char *utf8Str) {
1158 xpc_dictionary_set_string(message, kSecXPCKeyDeviceID, utf8Str);
1161 }, ^bool(xpc_object_t response, CFErrorRef *error) {
1162 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1169 static int idsDict_to_int_error_request(enum SecXPCOperation op,
1170 CFDictionaryRef IDS,
1173 __block int result = 0;
1175 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1176 SecXPCDictionarySetPListOptional(message, kSecXPCKeyIDSMessage, IDS, error);
1178 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1179 int64_t temp_result = xpc_dictionary_get_int64(response, kSecXPCKeyResult);
1180 if ((temp_result >= INT32_MIN) && (temp_result <= INT32_MAX)) {
1181 result = (int)temp_result;
1189 static bool idsData_peerID_to_bool_error_request(enum SecXPCOperation op, CFStringRef peerID,
1190 CFDataRef IDSMessage,
1193 __block bool result = 0;
1195 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1196 SecXPCDictionarySetData(message, kSecXPCKeyIDSMessage, IDSMessage, error);
1197 SecXPCDictionarySetString(message, kSecXPCKeyDeviceID, peerID, error);
1199 }, ^bool(xpc_object_t response, CFErrorRef *error) {
1200 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1206 static bool idscommand_to_bool_error_request(enum SecXPCOperation op,
1207 CFStringRef idsMessage,
1210 __block bool result = false;
1212 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1213 CFStringPerformWithCString(idsMessage, ^(const char *utf8Str) {
1214 xpc_dictionary_set_string(message, kSecXPCKeySendIDSMessage, utf8Str);
1217 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1218 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1225 bool SOSCCRegisterUserCredentials(CFStringRef user_label, CFDataRef user_password, CFErrorRef* error)
1227 secnotice("sosops", "SOSCCRegisterUserCredentials - calling SOSCCSetUserCredentials!! %@\n", user_label);
1228 return SOSCCSetUserCredentials(user_label, user_password, error);
1231 bool SOSCCSetUserCredentials(CFStringRef user_label, CFDataRef user_password, CFErrorRef* error)
1233 secnotice("sosops", "SOSCCSetUserCredentials!! %@\n", user_label);
1234 sec_trace_enter_api(CFSTR("user_label=%@"), user_label);
1235 sec_trace_return_bool_api(^{
1236 do_if_registered(soscc_SetUserCredentials, user_label, user_password, error);
1238 return label_and_password_to_bool_error_request(kSecXPCOpSetUserCredentials, user_label, user_password, error);
1242 bool SOSCCSetUserCredentialsAndDSID(CFStringRef user_label, CFDataRef user_password, CFStringRef dsid, CFErrorRef *error)
1244 secnotice("sosops", "SOSCCSetUserCredentialsAndDSID!! %@\n", user_label);
1245 sec_trace_enter_api(CFSTR("user_label=%@"), user_label);
1246 sec_trace_return_bool_api(^{
1247 do_if_registered(soscc_SetUserCredentialsAndDSID, user_label, user_password, dsid, error);
1249 bool result = false;
1250 __block CFStringRef account_dsid = dsid;
1252 require_action_quiet(user_label, out, SOSErrorCreate(kSOSErrorParam, error, NULL, CFSTR("user_label is nil")));
1253 require_action_quiet(user_password, out, SOSErrorCreate(kSOSErrorParam, error, NULL, CFSTR("user_password is nil")));
1255 if(account_dsid == NULL){
1256 account_dsid = CFSTR("");
1258 return label_and_password_and_dsid_to_bool_error_request(kSecXPCOpSetUserCredentialsAndDSID, user_label, user_password, account_dsid, error);
1264 bool SOSCCSetDeviceID(CFStringRef IDS, CFErrorRef* error)
1266 secnotice("sosops", "SOSCCSetDeviceID!! %@\n", IDS);
1267 sec_trace_enter_api(NULL);
1268 sec_trace_return_bool_api(^{
1269 do_if_registered(soscc_SetDeviceID, IDS, error);
1270 bool result = cfstring_to_bool_error_request(kSecXPCOpSetDeviceID, IDS, error);
1275 bool SOSCCIDSServiceRegistrationTest(CFStringRef message, CFErrorRef *error)
1277 secnotice("sosops", "SOSCCSendIDSTestMessage!! %@\n", message);
1278 sec_trace_enter_api(NULL);
1279 sec_trace_return_bool_api(^{
1280 do_if_registered(soscc_CheckIDSRegistration, message, error);
1281 return idscommand_to_bool_error_request(kSecXPCOpSendIDSMessage, message, error);
1285 bool SOSCCIDSPingTest(CFStringRef message, CFErrorRef *error)
1287 secnotice("sosops", "SOSCCSendIDSTestMessage!! %@\n", message);
1288 sec_trace_enter_api(NULL);
1289 sec_trace_return_bool_api(^{
1290 do_if_registered(soscc_PingTest, message, error);
1291 return idscommand_to_bool_error_request(kSecXPCOpPingTest, message, error);
1295 bool SOSCCIDSDeviceIDIsAvailableTest(CFErrorRef *error)
1297 secnotice("sosops", "SOSCCIDSDeviceIDIsAvailableTest!!\n");
1298 sec_trace_enter_api(NULL);
1299 sec_trace_return_bool_api(^{
1300 do_if_registered(soscc_GetIDSIDFromIDS, error);
1301 return simple_bool_error_request(kSecXPCOpIDSDeviceID, error);
1305 HandleIDSMessageReason SOSCCHandleIDSMessage(CFDictionaryRef IDS, CFErrorRef* error)
1307 secnotice("sosops", "SOSCCHandleIDSMessage!! %@\n", IDS);
1308 sec_trace_enter_api(NULL);
1309 sec_trace_return_api(HandleIDSMessageReason, ^{
1310 do_if_registered(soscc_HandleIDSMessage, IDS, error);
1311 return (HandleIDSMessageReason) idsDict_to_int_error_request(kSecXPCOpHandleIDSMessage, IDS, error);
1315 bool SOSCCClearPeerMessageKeyInKVS(CFStringRef peerID, CFErrorRef *error)
1317 secnotice("sosops", "SOSCCClearPeerMessageKeyInKVS!! %@\n", peerID);
1318 sec_trace_enter_api(NULL);
1319 sec_trace_return_bool_api(^{
1320 do_if_registered(socc_clearPeerMessageKeyInKVS, peerID, error);
1321 return cfstring_to_bool_error_request(kSecXPCOpClearKVSPeerMessage, peerID, error);
1326 bool SOSCCRequestSyncWithPeerOverKVSUsingIDOnly(CFStringRef peerID, CFErrorRef *error)
1328 secnotice("sosops", "SOSCCRequestSyncWithPeerOverKVSUsingIDOnly!! %@\n", peerID);
1329 sec_trace_enter_api(NULL);
1330 sec_trace_return_bool_api(^{
1331 do_if_registered(soscc_requestSyncWithPeerOverKVSIDOnly, peerID, error);
1332 return deviceid_to_bool_error_request(kSecXPCOpSyncWithKVSPeerIDOnly, peerID, error);
1336 bool SOSCCRequestSyncWithPeerOverKVS(CFStringRef peerID, CFDataRef message, CFErrorRef *error)
1338 secnotice("sosops", "SOSCCRequestSyncWithPeerOverKVS!! %@\n", peerID);
1339 sec_trace_enter_api(NULL);
1340 sec_trace_return_bool_api(^{
1341 do_if_registered(soscc_requestSyncWithPeerOverKVS, peerID, message, error);
1342 return idsData_peerID_to_bool_error_request(kSecXPCOpSyncWithKVSPeer, peerID, message, error);
1346 bool SOSCCTryUserCredentials(CFStringRef user_label, CFDataRef user_password, CFErrorRef* error)
1348 sec_trace_enter_api(CFSTR("user_label=%@"), user_label);
1349 sec_trace_return_bool_api(^{
1350 do_if_registered(soscc_TryUserCredentials, user_label, user_password, error);
1352 return label_and_password_to_bool_error_request(kSecXPCOpTryUserCredentials, user_label, user_password, error);
1357 bool SOSCCCanAuthenticate(CFErrorRef* error) {
1358 sec_trace_enter_api(NULL);
1359 sec_trace_return_bool_api(^{
1360 do_if_registered(soscc_CanAuthenticate, error);
1362 return simple_bool_error_request(kSecXPCOpCanAuthenticate, error);
1366 bool SOSCCPurgeUserCredentials(CFErrorRef* error) {
1367 sec_trace_enter_api(NULL);
1368 sec_trace_return_bool_api(^{
1369 do_if_registered(soscc_PurgeUserCredentials, error);
1371 return simple_bool_error_request(kSecXPCOpPurgeUserCredentials, error);
1375 enum DepartureReason SOSCCGetLastDepartureReason(CFErrorRef *error) {
1376 sec_trace_enter_api(NULL);
1377 sec_trace_return_api(enum DepartureReason, ^{
1378 do_if_registered(soscc_GetLastDepartureReason, error);
1380 return (enum DepartureReason) simple_int_error_request(kSecXPCOpGetLastDepartureReason, error);
1384 bool SOSCCSetLastDepartureReason(enum DepartureReason reason, CFErrorRef *error) {
1385 sec_trace_enter_api(NULL);
1386 sec_trace_return_api(bool, ^{
1387 do_if_registered(soscc_SetLastDepartureReason, reason, error);
1388 return securityd_send_sync_and_do(kSecXPCOpSetLastDepartureReason, error,
1389 ^bool(xpc_object_t message, CFErrorRef *error) {
1390 xpc_dictionary_set_int64(message, kSecXPCKeyReason, reason);
1393 ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1394 return xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1400 CFStringRef SOSCCCopyIncompatibilityInfo(CFErrorRef* error) {
1401 sec_trace_enter_api(NULL);
1402 sec_trace_return_api(CFStringRef, ^{
1403 do_if_registered(soscc_CopyIncompatibilityInfo, error);
1405 return simple_cfstring_error_request(kSecXPCOpCopyIncompatibilityInfo, error);
1409 CFStringRef SOSCCCopyDeviceID(CFErrorRef* error)
1411 sec_trace_enter_api(NULL);
1412 sec_trace_return_api(CFStringRef, ^{
1413 do_if_registered(soscc_CopyDeviceID, error);
1414 CFStringRef deviceID = simple_cfstring_error_request(kSecXPCOpRequestDeviceID, error);
1419 bool SOSCCProcessEnsurePeerRegistration(CFErrorRef* error){
1420 secnotice("updates", "enter SOSCCProcessEnsurePeerRegistration");
1421 sec_trace_enter_api(NULL);
1422 sec_trace_return_bool_api(^{
1423 do_if_registered(soscc_EnsurePeerRegistration, error);
1425 return simple_bool_error_request(soscc_EnsurePeerRegistration_id, error);
1430 CFSetRef /* CFString */ SOSCCProcessSyncWithPeers(CFSetRef peers, CFSetRef backupPeers, CFErrorRef* error)
1432 sec_trace_enter_api(NULL);
1433 sec_trace_return_api(CFSetRef, ^{
1434 do_if_registered(soscc_ProcessSyncWithPeers, peers, backupPeers, error);
1436 return cfset_cfset_to_cfset_error_request(kSecXPCOpProcessSyncWithPeers, peers, backupPeers, error);
1441 SyncWithAllPeersReason SOSCCProcessSyncWithAllPeers(CFErrorRef* error)
1443 sec_trace_enter_api(NULL);
1444 sec_trace_return_api(SyncWithAllPeersReason, ^{
1445 do_if_registered(soscc_ProcessSyncWithAllPeers, error);
1447 return (SyncWithAllPeersReason) simple_int_error_request(kSecXPCOpProcessSyncWithAllPeers, error);
1451 CFStringRef SOSCCGetStatusDescription(SOSCCStatus status)
1454 case kSOSCCInCircle:
1455 return CFSTR("InCircle");
1456 case kSOSCCNotInCircle:
1457 return CFSTR("NotInCircle");
1458 case kSOSCCRequestPending:
1459 return CFSTR("RequestPending");
1460 case kSOSCCCircleAbsent:
1461 return CFSTR("CircleAbsent");
1463 return CFSTR("InternalError");
1465 return CFSTR("Unknown Status");
1470 kSOSCCGeneralViewError = -1,
1471 kSOSCCViewMember = 0,
1472 kSOSCCViewNotMember = 1,
1473 kSOSCCViewNotQualified = 2,
1474 kSOSCCNoSuchView = 3,
1478 CFStringRef SOSCCGetViewResultDescription(SOSViewResultCode vrc)
1481 case kSOSCCGeneralViewError:
1482 return CFSTR("GeneralViewError");
1483 case kSOSCCViewMember:
1484 return CFSTR("ViewMember");
1485 case kSOSCCViewNotMember:
1486 return CFSTR("ViewNotMember");
1487 case kSOSCCViewNotQualified:
1488 return CFSTR("ViewNotQualified");
1489 case kSOSCCNoSuchView:
1490 return CFSTR("ViewUndefined");
1492 return CFSTR("Unknown View Status");
1497 static int64_t name_action_to_code_request(enum SecXPCOperation op, uint16_t error_result,
1498 CFStringRef name, uint64_t action, CFErrorRef *error) {
1499 __block int64_t result = error_result;
1501 securityd_send_sync_and_do(op, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1502 CFStringPerformWithCString(name, ^(const char *utf8Str) {
1503 xpc_dictionary_set_string(message, kSecXPCKeyViewName, utf8Str);
1505 xpc_dictionary_set_int64(message, kSecXPCKeyViewActionCode, action);
1507 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1508 if (response && xpc_dictionary_entry_is_type(response, kSecXPCKeyResult, XPC_TYPE_INT64)) {
1509 result = xpc_dictionary_get_int64(response, kSecXPCKeyResult);
1511 return result != error_result;
1517 SOSViewResultCode SOSCCView(CFStringRef view, SOSViewActionCode actionCode, CFErrorRef *error) {
1518 sec_trace_enter_api(NULL);
1519 sec_trace_return_api(SOSViewResultCode, ^{
1520 do_if_registered(soscc_View, view, actionCode, error);
1522 return (SOSViewResultCode) name_action_to_code_request(kSecXPCOpView, kSOSCCGeneralViewError, view, actionCode, error);
1523 }, CFSTR("SOSViewResultCode=%d"))
1527 bool SOSCCViewSet(CFSetRef enabledViews, CFSetRef disabledViews) {
1528 CFErrorRef *error = NULL;
1529 __block bool result = false;
1531 sec_trace_enter_api(NULL);
1532 sec_trace_return_bool_api(^{
1533 do_if_registered(soscc_ViewSet, enabledViews, disabledViews);
1534 return securityd_send_sync_and_do(kSecXPCOpViewSet, error, ^bool(xpc_object_t message, CFErrorRef *error) {
1535 xpc_object_t enabledSetXpc = CreateXPCObjectWithCFSetRef(enabledViews, error);
1536 xpc_object_t disabledSetXpc = CreateXPCObjectWithCFSetRef(disabledViews, error);
1537 if (enabledSetXpc) xpc_dictionary_set_value(message, kSecXPCKeyEnabledViewsKey, enabledSetXpc);
1538 if (disabledSetXpc) xpc_dictionary_set_value(message, kSecXPCKeyDisabledViewsKey, disabledSetXpc);
1539 return (enabledSetXpc != NULL) || (disabledSetXpc != NULL) ;
1540 }, ^bool(xpc_object_t response, __unused CFErrorRef *error) {
1541 result = xpc_dictionary_get_bool(response, kSecXPCKeyResult);
1547 SOSSecurityPropertyResultCode SOSCCSecurityProperty(CFStringRef property, SOSSecurityPropertyActionCode actionCode, CFErrorRef *error) {
1548 sec_trace_enter_api(NULL);
1549 sec_trace_return_api(SOSSecurityPropertyResultCode, ^{
1550 SOSSecurityPropertyResultCode result = kSOSCCGeneralSecurityPropertyError;
1551 do_if_registered(soscc_SecurityProperty, property, actionCode, error);
1552 xpc_object_t message = securityd_create_message(kSecXPCOpSecurityProperty, error);
1554 int64_t bigac = actionCode;
1555 xpc_dictionary_set_string(message, kSecXPCKeyViewName, CFStringGetCStringPtr(property, kCFStringEncodingUTF8));
1556 xpc_dictionary_set_int64(message, kSecXPCKeyViewActionCode, bigac);
1558 xpc_object_t response = securityd_message_with_reply_sync(message, error);
1560 if (response && xpc_dictionary_entry_is_type(response, kSecXPCKeyResult, XPC_TYPE_INT64)) {
1561 result = (SOSSecurityPropertyResultCode) xpc_dictionary_get_int64(response, kSecXPCKeyResult);
1564 if (result == kSOSCCGeneralSecurityPropertyError) {
1565 if (response && securityd_message_no_error(response, error)) {
1566 char *desc = xpc_copy_description(response);
1567 SecCFCreateErrorWithFormat(0, sSecXPCErrorDomain, NULL, error, NULL, CFSTR("Remote error occurred/no info: %s"), desc);
1578 }, CFSTR("SOSSecurityPropertyResultCode=%d"))
1581 static CFStringRef copyViewNames(size_t n, CFStringRef *views) {
1582 CFMutableStringRef retval = CFStringCreateMutable(kCFAllocatorDefault, 0);
1583 CFStringAppend(retval, CFSTR("|"));
1584 for(size_t i = 0; i < n; i++) {
1585 CFStringAppend(retval, views[i]);
1586 CFStringAppend(retval, CFSTR("|"));
1591 static bool sosIsViewSetSyncing(size_t n, CFStringRef *views) {
1592 __block bool retval = true;
1593 CFErrorRef error = NULL;
1595 if(n == 0 || views == NULL) return false;
1596 CFStringRef viewString = copyViewNames(n, views);
1598 SOSCCStatus cstatus = SOSCCThisDeviceIsInCircle(&error);
1599 if(cstatus != kSOSCCInCircle) {
1600 secnotice("viewCheck", "Checking view / circle status for %@: SOSCCStatus: (%@) Error: (%@)", viewString, SOSCCGetStatusDescription(cstatus), error);
1604 if(retval == true) {
1605 for(size_t i = 0; i < n; i++) {
1606 SOSViewResultCode vstatus = SOSCCView(views[i], kSOSCCViewQuery, &error);
1607 if(vstatus != kSOSCCViewMember) {
1608 secnotice("viewCheck", "Checking view / circle status for %@: SOSCCStatus: (%@) SOSViewResultCode(%@) Error: (%@)", views[i],
1609 SOSCCGetStatusDescription(cstatus), SOSCCGetViewResultDescription(vstatus), error);
1615 if(retval == true) {
1616 secnotice("viewCheck", "Checking view / circle status for %@: ENABLED", viewString);
1618 CFReleaseNull(error);
1619 CFReleaseNull(viewString);
1623 bool SOSCCIsIcloudKeychainSyncing(void) {
1624 CFStringRef views[] = { kSOSViewWiFi, kSOSViewAutofillPasswords, kSOSViewSafariCreditCards, kSOSViewOtherSyncable };
1625 return sosIsViewSetSyncing(sizeof(views)/sizeof(views[0]), views);
1628 bool SOSCCIsSafariSyncing(void) {
1629 CFStringRef views[] = { kSOSViewAutofillPasswords, kSOSViewSafariCreditCards };
1630 return sosIsViewSetSyncing(sizeof(views)/sizeof(views[0]), views);
1633 bool SOSCCIsAppleTVSyncing(void) {
1634 CFStringRef views[] = { kSOSViewAppleTV };
1635 return sosIsViewSetSyncing(sizeof(views)/sizeof(views[0]), views);
1638 bool SOSCCIsHomeKitSyncing(void) {
1639 CFStringRef views[] = { kSOSViewHomeKit };
1640 return sosIsViewSetSyncing(sizeof(views)/sizeof(views[0]), views);
1643 bool SOSCCIsWiFiSyncing(void) {
1644 CFStringRef views[] = { kSOSViewWiFi };
1645 return sosIsViewSetSyncing(sizeof(views)/sizeof(views[0]), views);
1648 bool SOSCCIsContinuityUnlockSyncing(void) {
1649 CFStringRef views[] = { kSOSViewContinuityUnlock };
1650 return sosIsViewSetSyncing(sizeof(views)/sizeof(views[0]), views);
1654 bool SOSCCSetEscrowRecord(CFStringRef escrow_label, uint64_t tries, CFErrorRef *error ){
1655 secnotice("escrow", "enter SOSCCSetEscrowRecord");
1656 sec_trace_enter_api(NULL);
1657 sec_trace_return_bool_api(^{
1658 do_if_registered(soscc_SetEscrowRecords, escrow_label, tries, error);
1660 return escrow_to_bool_error_request(kSecXPCOpSetEscrowRecord, escrow_label, tries, error);
1664 CFDictionaryRef SOSCCCopyEscrowRecord(CFErrorRef *error){
1665 secnotice("escrow", "enter SOSCCCopyEscrowRecord");
1666 sec_trace_enter_api(NULL);
1667 sec_trace_return_api(CFDictionaryRef, ^{
1668 do_if_registered(soscc_CopyEscrowRecords, error);
1670 return strings_to_dictionary_error_request(kSecXPCOpGetEscrowRecord, error);
1671 }, CFSTR("return=%@"))
1675 CFDictionaryRef SOSCCCopyBackupInformation(CFErrorRef *error) {
1676 secnotice("escrow", "enter SOSCCCopyBackupInformation");
1677 sec_trace_enter_api(NULL);
1678 sec_trace_return_api(CFDictionaryRef, ^{
1679 do_if_registered(soscc_CopyBackupInformation, error);
1680 return strings_to_dictionary_error_request(kSecXPCOpCopyBackupInformation, error);
1681 }, CFSTR("return=%@"))
1684 bool SOSCCCheckPeerAvailability(CFErrorRef *error){
1685 secnotice("peer", "enter SOSCCCheckPeerAvailability");
1686 sec_trace_enter_api(NULL);
1687 sec_trace_return_bool_api(^{
1688 do_if_registered(soscc_PeerAvailability, error);
1690 return simple_bool_error_request(kSecXPCOpCheckPeerAvailability, error);
1696 bool SOSWrapToBackupSliceKeyBagForView(CFStringRef viewName, CFDataRef input, CFDataRef* output, CFDataRef* bskbEncoded, CFErrorRef* error) {
1697 sec_trace_enter_api(NULL);
1698 sec_trace_return_bool_api(^{
1699 do_if_registered(sosbskb_WrapToBackupSliceKeyBagForView, viewName, input, output, bskbEncoded, error);
1701 return cfstring_and_cfdata_to_cfdata_cfdata_error_request(kSecXPCOpWrapToBackupSliceKeyBagForView, viewName, input, output, bskbEncoded, error);
1706 SOSPeerInfoRef SOSCCCopyApplication(CFErrorRef *error) {
1707 secnotice("hsa2PB", "enter SOSCCCopyApplication applicant");
1708 sec_trace_enter_api(NULL);
1710 sec_trace_return_api(SOSPeerInfoRef, ^{
1711 do_if_registered(soscc_CopyApplicant, error);
1712 return peer_info_error_request(kSecXPCOpCopyApplication, error);
1713 }, CFSTR("return=%@"));
1716 bool SOSCCCleanupKVSKeys(CFErrorRef *error) {
1717 secnotice("cleanup-keys", "enter SOSCCCleanupKVSKeys");
1718 sec_trace_enter_api(NULL);
1719 sec_trace_return_bool_api(^{
1720 do_if_registered(soscc_SOSCCCleanupKVSKeys, error);
1722 return simple_bool_error_request(kSecXPCOpKVSKeyCleanup, error);
1728 bool SOSCCTestPopulateKVSWithBadKeys(CFErrorRef *error) {
1729 secnotice("cleanup-keys", "enter SOSCCPopulateKVSWithBadKeys");
1730 sec_trace_enter_api(NULL);
1731 sec_trace_return_bool_api(^{
1732 do_if_registered(soscc_SOSCCTestPopulateKVSWithBadKeys, error);
1734 return simple_bool_error_request(kSecXPCOpPopulateKVS, error);
1740 CFDataRef SOSCCCopyCircleJoiningBlob(SOSPeerInfoRef applicant, CFErrorRef *error) {
1741 secnotice("hsa2PB", "enter SOSCCCopyCircleJoiningBlob approver");
1742 sec_trace_enter_api(NULL);
1744 sec_trace_return_api(CFDataRef, ^{
1745 CFDataRef result = NULL;
1746 do_if_registered(soscc_CopyCircleJoiningBlob, applicant, error);
1747 CFDataRef piData = SOSPeerInfoCopyEncodedData(applicant, kCFAllocatorDefault, error);
1748 result = cfdata_error_request_returns_cfdata(kSecXPCOpCopyCircleJoiningBlob, piData, error);
1749 CFReleaseNull(piData);
1751 }, CFSTR("return=%@"));
1754 CFDataRef SOSCCCopyInitialSyncData(CFErrorRef *error) {
1755 secnotice("circleJoin", "enter SOSCCCopyInitialSyncData approver");
1756 sec_trace_enter_api(NULL);
1758 sec_trace_return_api(CFDataRef, ^{
1759 do_if_registered(soscc_CopyInitialSyncData, error);
1760 return data_to_error_request(kSecXPCOpCopyInitialSyncBlob, error);
1761 }, CFSTR("return=%@"));
1764 bool SOSCCJoinWithCircleJoiningBlob(CFDataRef joiningBlob, PiggyBackProtocolVersion version, CFErrorRef *error) {
1765 secnotice("hsa2PB", "enter SOSCCJoinWithCircleJoiningBlob applicant");
1766 sec_trace_enter_api(NULL);
1767 sec_trace_return_bool_api(^{
1768 do_if_registered(soscc_JoinWithCircleJoiningBlob, joiningBlob, version, error);
1770 return cfdata_and_int_error_request_returns_bool(kSecXPCOpJoinWithCircleJoiningBlob, joiningBlob, version, error);
1776 bool SOSCCIsThisDeviceLastBackup(CFErrorRef *error) {
1777 secnotice("peer", "enter SOSCCIsThisDeviceLastBackup");
1778 sec_trace_enter_api(NULL);
1779 sec_trace_return_bool_api(^{
1780 do_if_registered(soscc_IsThisDeviceLastBackup, error);
1782 return simple_bool_error_request(kSecXPCOpIsThisDeviceLastBackup, error);
1786 CFBooleanRef SOSCCPeersHaveViewsEnabled(CFArrayRef viewNames, CFErrorRef *error) {
1787 secnotice("view-enabled", "enter SOSCCPeersHaveViewsEnabled");
1788 sec_trace_enter_api(NULL);
1789 sec_trace_return_api(CFBooleanRef, ^{
1790 do_if_registered(soscc_SOSCCPeersHaveViewsEnabled, viewNames, error);
1792 return cfarray_to_cfboolean_error_request(kSecXPCOpPeersHaveViewsEnabled, viewNames, error);
1793 }, CFSTR("return=%@"))
1796 bool SOSCCMessageFromPeerIsPending(SOSPeerInfoRef peer, CFErrorRef *error) {
1797 secnotice("pending-check", "enter SOSCCMessageFromPeerIsPending");
1799 sec_trace_return_bool_api(^{
1800 do_if_registered(soscc_SOSCCMessageFromPeerIsPending, peer, error);
1802 return peer_info_to_bool_error_request(kSecXPCOpMessageFromPeerIsPending, peer, error);
1807 bool SOSCCSendToPeerIsPending(SOSPeerInfoRef peer, CFErrorRef *error) {
1808 sec_trace_return_bool_api(^{
1809 do_if_registered(soscc_SOSCCSendToPeerIsPending, peer, error);
1811 return peer_info_to_bool_error_request(kSecXPCOpSendToPeerIsPending, peer, error);
1816 * SecSOSStatus interfaces
1819 @interface SecSOSStatus : NSObject {
1820 NSXPCConnection* _connection;
1822 @property NSXPCConnection *connection;
1825 @implementation SecSOSStatus
1826 @synthesize connection = _connection;
1828 - (instancetype) initWithEndpoint:(xpc_endpoint_t)endpoint
1830 if ((self = [super init]) == NULL)
1833 NSXPCInterface *interface = [NSXPCInterface interfaceWithProtocol:@protocol(SOSControlProtocol)];
1834 _SOSControlSetupInterface(interface);
1835 NSXPCListenerEndpoint *listenerEndpoint = [[NSXPCListenerEndpoint alloc] init];
1837 [listenerEndpoint _setEndpoint:endpoint];
1839 self.connection = [[NSXPCConnection alloc] initWithListenerEndpoint:listenerEndpoint];
1840 if (self.connection == NULL)
1843 self.connection.remoteObjectInterface = interface;
1845 [self.connection resume];
1852 static id<SOSControlProtocol>
1853 SOSCCGetStatusObject(CFErrorRef *error)
1855 if (gSecurityd && gSecurityd->soscc_status)
1856 return (__bridge id<SOSControlProtocol>)gSecurityd->soscc_status();
1858 static SecSOSStatus *control;
1859 static dispatch_once_t onceToken;
1860 dispatch_once(&onceToken, ^{
1861 xpc_endpoint_t endpoint = _SecSecuritydCopySOSStatusEndpoint(error);
1862 if (endpoint == NULL)
1865 control = [[SecSOSStatus alloc] initWithEndpoint:endpoint];
1867 return control.connection.remoteObjectProxy;
1871 SOSCCAccountGetPublicKey(void (^reply)(BOOL trusted, NSData *data, NSError *error))
1873 CFErrorRef error = NULL;
1874 id<SOSControlProtocol> status = SOSCCGetStatusObject(&error);
1875 if (status == NULL) {
1876 reply(false, NULL, (__bridge NSError *)error);
1877 CFReleaseNull(error);
1881 [status userPublicKey:reply];
1885 SOSCCAccountGetAccountPrivateCredential(void (^complete)(NSData *data, NSError *error))
1887 CFErrorRef error = NULL;
1888 id<SOSControlProtocol> status = SOSCCGetStatusObject(&error);
1889 if (status == NULL) {
1890 complete(NULL, (__bridge NSError *)error);
1891 CFReleaseNull(error);
1895 [status validatedStashedAccountCredential:complete];
1899 SOSCCAccountGetKeyCircleGeneration(void (^reply)(NSData *data, NSError *error))
1901 SOSCCAccountGetPublicKey(^(BOOL __unused trusted, NSData *data, NSError *error){
1905 NSMutableData *digest = [NSMutableData dataWithLength:CCSHA256_OUTPUT_SIZE];
1906 ccdigest(ccsha256_di(), [data length], [data bytes], [digest mutableBytes]);
1907 reply(digest, error);