]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/pkcs12.h.in
Header file cleanup for C++20 header-units
[thirdparty/openssl.git] / include / openssl / pkcs12.h.in
CommitLineData
0f113f3e 1/*
add33927
MC
2 * {- join("\n * ", @autowarntext) -}
3 *
aff636a4 4 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
8d8c7266 5 *
48f4ad77 6 * Licensed under the Apache License 2.0 (the "License"). You may not use
21dcbebc
RS
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
8d8c7266
DSH
10 */
11
add33927
MC
12{-
13use OpenSSL::stackhash qw(generate_stack_macros);
14-}
15
ae4186b0
DMSP
16#ifndef OPENSSL_PKCS12_H
17# define OPENSSL_PKCS12_H
d86167ec
DMSP
18# pragma once
19
20# include <openssl/macros.h>
936c2b9e 21# ifndef OPENSSL_NO_DEPRECATED_3_0
d86167ec
DMSP
22# define HEADER_PKCS12_H
23# endif
8d8c7266 24
0f113f3e 25# include <openssl/bio.h>
b536880c 26# include <openssl/core.h>
0f113f3e 27# include <openssl/x509.h>
52df25cf 28# include <openssl/pkcs12err.h>
eab9dbbd
NS
29# ifndef OPENSSL_NO_STDIO
30# include <stdio.h>
31# endif
82271cee 32
8d8c7266
DSH
33#ifdef __cplusplus
34extern "C" {
35#endif
36
0f113f3e
MC
37# define PKCS12_KEY_ID 1
38# define PKCS12_IV_ID 2
39# define PKCS12_MAC_ID 3
8d8c7266 40
e84240d4 41/* Default iteration count */
0f113f3e
MC
42# ifndef PKCS12_DEFAULT_ITER
43# define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
44# endif
e84240d4 45
0f113f3e 46# define PKCS12_MAC_KEY_LENGTH 20
8d8c7266 47
0f113f3e 48# define PKCS12_SALT_LEN 8
8d8c7266 49
1194ea8d
AP
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
8d8c7266
DSH
53
54/* MS key usage constants */
55
0f113f3e
MC
56# define KEY_EX 0x10
57# define KEY_SIG 0x80
8d8c7266 58
54c38b7f
DSH
59typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA;
60
61typedef struct PKCS12_st PKCS12;
62
63typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG;
8d8c7266 64
add33927
MC
65{-
66 generate_stack_macros("PKCS12_SAFEBAG");
67-}
01659135 68
54c38b7f 69typedef struct pkcs12_bag_st PKCS12_BAGS;
8d8c7266 70
0f113f3e
MC
71# define PKCS12_ERROR 0
72# define PKCS12_OK 1
8d8c7266 73
ecbe0781 74/* Compatibility macros */
8d8c7266 75
00db8c60 76#ifndef OPENSSL_NO_DEPRECATED_1_1_0
116503cd 77
a40d5949
DSH
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
e8503762
DSH
82# define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert
83# define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl
e8503762
DSH
84# define PKCS12_bag_type PKCS12_SAFEBAG_get_nid
85# define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid
293042c9 86# define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert
425f3300
DSH
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
e8503762 90
116503cd 91#endif
be8e9b39
RL
92#ifndef OPENSSL_NO_DEPRECATED_1_1_0
93OSSL_DEPRECATEDIN_1_1_0 ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag,
94 int attr_nid);
95#endif
28da1455 96
a40d5949 97ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid);
28da1455 98int PKCS12_mac_present(const PKCS12 *p12);
59b4da05
DSH
99void 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);
1e1b48d1 104
28da1455
MC
105const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag,
106 int attr_nid);
107const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag);
108int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag);
109int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag);
c5ec6dcf
JS
110const ASN1_TYPE *PKCS12_SAFEBAG_get0_bag_obj(const PKCS12_SAFEBAG *bag);
111const ASN1_OBJECT *PKCS12_SAFEBAG_get0_bag_type(const PKCS12_SAFEBAG *bag);
1e1b48d1 112
28da1455
MC
113X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag);
114X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag);
115const STACK_OF(PKCS12_SAFEBAG) *
116PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag);
117const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag);
118const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag);
8d8c7266 119
293042c9
DSH
120PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
121PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
c5ec6dcf 122PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_secret(int type, int vtype, const unsigned char *value, int len);
425f3300
DSH
123PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
124PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
125PKCS12_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);
b536880c
JS
131PKCS12_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);
ecbe0781 139
0f113f3e
MC
140PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
141 int nid1, int nid2);
59b4da05 142PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
0f113f3e 143 int passlen);
b536880c
JS
144PKCS8_PRIV_KEY_INFO *PKCS8_decrypt_ex(const X509_SIG *p8, const char *pass,
145 int passlen, OSSL_LIB_CTX *ctx,
146 const char *propq);
28da1455 147PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag,
0f113f3e 148 const char *pass, int passlen);
b536880c
JS
149PKCS8_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);
0f113f3e
MC
153X509_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);
b536880c
JS
156X509_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);
6355d315
DSH
160X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen,
161 PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe);
b536880c
JS
162X509_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);
f2716dad 165PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
ecbe0781 166STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
61f5b6f3 167PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
0f113f3e
MC
168 unsigned char *salt, int saltlen, int iter,
169 STACK_OF(PKCS12_SAFEBAG) *bags);
b536880c
JS
170PKCS7 *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
0f113f3e
MC
175STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
176 int passlen);
ecbe0781
DSH
177
178int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
28da1455 179STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12);
ecbe0781 180
0f113f3e
MC
181int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
182 int namelen);
61f5b6f3 183int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
0f113f3e 184 int namelen);
b799aef8
AP
185int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
186 int namelen);
f2a253e0 187int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
0f113f3e
MC
188 int namelen);
189int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
190 const unsigned char *name, int namelen);
c5ec6dcf
JS
191int PKCS12_add1_attr_by_NID(PKCS12_SAFEBAG *bag, int nid, int type,
192 const unsigned char *bytes, int len);
193int PKCS12_add1_attr_by_txt(PKCS12_SAFEBAG *bag, const char *attrname, int type,
194 const unsigned char *bytes, int len);
8d8c7266 195int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
b2e57e09
MC
196ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs,
197 int attr_nid);
8d8c7266 198char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
28da1455
MC
199const STACK_OF(X509_ATTRIBUTE) *
200PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag);
59b4da05
DSH
201unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
202 const char *pass, int passlen,
203 const unsigned char *in, int inlen,
0f113f3e
MC
204 unsigned char **data, int *datalen,
205 int en_de);
b536880c
JS
206unsigned 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);
59b4da05 212void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
0f113f3e 213 const char *pass, int passlen,
59b4da05 214 const ASN1_OCTET_STRING *oct, int zbuf);
b536880c
JS
215void *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);
0f113f3e
MC
220ASN1_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);
b536880c
JS
224ASN1_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);
8d8c7266 230PKCS12 *PKCS12_init(int mode);
b536880c
JS
231PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq);
232
61f5b6f3 233int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
0f113f3e
MC
234 int saltlen, int id, int iter, int n,
235 unsigned char *out, const EVP_MD *md_type);
b536880c
JS
236int 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);
0f113f3e
MC
240int 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);
b536880c
JS
243int 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);
9e6b2f54
AP
247int 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);
b536880c
JS
250int 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
2bd83ca1 255int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
0f113f3e
MC
256 ASN1_TYPE *param, const EVP_CIPHER *cipher,
257 const EVP_MD *md_type, int en_de);
b536880c
JS
258int 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);
69cbf468 262int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
0f113f3e 263 unsigned char *mac, unsigned int *maclen);
61f5b6f3
BL
264int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
265int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
0f113f3e
MC
266 unsigned char *salt, int saltlen, int iter,
267 const EVP_MD *md_type);
69cbf468 268int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
0f113f3e
MC
269 int saltlen, const EVP_MD *md_type);
270unsigned char *OPENSSL_asc2uni(const char *asc, int asclen,
271 unsigned char **uni, int *unilen);
9e6b2f54
AP
272char *OPENSSL_uni2asc(const unsigned char *uni, int unilen);
273unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
274 unsigned char **uni, int *unilen);
275char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen);
9d6b1ce6
DSH
276
277DECLARE_ASN1_FUNCTIONS(PKCS12)
278DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
279DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
280DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
281
ecbe0781
DSH
282DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
283DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
284
8d8c7266 285void PKCS12_PBE_add(void);
61f5b6f3 286int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
0f113f3e 287 STACK_OF(X509) **ca);
02e112a8
F
288PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
289 X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
82af00fb 290 int iter, int mac_iter, int keytype);
b536880c
JS
291PKCS12 *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);
9a48b07e
DSH
295
296PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
0f113f3e
MC
297PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
298 EVP_PKEY *key, int key_usage, int iter,
82af00fb 299 int key_nid, const char *pass);
b536880c
JS
300PKCS12_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
c5ec6dcf
JS
305PKCS12_SAFEBAG *PKCS12_add_secret(STACK_OF(PKCS12_SAFEBAG) **pbags,
306 int nid_type, const unsigned char *value, int len);
9a48b07e 307int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
82af00fb 308 int safe_nid, int iter, const char *pass);
b536880c
JS
309int 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
9a48b07e 313PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
b536880c
JS
314PKCS12 *PKCS12_add_safes_ex(STACK_OF(PKCS7) *safes, int p7_nid,
315 OSSL_LIB_CTX *ctx, const char *propq);
9a48b07e 316
9fdcc21f 317int i2d_PKCS12_bio(BIO *bp, const PKCS12 *p12);
739fe504 318# ifndef OPENSSL_NO_STDIO
9fdcc21f 319int i2d_PKCS12_fp(FILE *fp, const PKCS12 *p12);
739fe504 320# endif
8d8c7266 321PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
739fe504 322# ifndef OPENSSL_NO_STDIO
8d8c7266 323PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
739fe504 324# endif
049f5bbc 325int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
8d8c7266 326
0cd0a820 327# ifdef __cplusplus
8d8c7266 328}
0cd0a820 329# endif
8d8c7266 330#endif