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