Invoke tear_down when exiting test_encode_tls_sct() prematurely
[openssl.git] / include / openssl / pkcs12.h.in
1 /*
2  * {- join("\n * ", @autowarntext) -}
3  *
4  * Copyright 1999-2020 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/x509.h>
27 # include <openssl/pkcs12err.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 # define PKCS12_KEY_ID   1
34 # define PKCS12_IV_ID    2
35 # define PKCS12_MAC_ID   3
36
37 /* Default iteration count */
38 # ifndef PKCS12_DEFAULT_ITER
39 #  define PKCS12_DEFAULT_ITER     PKCS5_DEFAULT_ITER
40 # endif
41
42 # define PKCS12_MAC_KEY_LENGTH 20
43
44 # define PKCS12_SALT_LEN 8
45
46 /* It's not clear if these are actually needed... */
47 # define PKCS12_key_gen PKCS12_key_gen_utf8
48 # define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8
49
50 /* MS key usage constants */
51
52 # define KEY_EX  0x10
53 # define KEY_SIG 0x80
54
55 typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA;
56
57 typedef struct PKCS12_st PKCS12;
58
59 typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG;
60
61 {-
62     generate_stack_macros("PKCS12_SAFEBAG");
63 -}
64
65 typedef struct pkcs12_bag_st PKCS12_BAGS;
66
67 # define PKCS12_ERROR    0
68 # define PKCS12_OK       1
69
70 /* Compatibility macros */
71
72 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
73
74 # define M_PKCS12_bag_type PKCS12_bag_type
75 # define M_PKCS12_cert_bag_type PKCS12_cert_bag_type
76 # define M_PKCS12_crl_bag_type PKCS12_cert_bag_type
77
78 # define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert
79 # define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl
80 # define PKCS12_bag_type PKCS12_SAFEBAG_get_nid
81 # define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid
82 # define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert
83 # define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl
84 # define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf
85 # define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt
86
87 #endif
88 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
89 OSSL_DEPRECATEDIN_1_1_0 ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag,
90                                                    int attr_nid);
91 #endif
92
93 ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid);
94 int PKCS12_mac_present(const PKCS12 *p12);
95 void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
96                      const X509_ALGOR **pmacalg,
97                      const ASN1_OCTET_STRING **psalt,
98                      const ASN1_INTEGER **piter,
99                      const PKCS12 *p12);
100
101 const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag,
102                                           int attr_nid);
103 const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag);
104 int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag);
105 int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag);
106 const ASN1_TYPE *PKCS12_SAFEBAG_get0_bag_obj(const PKCS12_SAFEBAG *bag);
107 const ASN1_OBJECT *PKCS12_SAFEBAG_get0_bag_type(const PKCS12_SAFEBAG *bag);
108
109 X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag);
110 X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag);
111 const STACK_OF(PKCS12_SAFEBAG) *
112 PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag);
113 const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag);
114 const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag);
115
116 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
117 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
118 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_secret(int type, int vtype, const unsigned char *value, int len);
119 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
120 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
121 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
122                                                     const char *pass,
123                                                     int passlen,
124                                                     unsigned char *salt,
125                                                     int saltlen, int iter,
126                                                     PKCS8_PRIV_KEY_INFO *p8inf);
127
128 PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
129                                          int nid1, int nid2);
130 PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
131                                    int passlen);
132 PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag,
133                                          const char *pass, int passlen);
134 X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
135                         const char *pass, int passlen, unsigned char *salt,
136                         int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8);
137 X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen,
138                         PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe);
139 PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
140 STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
141 PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
142                              unsigned char *salt, int saltlen, int iter,
143                              STACK_OF(PKCS12_SAFEBAG) *bags);
144 STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
145                                                   int passlen);
146
147 int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
148 STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12);
149
150 int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
151                           int namelen);
152 int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
153                                 int namelen);
154 int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
155                                  int namelen);
156 int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
157                            int namelen);
158 int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
159                                 const unsigned char *name, int namelen);
160 int PKCS12_add1_attr_by_NID(PKCS12_SAFEBAG *bag, int nid, int type,
161                             const unsigned char *bytes, int len);
162 int PKCS12_add1_attr_by_txt(PKCS12_SAFEBAG *bag, const char *attrname, int type,
163                             const unsigned char *bytes, int len);
164 int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
165 ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs,
166                                int attr_nid);
167 char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
168 const STACK_OF(X509_ATTRIBUTE) *
169 PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag);
170 unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
171                                 const char *pass, int passlen,
172                                 const unsigned char *in, int inlen,
173                                 unsigned char **data, int *datalen,
174                                 int en_de);
175 void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
176                               const char *pass, int passlen,
177                               const ASN1_OCTET_STRING *oct, int zbuf);
178 ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor,
179                                            const ASN1_ITEM *it,
180                                            const char *pass, int passlen,
181                                            void *obj, int zbuf);
182 PKCS12 *PKCS12_init(int mode);
183 int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
184                        int saltlen, int id, int iter, int n,
185                        unsigned char *out, const EVP_MD *md_type);
186 int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
187                        int saltlen, int id, int iter, int n,
188                        unsigned char *out, const EVP_MD *md_type);
189 int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
190                         int saltlen, int id, int iter, int n,
191                         unsigned char *out, const EVP_MD *md_type);
192 int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
193                         ASN1_TYPE *param, const EVP_CIPHER *cipher,
194                         const EVP_MD *md_type, int en_de);
195 int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
196                    unsigned char *mac, unsigned int *maclen);
197 int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
198 int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
199                    unsigned char *salt, int saltlen, int iter,
200                    const EVP_MD *md_type);
201 int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
202                      int saltlen, const EVP_MD *md_type);
203 unsigned char *OPENSSL_asc2uni(const char *asc, int asclen,
204                                unsigned char **uni, int *unilen);
205 char *OPENSSL_uni2asc(const unsigned char *uni, int unilen);
206 unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
207                                 unsigned char **uni, int *unilen);
208 char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen);
209
210 DECLARE_ASN1_FUNCTIONS(PKCS12)
211 DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
212 DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
213 DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
214
215 DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
216 DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
217
218 void PKCS12_PBE_add(void);
219 int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
220                  STACK_OF(X509) **ca);
221 PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
222                       X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
223                       int iter, int mac_iter, int keytype);
224
225 PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
226 PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
227                                EVP_PKEY *key, int key_usage, int iter,
228                                int key_nid, const char *pass);
229 PKCS12_SAFEBAG *PKCS12_add_secret(STACK_OF(PKCS12_SAFEBAG) **pbags,
230                                   int nid_type, const unsigned char *value, int len);
231 int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
232                     int safe_nid, int iter, const char *pass);
233 PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
234
235 int i2d_PKCS12_bio(BIO *bp, const PKCS12 *p12);
236 # ifndef OPENSSL_NO_STDIO
237 int i2d_PKCS12_fp(FILE *fp, const PKCS12 *p12);
238 # endif
239 PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
240 # ifndef OPENSSL_NO_STDIO
241 PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
242 # endif
243 int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
244
245 # ifdef  __cplusplus
246 }
247 # endif
248 #endif