]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/SecKeybagSupport.h
Security-57740.20.22.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
35 #ifndef USE_KEYSTORE
36 #define USE_KEYSTORE TARGET_HAS_KEYSTORE
37 #endif
38
39 #if USE_KEYSTORE
40 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h>
41 #include <Security/SecAccessControlPriv.h>
42 #endif /* USE_KEYSTORE */
43
44 __BEGIN_DECLS
45
46 #if !USE_KEYSTORE
47 /* TODO: this needs to be available in the sim! */
48 typedef int32_t keyclass_t;
49 typedef int32_t key_handle_t;
50 enum key_classes {
51 key_class_ak = 6,
52 key_class_ck,
53 key_class_dk,
54 key_class_aku,
55 key_class_cku,
56 key_class_dku,
57 key_class_akpu
58 };
59 #endif /* !USE_KEYSTORE */
60
61 /* KEYBAG_NONE is private to security and have special meaning.
62 They should not collide with AppleKeyStore constants, but are only referenced
63 in here.
64 */
65 #define KEYBAG_NONE (-1) /* Set q_keybag to KEYBAG_NONE to obtain cleartext data. */
66 #define KEYBAG_DEVICE (g_keychain_keybag) /* actual keybag used to encrypt items */
67 extern keybag_handle_t g_keychain_keybag;
68
69 bool use_hwaes(void);
70 bool ks_crypt(CFTypeRef operation, keybag_handle_t keybag,
71 keyclass_t keyclass, uint32_t textLength, const uint8_t *source, keyclass_t *actual_class,
72 CFMutableDataRef dest, CFErrorRef *error);
73 #if USE_KEYSTORE
74 bool ks_encrypt_acl(keybag_handle_t keybag, keyclass_t keyclass, uint32_t textLength, const uint8_t *source,
75 CFMutableDataRef dest, CFDataRef auth_data, CFDataRef acm_context,
76 SecAccessControlRef access_control, CFErrorRef *error);
77 bool ks_decrypt_acl(aks_ref_key_t ref_key, CFDataRef encrypted_data, CFMutableDataRef dest,
78 CFDataRef acm_context, CFDataRef caller_access_groups,
79 SecAccessControlRef access_control, CFErrorRef *error);
80 bool ks_delete_acl(aks_ref_key_t ref_key, CFDataRef encrypted_data,
81 CFDataRef acm_context, CFDataRef caller_access_groups,
82 SecAccessControlRef access_control, CFErrorRef *error);
83 const void* ks_ref_key_get_external_data(keybag_handle_t keybag, CFDataRef key_data,
84 aks_ref_key_t *ref_key, size_t *external_data_len, CFErrorRef *error);
85 bool ks_separate_data_and_key(CFDictionaryRef blob_dict, CFDataRef *ed_data, CFDataRef *key_data);
86 #endif
87 bool ks_open_keybag(CFDataRef keybag, CFDataRef password, keybag_handle_t *handle, CFErrorRef *error);
88 bool ks_close_keybag(keybag_handle_t keybag, CFErrorRef *error);
89
90 __END_DECLS
91
92 #endif /* _SECURITYD_SECKEYBAGSUPPORT_H_ */