+ case sec_item_copy_parent_certificates_id:
+ {
+ CFArrayRef results = NULL;
+ if(EntitlementPresentAndTrue(operation, client.task, kSecEntitlementPrivateCertificateAllAccess, &error)) {
+ CFDataRef issuer = SecXPCDictionaryCopyData(event, kSecXPCKeyNormalizedIssuer, &error);
+ CFArrayRef accessGroups = SecXPCDictionaryCopyArray(event, kSecXPCKeyAccessGroups, &error);
+ if (issuer && accessGroups) {
+ results = _SecItemCopyParentCertificates(issuer, accessGroups, &error);
+ }
+ CFReleaseNull(issuer);
+ CFReleaseNull(accessGroups);
+ }
+ SecXPCDictionarySetPListOptional(replyMessage, kSecXPCKeyResult, results, &error);
+ CFReleaseNull(results);
+ }
+ break;
+ case sec_item_certificate_exists_id:
+ {
+ bool result = false;
+ if(EntitlementPresentAndTrue(operation, client.task, kSecEntitlementPrivateCertificateAllAccess, &error)) {
+ CFDataRef issuer = SecXPCDictionaryCopyData(event, kSecXPCKeyNormalizedIssuer, &error);
+ CFDataRef serialNum = SecXPCDictionaryCopyData(event, kSecXPCKeySerialNumber, &error);
+ CFArrayRef accessGroups = SecXPCDictionaryCopyArray(event, kSecXPCKeyAccessGroups, &error);
+ if (issuer && serialNum && accessGroups) {
+ result = _SecItemCertificateExists(issuer, serialNum, accessGroups, &error);
+ }
+ CFReleaseNull(issuer);
+ CFReleaseNull(serialNum);
+ CFReleaseNull(accessGroups);
+ }
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, result);
+ }
+ break;
+ case kSecXPCOpCKKSEndpoint: {
+ if(EntitlementPresentAndTrue(operation, client.task, kSecEntitlementPrivateCKKS, &error)) {
+ xpc_endpoint_t endpoint = SecServerCreateCKKSEndpoint();
+ if (endpoint) {
+ xpc_dictionary_set_value(replyMessage, kSecXPCKeyEndpoint, endpoint);
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, true);
+ xpc_release(endpoint);
+ } else {
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, false);
+ }
+ }
+ break;
+ }
+ case kSecXPCOpSOSEndpoint: {
+ if(EntitlementPresentAndTrue(operation, client.task, kSecEntitlementKeychainCloudCircle, &error)) {
+ xpc_endpoint_t endpoint = SOSCCCreateSOSEndpoint_server(&error);
+ if (endpoint) {
+ xpc_dictionary_set_value(replyMessage, kSecXPCKeyEndpoint, endpoint);
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, true);
+ xpc_release(endpoint);
+ } else {
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, false);
+ }
+ }
+ break;
+ }
+ case kSecXPCOpSecuritydXPCServerEndpoint: {
+ xpc_endpoint_t endpoint = SecCreateSecuritydXPCServerEndpoint(&error);
+ if (endpoint) {
+ xpc_dictionary_set_value(replyMessage, kSecXPCKeyEndpoint, endpoint);
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, true);
+ xpc_release(endpoint);
+ } else {
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, false);
+ }
+ break;
+ }
+ case kSecXPCOpBackupKeybagAdd: {
+ if (EntitlementPresentAndTrue(operation, client.task, kSecEntitlementBackupTableOperations, &error)) {
+ CFDataRef keybag = NULL, passcode = NULL;
+ if (SecXPCDictionaryCopyDataOptional(event, kSecXPCKeyUserPassword, &passcode, &error)) {
+ CFDataRef identifier = NULL;
+ CFDataRef pathinfo = NULL; // really a CFURLRef
+ bool added = _SecServerBackupKeybagAdd(&client, passcode, &identifier, &pathinfo, &error);
+ if (added) {
+ added &= SecXPCDictionarySetDataOptional(replyMessage, kSecXPCKeyBackupKeybagIdentifier, identifier, &error);
+ added &= SecXPCDictionarySetDataOptional(replyMessage, kSecXPCKeyBackupKeybagPath, pathinfo, &error);
+ SecXPCDictionarySetBool(replyMessage, kSecXPCKeyResult, added, NULL);
+ } else {
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, false);
+ }
+ }
+ CFReleaseSafe(passcode);
+ CFReleaseSafe(keybag);
+ }
+ break;
+ }
+ case kSecXPCOpBackupKeybagDelete: {
+ // >>>
+ if (EntitlementPresentAndTrue(operation, client.task, kSecEntitlementBackupTableOperations, &error)) {
+ bool deleted = false;
+ CFDictionaryRef query = SecXPCDictionaryCopyDictionary(event, kSecXPCKeyQuery, &error);
+ if (query) {
+ CFTypeRef matchLimit = CFDictionaryGetValue(query, kSecMatchLimit);
+ bool deleteAll = matchLimit && CFEqualSafe(matchLimit, kSecMatchLimitAll);
+
+ if (deleteAll && !EntitlementPresentAndTrue(operation, client.task, kSecEntitlementBackupTableOperationsDeleteAll, &error)) {
+ // require special entitlement to delete all backup keybags
+ } else {
+ CFMutableDictionaryRef attributes = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, query);
+ CFStringRef requestedAgrp = CFDictionaryGetValue(attributes, kSecAttrAccessGroup);
+ CFStringRef resolvedAgrp = NULL;
+ if (client.musr) {
+ CFDictionarySetValue(attributes, kSecAttrMultiUser, client.musr);
+ }
+ if (extractAccessGroup(&client, requestedAgrp, &resolvedAgrp, &error)) {
+ if (resolvedAgrp) {
+ CFDictionarySetValue(attributes, kSecAttrAccessGroup, resolvedAgrp);
+ }
+ deleted = _SecServerBackupKeybagDelete(attributes, deleteAll, &error);
+ }
+ CFReleaseNull(resolvedAgrp);
+ CFReleaseNull(attributes);
+ }
+ }
+ xpc_dictionary_set_bool(replyMessage, kSecXPCKeyResult, deleted);
+ CFReleaseNull(query);
+ }
+ break;
+ }