Debian Codegraph @

crt/aws-c-io/include/aws/io/private/pki_utils.h

raw symbols SCIP
1 #ifndef AWS_IO_PKI_UTILS_H
2 #define AWS_IO_PKI_UTILS_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7 #include <aws/io/io.h>
8
9 #ifdef _WIN32
10 /* It's ok to include external headers because this is a PRIVATE header file
11 * (it is usually a crime to include windows.h from header file) */
12 # define NOMINMAX
13 # define NOCRYPT
14 # include <windows.h>
15
16 /* Note: we need defs for crypto definitions, we can get them from windows.h, but
17 * with lean an mean on they will be missing from windows.h.
18 * So instead lets have a proper dependency on the header that defines them, and force them
19 * to not be included in windows.h.
20 */
21 # include <wincrypt.h>
22 #endif /* _WIN32 */
23
24 #ifdef AWS_OS_APPLE
25 /* It's ok to include external headers because this is a PRIVATE header file */
26 # include <CoreFoundation/CFArray.h>
27 # include <Security/Security.h>
28 #endif /* AWS_OS_APPLE */
29
30 struct aws_secitem_options;
31 struct aws_string;
32
33 AWS_EXTERN_C_BEGIN
34
35 /**
36 * Returns the path to the directory and file, respectively, which holds the
37 * SSL certificate trust store on the system.
38 */
39 AWS_IO_API const char *aws_determine_default_pki_dir(void);
40 AWS_IO_API const char *aws_determine_default_pki_ca_file(void);
41
42 #ifdef AWS_OS_APPLE
43 /**
44 * Imports a PEM armored PKCS#7 public/private key pair
45 * into identity for use with SecurityFramework.
46 */
47 int aws_import_public_and_private_keys_to_identity(
48 struct aws_allocator *alloc,
49 CFAllocatorRef cf_alloc,
50 const struct aws_byte_cursor *public_cert_chain,
51 const struct aws_byte_cursor *private_key,
52 CFArrayRef *identity,
53 const struct aws_string *keychain_path);
54
55 /**
56 * Imports a PKCS#12 file into identity for use with
57 * SecurityFramework
58 */
59 int aws_import_pkcs12_to_identity(
60 CFAllocatorRef cf_alloc,
61 const struct aws_byte_cursor *pkcs12_cursor,
62 const struct aws_byte_cursor *password,
63 CFArrayRef *identity);
64
65 /**
66 * Loads PRM armored PKCS#7 certificates into certs
67 * for use with custom CA.
68 */
69 int aws_import_trusted_certificates(
70 struct aws_allocator *alloc,
71 CFAllocatorRef cf_alloc,
72 const struct aws_byte_cursor *certificates_blob,
73 CFArrayRef *certs);
74
75 /**
76 * Imports a PEM armored PKCS#7 public/private key pair
77 * into protected data keychain for use with Apple Network Framework.
78 * Currently only implemented for iOS.
79 */
80 int aws_secitem_import_cert_and_key(
81 struct aws_allocator *alloc,
82 CFAllocatorRef cf_alloc,
83 const struct aws_byte_cursor *public_cert_chain,
84 const struct aws_byte_cursor *private_key,
85 sec_identity_t *secitem_identity,
86 const struct aws_secitem_options *secitem_options);
87
88 /**
89 * Imports a PKCS#12 file into protected data keychain for use with
90 * Apple Network Framework.
91 * Currently only implemented for iOS.
92 */
93 int aws_secitem_import_pkcs12(
94 CFAllocatorRef cf_alloc,
95 const struct aws_byte_cursor *pkcs12_cursor,
96 const struct aws_byte_cursor *password,
97 sec_identity_t *out_identity);
98
99 #endif /* AWS_OS_APPLE */
100
101 #ifdef _WIN32
102
103 /**
104 * Returns AWS_OP_SUCCESS if we were able to successfully load the certificate and cert_store.
105 *
106 * Returns AWS_OP_ERR otherwise.
107 */
108 AWS_IO_API int aws_load_cert_from_system_cert_store(
109 const char *cert_path,
110 HCERTSTORE *cert_store,
111 PCCERT_CONTEXT *certs);
112
113 /**
114 * Imports a PEM armored PKCS#7 blob into an ephemeral certificate store for use
115 * as a custom CA.
116 */
117 AWS_IO_API int aws_import_trusted_certificates(
118 struct aws_allocator *alloc,
119 const struct aws_byte_cursor *certificates_blob,
120 HCERTSTORE *cert_store);
121
122 /**
123 * Closes a cert store that was opened by aws_is_system_cert_store, aws_import_trusted_certificates,
124 * or aws_import_key_pair_to_cert_context.
125 */
126 AWS_IO_API void aws_close_cert_store(HCERTSTORE cert_store);
127
128 /**
129 * Imports a PEM armored PKCS#7 public/private key pair into certs for use as a certificate with SSPI.
130 */
131 AWS_IO_API int aws_import_key_pair_to_cert_context(
132 struct aws_allocator *alloc,
133 const struct aws_byte_cursor *public_cert_chain,
134 const struct aws_byte_cursor *private_key,
135 bool is_client_mode,
136 HCERTSTORE *cert_store,
137 PCCERT_CONTEXT *certs,
138 HCRYPTPROV *crypto_provider,
139 HCRYPTKEY *private_key_handle,
140 bool *tls13_disabled);
141
142 #endif /* _WIN32 */
143
144 AWS_EXTERN_C_END
145
146 #endif /* AWS_IO_PKI_UTILS_H */