jpayne@69
|
1 /*
|
jpayne@69
|
2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * Licensed under the OpenSSL license (the "License"). You may not use
|
jpayne@69
|
5 * this file except in compliance with the License. You can obtain a copy
|
jpayne@69
|
6 * in the file LICENSE in the source distribution or at
|
jpayne@69
|
7 * https://www.openssl.org/source/license.html
|
jpayne@69
|
8 */
|
jpayne@69
|
9
|
jpayne@69
|
10 #ifndef HEADER_PKCS12_H
|
jpayne@69
|
11 # define HEADER_PKCS12_H
|
jpayne@69
|
12
|
jpayne@69
|
13 # include <openssl/bio.h>
|
jpayne@69
|
14 # include <openssl/x509.h>
|
jpayne@69
|
15 # include <openssl/pkcs12err.h>
|
jpayne@69
|
16
|
jpayne@69
|
17 #ifdef __cplusplus
|
jpayne@69
|
18 extern "C" {
|
jpayne@69
|
19 #endif
|
jpayne@69
|
20
|
jpayne@69
|
21 # define PKCS12_KEY_ID 1
|
jpayne@69
|
22 # define PKCS12_IV_ID 2
|
jpayne@69
|
23 # define PKCS12_MAC_ID 3
|
jpayne@69
|
24
|
jpayne@69
|
25 /* Default iteration count */
|
jpayne@69
|
26 # ifndef PKCS12_DEFAULT_ITER
|
jpayne@69
|
27 # define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
|
jpayne@69
|
28 # endif
|
jpayne@69
|
29
|
jpayne@69
|
30 # define PKCS12_MAC_KEY_LENGTH 20
|
jpayne@69
|
31
|
jpayne@69
|
32 # define PKCS12_SALT_LEN 8
|
jpayne@69
|
33
|
jpayne@69
|
34 /* It's not clear if these are actually needed... */
|
jpayne@69
|
35 # define PKCS12_key_gen PKCS12_key_gen_utf8
|
jpayne@69
|
36 # define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8
|
jpayne@69
|
37
|
jpayne@69
|
38 /* MS key usage constants */
|
jpayne@69
|
39
|
jpayne@69
|
40 # define KEY_EX 0x10
|
jpayne@69
|
41 # define KEY_SIG 0x80
|
jpayne@69
|
42
|
jpayne@69
|
43 typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA;
|
jpayne@69
|
44
|
jpayne@69
|
45 typedef struct PKCS12_st PKCS12;
|
jpayne@69
|
46
|
jpayne@69
|
47 typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG;
|
jpayne@69
|
48
|
jpayne@69
|
49 DEFINE_STACK_OF(PKCS12_SAFEBAG)
|
jpayne@69
|
50
|
jpayne@69
|
51 typedef struct pkcs12_bag_st PKCS12_BAGS;
|
jpayne@69
|
52
|
jpayne@69
|
53 # define PKCS12_ERROR 0
|
jpayne@69
|
54 # define PKCS12_OK 1
|
jpayne@69
|
55
|
jpayne@69
|
56 /* Compatibility macros */
|
jpayne@69
|
57
|
jpayne@69
|
58 #if OPENSSL_API_COMPAT < 0x10100000L
|
jpayne@69
|
59
|
jpayne@69
|
60 # define M_PKCS12_bag_type PKCS12_bag_type
|
jpayne@69
|
61 # define M_PKCS12_cert_bag_type PKCS12_cert_bag_type
|
jpayne@69
|
62 # define M_PKCS12_crl_bag_type PKCS12_cert_bag_type
|
jpayne@69
|
63
|
jpayne@69
|
64 # define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert
|
jpayne@69
|
65 # define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl
|
jpayne@69
|
66 # define PKCS12_bag_type PKCS12_SAFEBAG_get_nid
|
jpayne@69
|
67 # define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid
|
jpayne@69
|
68 # define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert
|
jpayne@69
|
69 # define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl
|
jpayne@69
|
70 # define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf
|
jpayne@69
|
71 # define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt
|
jpayne@69
|
72
|
jpayne@69
|
73 #endif
|
jpayne@69
|
74
|
jpayne@69
|
75 DEPRECATEDIN_1_1_0(ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag, int attr_nid))
|
jpayne@69
|
76
|
jpayne@69
|
77 ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid);
|
jpayne@69
|
78 int PKCS12_mac_present(const PKCS12 *p12);
|
jpayne@69
|
79 void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
|
jpayne@69
|
80 const X509_ALGOR **pmacalg,
|
jpayne@69
|
81 const ASN1_OCTET_STRING **psalt,
|
jpayne@69
|
82 const ASN1_INTEGER **piter,
|
jpayne@69
|
83 const PKCS12 *p12);
|
jpayne@69
|
84
|
jpayne@69
|
85 const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag,
|
jpayne@69
|
86 int attr_nid);
|
jpayne@69
|
87 const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
88 int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
89 int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
90
|
jpayne@69
|
91 X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
92 X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
93 const STACK_OF(PKCS12_SAFEBAG) *
|
jpayne@69
|
94 PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
95 const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
96 const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
97
|
jpayne@69
|
98 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
|
jpayne@69
|
99 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
|
jpayne@69
|
100 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
|
jpayne@69
|
101 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
|
jpayne@69
|
102 PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
|
jpayne@69
|
103 const char *pass,
|
jpayne@69
|
104 int passlen,
|
jpayne@69
|
105 unsigned char *salt,
|
jpayne@69
|
106 int saltlen, int iter,
|
jpayne@69
|
107 PKCS8_PRIV_KEY_INFO *p8inf);
|
jpayne@69
|
108
|
jpayne@69
|
109 PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
|
jpayne@69
|
110 int nid1, int nid2);
|
jpayne@69
|
111 PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
|
jpayne@69
|
112 int passlen);
|
jpayne@69
|
113 PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag,
|
jpayne@69
|
114 const char *pass, int passlen);
|
jpayne@69
|
115 X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
|
jpayne@69
|
116 const char *pass, int passlen, unsigned char *salt,
|
jpayne@69
|
117 int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8);
|
jpayne@69
|
118 X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen,
|
jpayne@69
|
119 PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe);
|
jpayne@69
|
120 PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
|
jpayne@69
|
121 STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
|
jpayne@69
|
122 PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
|
jpayne@69
|
123 unsigned char *salt, int saltlen, int iter,
|
jpayne@69
|
124 STACK_OF(PKCS12_SAFEBAG) *bags);
|
jpayne@69
|
125 STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
|
jpayne@69
|
126 int passlen);
|
jpayne@69
|
127
|
jpayne@69
|
128 int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
|
jpayne@69
|
129 STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12);
|
jpayne@69
|
130
|
jpayne@69
|
131 int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
|
jpayne@69
|
132 int namelen);
|
jpayne@69
|
133 int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
|
jpayne@69
|
134 int namelen);
|
jpayne@69
|
135 int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
|
jpayne@69
|
136 int namelen);
|
jpayne@69
|
137 int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
|
jpayne@69
|
138 int namelen);
|
jpayne@69
|
139 int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
|
jpayne@69
|
140 const unsigned char *name, int namelen);
|
jpayne@69
|
141 int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
|
jpayne@69
|
142 ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs,
|
jpayne@69
|
143 int attr_nid);
|
jpayne@69
|
144 char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
|
jpayne@69
|
145 const STACK_OF(X509_ATTRIBUTE) *
|
jpayne@69
|
146 PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag);
|
jpayne@69
|
147 unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
|
jpayne@69
|
148 const char *pass, int passlen,
|
jpayne@69
|
149 const unsigned char *in, int inlen,
|
jpayne@69
|
150 unsigned char **data, int *datalen,
|
jpayne@69
|
151 int en_de);
|
jpayne@69
|
152 void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
|
jpayne@69
|
153 const char *pass, int passlen,
|
jpayne@69
|
154 const ASN1_OCTET_STRING *oct, int zbuf);
|
jpayne@69
|
155 ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor,
|
jpayne@69
|
156 const ASN1_ITEM *it,
|
jpayne@69
|
157 const char *pass, int passlen,
|
jpayne@69
|
158 void *obj, int zbuf);
|
jpayne@69
|
159 PKCS12 *PKCS12_init(int mode);
|
jpayne@69
|
160 int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
|
jpayne@69
|
161 int saltlen, int id, int iter, int n,
|
jpayne@69
|
162 unsigned char *out, const EVP_MD *md_type);
|
jpayne@69
|
163 int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
|
jpayne@69
|
164 int saltlen, int id, int iter, int n,
|
jpayne@69
|
165 unsigned char *out, const EVP_MD *md_type);
|
jpayne@69
|
166 int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
|
jpayne@69
|
167 int saltlen, int id, int iter, int n,
|
jpayne@69
|
168 unsigned char *out, const EVP_MD *md_type);
|
jpayne@69
|
169 int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
|
jpayne@69
|
170 ASN1_TYPE *param, const EVP_CIPHER *cipher,
|
jpayne@69
|
171 const EVP_MD *md_type, int en_de);
|
jpayne@69
|
172 int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
|
jpayne@69
|
173 unsigned char *mac, unsigned int *maclen);
|
jpayne@69
|
174 int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
|
jpayne@69
|
175 int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
|
jpayne@69
|
176 unsigned char *salt, int saltlen, int iter,
|
jpayne@69
|
177 const EVP_MD *md_type);
|
jpayne@69
|
178 int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
|
jpayne@69
|
179 int saltlen, const EVP_MD *md_type);
|
jpayne@69
|
180 unsigned char *OPENSSL_asc2uni(const char *asc, int asclen,
|
jpayne@69
|
181 unsigned char **uni, int *unilen);
|
jpayne@69
|
182 char *OPENSSL_uni2asc(const unsigned char *uni, int unilen);
|
jpayne@69
|
183 unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
|
jpayne@69
|
184 unsigned char **uni, int *unilen);
|
jpayne@69
|
185 char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen);
|
jpayne@69
|
186
|
jpayne@69
|
187 DECLARE_ASN1_FUNCTIONS(PKCS12)
|
jpayne@69
|
188 DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
|
jpayne@69
|
189 DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
|
jpayne@69
|
190 DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
|
jpayne@69
|
191
|
jpayne@69
|
192 DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
|
jpayne@69
|
193 DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
|
jpayne@69
|
194
|
jpayne@69
|
195 void PKCS12_PBE_add(void);
|
jpayne@69
|
196 int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
|
jpayne@69
|
197 STACK_OF(X509) **ca);
|
jpayne@69
|
198 PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
|
jpayne@69
|
199 X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
|
jpayne@69
|
200 int iter, int mac_iter, int keytype);
|
jpayne@69
|
201
|
jpayne@69
|
202 PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
|
jpayne@69
|
203 PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
|
jpayne@69
|
204 EVP_PKEY *key, int key_usage, int iter,
|
jpayne@69
|
205 int key_nid, const char *pass);
|
jpayne@69
|
206 int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
|
jpayne@69
|
207 int safe_nid, int iter, const char *pass);
|
jpayne@69
|
208 PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
|
jpayne@69
|
209
|
jpayne@69
|
210 int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
|
jpayne@69
|
211 # ifndef OPENSSL_NO_STDIO
|
jpayne@69
|
212 int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
|
jpayne@69
|
213 # endif
|
jpayne@69
|
214 PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
|
jpayne@69
|
215 # ifndef OPENSSL_NO_STDIO
|
jpayne@69
|
216 PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
|
jpayne@69
|
217 # endif
|
jpayne@69
|
218 int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
|
jpayne@69
|
219
|
jpayne@69
|
220 # ifdef __cplusplus
|
jpayne@69
|
221 }
|
jpayne@69
|
222 # endif
|
jpayne@69
|
223 #endif
|