2 * Copyright (c) 2013-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 @header SecKeybagSupport.h - The thing that does the stuff with the gibli.
28 #ifndef _SECURITYD_SECKEYBAGSUPPORT_H_
29 #define _SECURITYD_SECKEYBAGSUPPORT_H_
31 #include <CoreFoundation/CoreFoundation.h>
32 #include "utilities/SecAKSWrappers.h"
33 #include <libaks_acl_cf_keys.h>
34 #include <TargetConditionals.h>
37 // Use keystore (real or mock) on all platforms, except bridge
38 #define USE_KEYSTORE !TARGET_OS_BRIDGE
41 #if __has_include(<Kernel/IOKit/crypto/AppleKeyStoreDefs.h>)
42 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h>
46 #include <Security/SecAccessControlPriv.h>
47 #endif /* USE_KEYSTORE */
52 /* KEYBAG_NONE is private to security and have special meaning.
53 They should not collide with AppleKeyStore constants, but are only referenced
56 #define KEYBAG_NONE (-1) /* Set q_keybag to KEYBAG_NONE to obtain cleartext data. */
57 #define KEYBAG_DEVICE (g_keychain_keybag) /* actual keybag used to encrypt items */
58 extern keybag_handle_t g_keychain_keybag
;
62 bool ks_crypt(CFTypeRef operation
, keybag_handle_t keybag
,
63 keyclass_t keyclass
, uint32_t textLength
, const uint8_t *source
, keyclass_t
*actual_class
,
64 CFMutableDataRef dest
, CFErrorRef
*error
);
66 bool ks_encrypt_acl(keybag_handle_t keybag
, keyclass_t keyclass
, uint32_t textLength
, const uint8_t *source
,
67 CFMutableDataRef dest
, CFDataRef auth_data
, CFDataRef acm_context
,
68 SecAccessControlRef access_control
, CFErrorRef
*error
);
69 bool ks_decrypt_acl(aks_ref_key_t ref_key
, CFDataRef encrypted_data
, CFMutableDataRef dest
,
70 CFDataRef acm_context
, CFDataRef caller_access_groups
,
71 SecAccessControlRef access_control
, CFErrorRef
*error
);
72 bool ks_delete_acl(aks_ref_key_t ref_key
, CFDataRef encrypted_data
,
73 CFDataRef acm_context
, CFDataRef caller_access_groups
,
74 SecAccessControlRef access_control
, CFErrorRef
*error
);
75 const void* ks_ref_key_get_external_data(keybag_handle_t keybag
, CFDataRef key_data
,
76 aks_ref_key_t
*ref_key
, size_t *external_data_len
, CFErrorRef
*error
);
77 bool ks_separate_data_and_key(CFDictionaryRef blob_dict
, CFDataRef
*ed_data
, CFDataRef
*key_data
);
79 bool ks_access_control_needed_error(CFErrorRef
*error
, CFDataRef access_control_data
, CFTypeRef operation
);
80 bool create_cferror_from_aks(int aks_return
, CFTypeRef operation
, keybag_handle_t keybag
, keyclass_t keyclass
, CFDataRef access_control_data
, CFDataRef acm_context_data
, CFErrorRef
*error
);
82 bool ks_open_keybag(CFDataRef keybag
, CFDataRef password
, keybag_handle_t
*handle
, CFErrorRef
*error
);
83 bool ks_close_keybag(keybag_handle_t keybag
, CFErrorRef
*error
);
87 #endif /* _SECURITYD_SECKEYBAGSUPPORT_H_ */