]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/SecKeybagSupport.h
Security-59306.11.20.tar.gz
[apple/security.git] / OSX / sec / securityd / SecKeybagSupport.h
1 /*
2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*!
25 @header SecKeybagSupport.h - The thing that does the stuff with the gibli.
26 */
27
28 #ifndef _SECURITYD_SECKEYBAGSUPPORT_H_
29 #define _SECURITYD_SECKEYBAGSUPPORT_H_
30
31 #include <CoreFoundation/CoreFoundation.h>
32 #include "utilities/SecAKSWrappers.h"
33 #include <libaks_acl_cf_keys.h>
34 #include <TargetConditionals.h>
35
36 #ifndef USE_KEYSTORE
37 // Use keystore (real or mock) on all platforms, except bridge
38 #define USE_KEYSTORE !TARGET_OS_BRIDGE
39 #endif
40
41 #if __has_include(<Kernel/IOKit/crypto/AppleKeyStoreDefs.h>)
42 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h>
43 #endif
44
45 #if USE_KEYSTORE
46 #include <Security/SecAccessControlPriv.h>
47 #endif /* USE_KEYSTORE */
48
49 __BEGIN_DECLS
50
51
52 /* KEYBAG_NONE is private to security and have special meaning.
53 They should not collide with AppleKeyStore constants, but are only referenced
54 in here.
55 */
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;
59
60 bool use_hwaes(void);
61
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);
65 #if USE_KEYSTORE
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);
78
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);
81 #endif
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);
84
85 __END_DECLS
86
87 #endif /* _SECURITYD_SECKEYBAGSUPPORT_H_ */