1 | /*
|
---|
2 | * {- join("\n * ", @autowarntext) -}
|
---|
3 | *
|
---|
4 | * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
7 | * this file except in compliance with the License. You can obtain a copy
|
---|
8 | * in the file LICENSE in the source distribution or at
|
---|
9 | * https://www.openssl.org/source/license.html
|
---|
10 | */
|
---|
11 |
|
---|
12 | {-
|
---|
13 | use OpenSSL::stackhash qw(generate_stack_macros);
|
---|
14 | -}
|
---|
15 |
|
---|
16 | #ifndef OPENSSL_PKCS12_H
|
---|
17 | # define OPENSSL_PKCS12_H
|
---|
18 | # pragma once
|
---|
19 |
|
---|
20 | # include <openssl/macros.h>
|
---|
21 | # ifndef OPENSSL_NO_DEPRECATED_3_0
|
---|
22 | # define HEADER_PKCS12_H
|
---|
23 | # endif
|
---|
24 |
|
---|
25 | # include <openssl/bio.h>
|
---|
26 | # include <openssl/core.h>
|
---|
27 | # include <openssl/x509.h>
|
---|
28 | # include <openssl/pkcs12err.h>
|
---|
29 |
|
---|
30 | #ifdef __cplusplus
|
---|
31 | extern "C" {
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | # define PKCS12_KEY_ID 1
|
---|
35 | # define PKCS12_IV_ID 2
|
---|
36 | # define PKCS12_MAC_ID 3
|
---|
37 |
|
---|
38 | /* Default iteration count */
|
---|
39 | # ifndef PKCS12_DEFAULT_ITER
|
---|
40 | # define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
|
---|
41 | # endif
|
---|
42 |
|
---|
43 | # define PKCS12_MAC_KEY_LENGTH 20
|
---|
44 |
|
---|
45 | # define PKCS12_SALT_LEN 8
|
---|
46 |
|
---|
47 | /* It's not clear if these are actually needed... */
|
---|
48 | # define PKCS12_key_gen PKCS12_key_gen_utf8
|
---|
49 | # define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8
|
---|
50 |
|
---|
51 | /* MS key usage constants */
|
---|
52 |
|
---|
53 | # define KEY_EX 0x10
|
---|
54 | # define KEY_SIG 0x80
|
---|
55 |
|
---|
56 | typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA;
|
---|
57 |
|
---|
58 | typedef struct PKCS12_st PKCS12;
|
---|
59 |
|
---|
60 | typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG;
|
---|
61 |
|
---|
62 | {-
|
---|
63 | generate_stack_macros("PKCS12_SAFEBAG");
|
---|
64 | -}
|
---|
65 |
|
---|
66 | typedef struct pkcs12_bag_st PKCS12_BAGS;
|
---|
67 |
|
---|
68 | # define PKCS12_ERROR 0
|
---|
69 | # define PKCS12_OK 1
|
---|
70 |
|
---|
71 | /* Compatibility macros */
|
---|
72 |
|
---|
73 | #ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
---|
74 |
|
---|
75 | # define M_PKCS12_bag_type PKCS12_bag_type
|
---|
76 | # define M_PKCS12_cert_bag_type PKCS12_cert_bag_type
|
---|
77 | # define M_PKCS12_crl_bag_type PKCS12_cert_bag_type
|
---|
78 |
|
---|
79 | # define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert
|
---|
80 | # define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl
|
---|
81 | # define PKCS12_bag_type PKCS12_SAFEBAG_get_nid
|
---|
82 | # define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid
|
---|
83 | # define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert
|
---|
84 | # define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl
|
---|
85 | # define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf
|
---|
86 | # define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt
|
---|
87 |
|
---|
88 | #endif
|
---|
89 | #ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
---|
90 | OSSL_DEPRECATEDIN_1_1_0 ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag,
|
---|
91 | int attr_nid);
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid);
|
---|
95 | int PKCS12_mac_present(const PKCS12 *p12);
|
---|
96 | void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
|
---|
97 | const X509_ALGOR **pmacalg,
|
---|
98 | const ASN1_OCTET_STRING **psalt,
|
---|
99 | const ASN1_INTEGER **piter,
|
---|
100 | const PKCS12 *p12);
|
---|
101 |
|
---|
102 | const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag,
|
---|
103 | int attr_nid);
|
---|
104 | const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag);
|
---|
105 | int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag);
|
---|
106 | int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag);
|
---|
107 | const ASN1_TYPE *PKCS12_SAFEBAG_get0_bag_obj(const PKCS12_SAFEBAG *bag);
|
---|
108 | const ASN1_OBJECT *PKCS12_SAFEBAG_get0_bag_type(const PKCS12_SAFEBAG *bag);
|
---|
109 |
|
---|
110 | X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag);
|
---|
111 | X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag);
|
---|
112 | const STACK_OF(PKCS12_SAFEBAG) *
|
---|
113 | PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag);
|
---|
114 | const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag);
|
---|
115 | const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag);
|
---|
116 |
|
---|
117 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
|
---|
118 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
|
---|
119 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_secret(int type, int vtype, const unsigned char *value, int len);
|
---|
120 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
|
---|
121 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
|
---|
122 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
|
---|
123 | const char *pass,
|
---|
124 | int passlen,
|
---|
125 | unsigned char *salt,
|
---|
126 | int saltlen, int iter,
|
---|
127 | PKCS8_PRIV_KEY_INFO *p8inf);
|
---|
128 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt_ex(int pbe_nid,
|
---|
129 | const char *pass,
|
---|
130 | int passlen,
|
---|
131 | unsigned char *salt,
|
---|
132 | int saltlen, int iter,
|
---|
133 | PKCS8_PRIV_KEY_INFO *p8inf,
|
---|
134 | OSSL_LIB_CTX *ctx,
|
---|
135 | const char *propq);
|
---|
136 |
|
---|
137 | PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
|
---|
138 | int nid1, int nid2);
|
---|
139 | PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
|
---|
140 | int passlen);
|
---|
141 | PKCS8_PRIV_KEY_INFO *PKCS8_decrypt_ex(const X509_SIG *p8, const char *pass,
|
---|
142 | int passlen, OSSL_LIB_CTX *ctx,
|
---|
143 | const char *propq);
|
---|
144 | PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag,
|
---|
145 | const char *pass, int passlen);
|
---|
146 | PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey_ex(const PKCS12_SAFEBAG *bag,
|
---|
147 | const char *pass, int passlen,
|
---|
148 | OSSL_LIB_CTX *ctx,
|
---|
149 | const char *propq);
|
---|
150 | X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
|
---|
151 | const char *pass, int passlen, unsigned char *salt,
|
---|
152 | int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8);
|
---|
153 | X509_SIG *PKCS8_encrypt_ex(int pbe_nid, const EVP_CIPHER *cipher,
|
---|
154 | const char *pass, int passlen, unsigned char *salt,
|
---|
155 | int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8,
|
---|
156 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
157 | X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen,
|
---|
158 | PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe);
|
---|
159 | X509_SIG *PKCS8_set0_pbe_ex(const char *pass, int passlen,
|
---|
160 | PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe,
|
---|
161 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
162 | PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
|
---|
163 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
|
---|
164 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
|
---|
165 | unsigned char *salt, int saltlen, int iter,
|
---|
166 | STACK_OF(PKCS12_SAFEBAG) *bags);
|
---|
167 | PKCS7 *PKCS12_pack_p7encdata_ex(int pbe_nid, const char *pass, int passlen,
|
---|
168 | unsigned char *salt, int saltlen, int iter,
|
---|
169 | STACK_OF(PKCS12_SAFEBAG) *bags,
|
---|
170 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
171 |
|
---|
172 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
|
---|
173 | int passlen);
|
---|
174 |
|
---|
175 | int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
|
---|
176 | STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12);
|
---|
177 |
|
---|
178 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
|
---|
179 | int namelen);
|
---|
180 | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
|
---|
181 | int namelen);
|
---|
182 | int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
|
---|
183 | int namelen);
|
---|
184 | int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
|
---|
185 | int namelen);
|
---|
186 | int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
|
---|
187 | const unsigned char *name, int namelen);
|
---|
188 | int PKCS12_add1_attr_by_NID(PKCS12_SAFEBAG *bag, int nid, int type,
|
---|
189 | const unsigned char *bytes, int len);
|
---|
190 | int PKCS12_add1_attr_by_txt(PKCS12_SAFEBAG *bag, const char *attrname, int type,
|
---|
191 | const unsigned char *bytes, int len);
|
---|
192 | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
|
---|
193 | ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs,
|
---|
194 | int attr_nid);
|
---|
195 | char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
|
---|
196 | const STACK_OF(X509_ATTRIBUTE) *
|
---|
197 | PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag);
|
---|
198 | unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
|
---|
199 | const char *pass, int passlen,
|
---|
200 | const unsigned char *in, int inlen,
|
---|
201 | unsigned char **data, int *datalen,
|
---|
202 | int en_de);
|
---|
203 | unsigned char *PKCS12_pbe_crypt_ex(const X509_ALGOR *algor,
|
---|
204 | const char *pass, int passlen,
|
---|
205 | const unsigned char *in, int inlen,
|
---|
206 | unsigned char **data, int *datalen,
|
---|
207 | int en_de, OSSL_LIB_CTX *libctx,
|
---|
208 | const char *propq);
|
---|
209 | void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
|
---|
210 | const char *pass, int passlen,
|
---|
211 | const ASN1_OCTET_STRING *oct, int zbuf);
|
---|
212 | void *PKCS12_item_decrypt_d2i_ex(const X509_ALGOR *algor, const ASN1_ITEM *it,
|
---|
213 | const char *pass, int passlen,
|
---|
214 | const ASN1_OCTET_STRING *oct, int zbuf,
|
---|
215 | OSSL_LIB_CTX *libctx,
|
---|
216 | const char *propq);
|
---|
217 | ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor,
|
---|
218 | const ASN1_ITEM *it,
|
---|
219 | const char *pass, int passlen,
|
---|
220 | void *obj, int zbuf);
|
---|
221 | ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt_ex(X509_ALGOR *algor,
|
---|
222 | const ASN1_ITEM *it,
|
---|
223 | const char *pass, int passlen,
|
---|
224 | void *obj, int zbuf,
|
---|
225 | OSSL_LIB_CTX *ctx,
|
---|
226 | const char *propq);
|
---|
227 | PKCS12 *PKCS12_init(int mode);
|
---|
228 | PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq);
|
---|
229 |
|
---|
230 | int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
|
---|
231 | int saltlen, int id, int iter, int n,
|
---|
232 | unsigned char *out, const EVP_MD *md_type);
|
---|
233 | int PKCS12_key_gen_asc_ex(const char *pass, int passlen, unsigned char *salt,
|
---|
234 | int saltlen, int id, int iter, int n,
|
---|
235 | unsigned char *out, const EVP_MD *md_type,
|
---|
236 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
237 | int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
|
---|
238 | int saltlen, int id, int iter, int n,
|
---|
239 | unsigned char *out, const EVP_MD *md_type);
|
---|
240 | int PKCS12_key_gen_uni_ex(unsigned char *pass, int passlen, unsigned char *salt,
|
---|
241 | int saltlen, int id, int iter, int n,
|
---|
242 | unsigned char *out, const EVP_MD *md_type,
|
---|
243 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
244 | int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
|
---|
245 | int saltlen, int id, int iter, int n,
|
---|
246 | unsigned char *out, const EVP_MD *md_type);
|
---|
247 | int PKCS12_key_gen_utf8_ex(const char *pass, int passlen, unsigned char *salt,
|
---|
248 | int saltlen, int id, int iter, int n,
|
---|
249 | unsigned char *out, const EVP_MD *md_type,
|
---|
250 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
251 |
|
---|
252 | int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
|
---|
253 | ASN1_TYPE *param, const EVP_CIPHER *cipher,
|
---|
254 | const EVP_MD *md_type, int en_de);
|
---|
255 | int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
|
---|
256 | ASN1_TYPE *param, const EVP_CIPHER *cipher,
|
---|
257 | const EVP_MD *md_type, int en_de,
|
---|
258 | OSSL_LIB_CTX *libctx, const char *propq);
|
---|
259 | int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
|
---|
260 | unsigned char *mac, unsigned int *maclen);
|
---|
261 | int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
|
---|
262 | int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
|
---|
263 | unsigned char *salt, int saltlen, int iter,
|
---|
264 | const EVP_MD *md_type);
|
---|
265 | int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
|
---|
266 | int saltlen, const EVP_MD *md_type);
|
---|
267 | unsigned char *OPENSSL_asc2uni(const char *asc, int asclen,
|
---|
268 | unsigned char **uni, int *unilen);
|
---|
269 | char *OPENSSL_uni2asc(const unsigned char *uni, int unilen);
|
---|
270 | unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
|
---|
271 | unsigned char **uni, int *unilen);
|
---|
272 | char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen);
|
---|
273 |
|
---|
274 | DECLARE_ASN1_FUNCTIONS(PKCS12)
|
---|
275 | DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
|
---|
276 | DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
|
---|
277 | DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
|
---|
278 |
|
---|
279 | DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
|
---|
280 | DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
|
---|
281 |
|
---|
282 | void PKCS12_PBE_add(void);
|
---|
283 | int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
|
---|
284 | STACK_OF(X509) **ca);
|
---|
285 | PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
|
---|
286 | X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
|
---|
287 | int iter, int mac_iter, int keytype);
|
---|
288 | PKCS12 *PKCS12_create_ex(const char *pass, const char *name, EVP_PKEY *pkey,
|
---|
289 | X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
|
---|
290 | int iter, int mac_iter, int keytype,
|
---|
291 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
292 |
|
---|
293 | PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
|
---|
294 | PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
|
---|
295 | EVP_PKEY *key, int key_usage, int iter,
|
---|
296 | int key_nid, const char *pass);
|
---|
297 | PKCS12_SAFEBAG *PKCS12_add_key_ex(STACK_OF(PKCS12_SAFEBAG) **pbags,
|
---|
298 | EVP_PKEY *key, int key_usage, int iter,
|
---|
299 | int key_nid, const char *pass,
|
---|
300 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
301 |
|
---|
302 | PKCS12_SAFEBAG *PKCS12_add_secret(STACK_OF(PKCS12_SAFEBAG) **pbags,
|
---|
303 | int nid_type, const unsigned char *value, int len);
|
---|
304 | int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
|
---|
305 | int safe_nid, int iter, const char *pass);
|
---|
306 | int PKCS12_add_safe_ex(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
|
---|
307 | int safe_nid, int iter, const char *pass,
|
---|
308 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
309 |
|
---|
310 | PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
|
---|
311 | PKCS12 *PKCS12_add_safes_ex(STACK_OF(PKCS7) *safes, int p7_nid,
|
---|
312 | OSSL_LIB_CTX *ctx, const char *propq);
|
---|
313 |
|
---|
314 | int i2d_PKCS12_bio(BIO *bp, const PKCS12 *p12);
|
---|
315 | # ifndef OPENSSL_NO_STDIO
|
---|
316 | int i2d_PKCS12_fp(FILE *fp, const PKCS12 *p12);
|
---|
317 | # endif
|
---|
318 | PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
|
---|
319 | # ifndef OPENSSL_NO_STDIO
|
---|
320 | PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
|
---|
321 | # endif
|
---|
322 | int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
|
---|
323 |
|
---|
324 | # ifdef __cplusplus
|
---|
325 | }
|
---|
326 | # endif
|
---|
327 | #endif
|
---|