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