/src/openssl/crypto/x509/x_all.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | /* |
11 | | * Low level APIs are deprecated for public use, but still ok for |
12 | | * internal use. |
13 | | */ |
14 | | #include "internal/deprecated.h" |
15 | | |
16 | | #include <stdio.h> |
17 | | #include "internal/cryptlib.h" |
18 | | #include <openssl/buffer.h> |
19 | | #include <openssl/asn1.h> |
20 | | #include <openssl/evp.h> |
21 | | #include <openssl/x509.h> |
22 | | #include <openssl/x509_acert.h> |
23 | | #include <openssl/http.h> |
24 | | #include <openssl/rsa.h> |
25 | | #include <openssl/dsa.h> |
26 | | #include <openssl/x509v3.h> |
27 | | #include "internal/asn1.h" |
28 | | #include "crypto/asn1.h" |
29 | | #include "crypto/pkcs7.h" |
30 | | #include "crypto/x509.h" |
31 | | #include "crypto/x509_acert.h" |
32 | | #include "crypto/rsa.h" |
33 | | #include "x509_local.h" |
34 | | |
35 | | int X509_verify(const X509 *a, EVP_PKEY *r) |
36 | 0 | { |
37 | 0 | if (X509_ALGOR_cmp(&a->sig_alg, &a->cert_info.signature) != 0) |
38 | 0 | return 0; |
39 | | |
40 | 0 | return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_CINF), &a->sig_alg, |
41 | 0 | &a->signature, &a->cert_info, |
42 | 0 | a->distinguishing_id, r, a->libctx, a->propq); |
43 | 0 | } |
44 | | |
45 | | int X509_REQ_verify_ex(X509_REQ *a, EVP_PKEY *r, OSSL_LIB_CTX *libctx, |
46 | | const char *propq) |
47 | 0 | { |
48 | 0 | if (X509_REQ_get_version(a) != X509_REQ_VERSION_1) { |
49 | 0 | ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_VERSION); |
50 | 0 | return -1; |
51 | 0 | } |
52 | | |
53 | 0 | return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_REQ_INFO), &a->sig_alg, |
54 | 0 | a->signature, &a->req_info, a->distinguishing_id, |
55 | 0 | r, libctx, propq); |
56 | 0 | } |
57 | | |
58 | | int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) |
59 | 0 | { |
60 | 0 | return X509_REQ_verify_ex(a, r, NULL, NULL); |
61 | 0 | } |
62 | | |
63 | | int X509_ACERT_verify(X509_ACERT *a, EVP_PKEY *r) |
64 | 0 | { |
65 | 0 | if (X509_ALGOR_cmp(&a->sig_alg, &a->acinfo->signature) != 0) |
66 | 0 | return 0; |
67 | | |
68 | 0 | return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_ACERT_INFO), &a->sig_alg, |
69 | 0 | &a->signature, a->acinfo, |
70 | 0 | NULL, r, NULL, NULL); |
71 | 0 | } |
72 | | |
73 | | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) |
74 | 0 | { |
75 | 0 | return ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), |
76 | 0 | &a->sig_algor, a->signature, a->spkac, r); |
77 | 0 | } |
78 | | |
79 | | /* Detect invalid empty SKID or AKID extensions. */ |
80 | | |
81 | | static int bad_keyid_exts(const STACK_OF(X509_EXTENSION) *exts) |
82 | 0 | { |
83 | 0 | int i, n = sk_X509_EXTENSION_num(exts); |
84 | |
|
85 | 0 | for (i = 0; i < n; ++i) { |
86 | 0 | X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i); |
87 | |
|
88 | 0 | if (ossl_ignored_x509_extension(ext, X509V3_ADD_DEFAULT)) |
89 | 0 | return 1; |
90 | 0 | } |
91 | 0 | return 0; |
92 | 0 | } |
93 | | |
94 | | int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) |
95 | 0 | { |
96 | 0 | const STACK_OF(X509_EXTENSION) *exts; |
97 | |
|
98 | 0 | if (x == NULL) { |
99 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
100 | 0 | return 0; |
101 | 0 | } |
102 | 0 | if ((exts = X509_get0_extensions(x)) != NULL |
103 | 0 | && sk_X509_EXTENSION_num(exts) > 0 |
104 | 0 | && (bad_keyid_exts(exts) || !X509_set_version(x, X509_VERSION_3))) |
105 | 0 | return 0; |
106 | | |
107 | | /* |
108 | | * Setting the modified flag before signing it. This makes the cached |
109 | | * encoding to be ignored, so even if the certificate fields have changed, |
110 | | * they are signed correctly. |
111 | | * The X509_sign_ctx, X509_REQ_sign{,_ctx}, X509_CRL_sign{,_ctx} functions |
112 | | * which exist below are the same. |
113 | | */ |
114 | 0 | x->cert_info.enc.modified = 1; |
115 | 0 | return ASN1_item_sign_ex(ASN1_ITEM_rptr(X509_CINF), &x->cert_info.signature, |
116 | 0 | &x->sig_alg, &x->signature, &x->cert_info, NULL, |
117 | 0 | pkey, md, x->libctx, x->propq); |
118 | 0 | } |
119 | | |
120 | | int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) |
121 | 0 | { |
122 | 0 | const STACK_OF(X509_EXTENSION) *exts; |
123 | |
|
124 | 0 | if (x == NULL) { |
125 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
126 | 0 | return 0; |
127 | 0 | } |
128 | 0 | if ((exts = X509_get0_extensions(x)) != NULL && bad_keyid_exts(exts)) |
129 | 0 | return 0; |
130 | 0 | if (sk_X509_EXTENSION_num(X509_get0_extensions(x)) > 0 |
131 | 0 | && !X509_set_version(x, X509_VERSION_3)) |
132 | 0 | return 0; |
133 | 0 | x->cert_info.enc.modified = 1; |
134 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), |
135 | 0 | &x->cert_info.signature, |
136 | 0 | &x->sig_alg, &x->signature, &x->cert_info, ctx); |
137 | 0 | } |
138 | | |
139 | | static ASN1_VALUE *simple_get_asn1(const char *url, BIO *bio, BIO *rbio, |
140 | | int timeout, const ASN1_ITEM *it) |
141 | 0 | { |
142 | 0 | #ifndef OPENSSL_NO_HTTP |
143 | 0 | size_t max_resp_len = (it == ASN1_ITEM_rptr(X509_CRL)) ? OSSL_HTTP_DEFAULT_MAX_CRL_LEN : OSSL_HTTP_DEFAULT_MAX_RESP_LEN; |
144 | 0 | BIO *mem = OSSL_HTTP_get(url, NULL /* proxy */, NULL /* no_proxy */, |
145 | 0 | bio, rbio, NULL /* cb */, NULL /* arg */, |
146 | 0 | 1024 /* buf_size */, NULL /* headers */, |
147 | 0 | NULL /* expected_ct */, 1 /* expect_asn1 */, |
148 | 0 | max_resp_len, timeout); |
149 | 0 | ASN1_VALUE *res = ASN1_item_d2i_bio(it, mem, NULL); |
150 | |
|
151 | 0 | BIO_free(mem); |
152 | 0 | return res; |
153 | | #else |
154 | | return 0; |
155 | | #endif |
156 | 0 | } |
157 | | |
158 | | X509 *X509_load_http(const char *url, BIO *bio, BIO *rbio, int timeout) |
159 | 0 | { |
160 | 0 | return (X509 *)simple_get_asn1(url, bio, rbio, timeout, |
161 | 0 | ASN1_ITEM_rptr(X509)); |
162 | 0 | } |
163 | | |
164 | | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) |
165 | 0 | { |
166 | 0 | STACK_OF(X509_EXTENSION) *exts; |
167 | 0 | int bad = 0; |
168 | |
|
169 | 0 | if (x == NULL) { |
170 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
171 | 0 | return 0; |
172 | 0 | } |
173 | 0 | if ((exts = ossl_x509_req_get1_extensions_by_nid(x, NID_ext_req)) != NULL) |
174 | 0 | bad = bad_keyid_exts(exts); |
175 | 0 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); |
176 | 0 | if (bad) |
177 | 0 | return 0; |
178 | 0 | x->req_info.enc.modified = 1; |
179 | 0 | return ASN1_item_sign_ex(ASN1_ITEM_rptr(X509_REQ_INFO), &x->sig_alg, NULL, |
180 | 0 | x->signature, &x->req_info, NULL, |
181 | 0 | pkey, md, x->libctx, x->propq); |
182 | 0 | } |
183 | | |
184 | | int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) |
185 | 0 | { |
186 | 0 | STACK_OF(X509_EXTENSION) *exts; |
187 | 0 | int bad = 0; |
188 | |
|
189 | 0 | if (x == NULL) { |
190 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
191 | 0 | return 0; |
192 | 0 | } |
193 | 0 | if ((exts = ossl_x509_req_get1_extensions_by_nid(x, NID_ext_req)) != NULL) |
194 | 0 | bad = bad_keyid_exts(exts); |
195 | 0 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); |
196 | 0 | if (bad) |
197 | 0 | return 0; |
198 | 0 | x->req_info.enc.modified = 1; |
199 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), |
200 | 0 | &x->sig_alg, NULL, x->signature, &x->req_info, |
201 | 0 | ctx); |
202 | 0 | } |
203 | | |
204 | | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) |
205 | 0 | { |
206 | 0 | if (x == NULL) { |
207 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
208 | 0 | return 0; |
209 | 0 | } |
210 | 0 | x->crl.enc.modified = 1; |
211 | 0 | return ASN1_item_sign_ex(ASN1_ITEM_rptr(X509_CRL_INFO), &x->crl.sig_alg, |
212 | 0 | &x->sig_alg, &x->signature, &x->crl, NULL, |
213 | 0 | pkey, md, x->libctx, x->propq); |
214 | 0 | } |
215 | | |
216 | | int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) |
217 | 0 | { |
218 | 0 | if (x == NULL) { |
219 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
220 | 0 | return 0; |
221 | 0 | } |
222 | 0 | x->crl.enc.modified = 1; |
223 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), |
224 | 0 | &x->crl.sig_alg, &x->sig_alg, &x->signature, |
225 | 0 | &x->crl, ctx); |
226 | 0 | } |
227 | | |
228 | | X509_CRL *X509_CRL_load_http(const char *url, BIO *bio, BIO *rbio, int timeout) |
229 | 0 | { |
230 | 0 | return (X509_CRL *)simple_get_asn1(url, bio, rbio, timeout, |
231 | 0 | ASN1_ITEM_rptr(X509_CRL)); |
232 | 0 | } |
233 | | |
234 | | int X509_ACERT_sign(X509_ACERT *x, EVP_PKEY *pkey, const EVP_MD *md) |
235 | 0 | { |
236 | 0 | return ASN1_item_sign_ex(ASN1_ITEM_rptr(X509_ACERT_INFO), &x->sig_alg, |
237 | 0 | &x->acinfo->signature, |
238 | 0 | &x->signature, x->acinfo, NULL, |
239 | 0 | pkey, md, NULL, NULL); |
240 | 0 | } |
241 | | |
242 | | int X509_ACERT_sign_ctx(X509_ACERT *x, EVP_MD_CTX *ctx) |
243 | 0 | { |
244 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_ACERT_INFO), |
245 | 0 | &x->sig_alg, &x->acinfo->signature, &x->signature, |
246 | 0 | x->acinfo, ctx); |
247 | 0 | } |
248 | | |
249 | | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) |
250 | 0 | { |
251 | 0 | return ASN1_item_sign_ex(ASN1_ITEM_rptr(NETSCAPE_SPKAC), &x->sig_algor, NULL, |
252 | 0 | x->signature, x->spkac, NULL, pkey, md, NULL, NULL); |
253 | 0 | } |
254 | | |
255 | | #ifndef OPENSSL_NO_STDIO |
256 | | X509 *d2i_X509_fp(FILE *fp, X509 **x509) |
257 | 0 | { |
258 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); |
259 | 0 | } |
260 | | |
261 | | int i2d_X509_fp(FILE *fp, const X509 *x509) |
262 | 0 | { |
263 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); |
264 | 0 | } |
265 | | #endif |
266 | | |
267 | | X509 *d2i_X509_bio(BIO *bp, X509 **x509) |
268 | 0 | { |
269 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); |
270 | 0 | } |
271 | | |
272 | | int i2d_X509_bio(BIO *bp, const X509 *x509) |
273 | 0 | { |
274 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); |
275 | 0 | } |
276 | | |
277 | | #ifndef OPENSSL_NO_STDIO |
278 | | X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) |
279 | 0 | { |
280 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
281 | 0 | } |
282 | | |
283 | | int i2d_X509_CRL_fp(FILE *fp, const X509_CRL *crl) |
284 | 0 | { |
285 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
286 | 0 | } |
287 | | #endif |
288 | | |
289 | | X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) |
290 | 0 | { |
291 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
292 | 0 | } |
293 | | |
294 | | int i2d_X509_CRL_bio(BIO *bp, const X509_CRL *crl) |
295 | 0 | { |
296 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
297 | 0 | } |
298 | | |
299 | | #ifndef OPENSSL_NO_STDIO |
300 | | PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) |
301 | 0 | { |
302 | 0 | PKCS7 *ret; |
303 | 0 | OSSL_LIB_CTX *libctx = NULL; |
304 | 0 | const char *propq = NULL; |
305 | |
|
306 | 0 | if (p7 != NULL && *p7 != NULL) { |
307 | 0 | libctx = (*p7)->ctx.libctx; |
308 | 0 | propq = (*p7)->ctx.propq; |
309 | 0 | } |
310 | |
|
311 | 0 | ret = ASN1_item_d2i_fp_ex(ASN1_ITEM_rptr(PKCS7), fp, p7, libctx, propq); |
312 | 0 | if (ret != NULL) |
313 | 0 | ossl_pkcs7_resolve_libctx(ret); |
314 | 0 | return ret; |
315 | 0 | } |
316 | | |
317 | | int i2d_PKCS7_fp(FILE *fp, const PKCS7 *p7) |
318 | 0 | { |
319 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
320 | 0 | } |
321 | | #endif |
322 | | |
323 | | PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) |
324 | 0 | { |
325 | 0 | PKCS7 *ret; |
326 | 0 | OSSL_LIB_CTX *libctx = NULL; |
327 | 0 | const char *propq = NULL; |
328 | |
|
329 | 0 | if (p7 != NULL && *p7 != NULL) { |
330 | 0 | libctx = (*p7)->ctx.libctx; |
331 | 0 | propq = (*p7)->ctx.propq; |
332 | 0 | } |
333 | |
|
334 | 0 | ret = ASN1_item_d2i_bio_ex(ASN1_ITEM_rptr(PKCS7), bp, p7, libctx, propq); |
335 | 0 | if (ret != NULL) |
336 | 0 | ossl_pkcs7_resolve_libctx(ret); |
337 | 0 | return ret; |
338 | 0 | } |
339 | | |
340 | | int i2d_PKCS7_bio(BIO *bp, const PKCS7 *p7) |
341 | 0 | { |
342 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
343 | 0 | } |
344 | | |
345 | | #ifndef OPENSSL_NO_STDIO |
346 | | X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) |
347 | 0 | { |
348 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
349 | 0 | } |
350 | | |
351 | | int i2d_X509_REQ_fp(FILE *fp, const X509_REQ *req) |
352 | 0 | { |
353 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
354 | 0 | } |
355 | | #endif |
356 | | |
357 | | X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) |
358 | 0 | { |
359 | 0 | OSSL_LIB_CTX *libctx = NULL; |
360 | 0 | const char *propq = NULL; |
361 | |
|
362 | 0 | if (req != NULL && *req != NULL) { |
363 | 0 | libctx = (*req)->libctx; |
364 | 0 | propq = (*req)->propq; |
365 | 0 | } |
366 | |
|
367 | 0 | return ASN1_item_d2i_bio_ex(ASN1_ITEM_rptr(X509_REQ), bp, req, libctx, propq); |
368 | 0 | } |
369 | | |
370 | | int i2d_X509_REQ_bio(BIO *bp, const X509_REQ *req) |
371 | 0 | { |
372 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
373 | 0 | } |
374 | | |
375 | | #ifndef OPENSSL_NO_STDIO |
376 | | RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) |
377 | 0 | { |
378 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
379 | 0 | } |
380 | | |
381 | | int i2d_RSAPrivateKey_fp(FILE *fp, const RSA *rsa) |
382 | 0 | { |
383 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
384 | 0 | } |
385 | | |
386 | | RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) |
387 | 0 | { |
388 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
389 | 0 | } |
390 | | |
391 | | RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) |
392 | 0 | { |
393 | 0 | return ASN1_d2i_fp((void *(*)(void)) |
394 | 0 | RSA_new, |
395 | 0 | (D2I_OF(void))d2i_RSA_PUBKEY, fp, |
396 | 0 | (void **)rsa); |
397 | 0 | } |
398 | | |
399 | | int i2d_RSAPublicKey_fp(FILE *fp, const RSA *rsa) |
400 | 0 | { |
401 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
402 | 0 | } |
403 | | |
404 | | int i2d_RSA_PUBKEY_fp(FILE *fp, const RSA *rsa) |
405 | 0 | { |
406 | 0 | return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY, fp, rsa); |
407 | 0 | } |
408 | | #endif |
409 | | |
410 | | RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) |
411 | 0 | { |
412 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
413 | 0 | } |
414 | | |
415 | | int i2d_RSAPrivateKey_bio(BIO *bp, const RSA *rsa) |
416 | 0 | { |
417 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
418 | 0 | } |
419 | | |
420 | | RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) |
421 | 0 | { |
422 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
423 | 0 | } |
424 | | |
425 | | RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) |
426 | 0 | { |
427 | 0 | return ASN1_d2i_bio_of(RSA, RSA_new, d2i_RSA_PUBKEY, bp, rsa); |
428 | 0 | } |
429 | | |
430 | | int i2d_RSAPublicKey_bio(BIO *bp, const RSA *rsa) |
431 | 0 | { |
432 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
433 | 0 | } |
434 | | |
435 | | int i2d_RSA_PUBKEY_bio(BIO *bp, const RSA *rsa) |
436 | 0 | { |
437 | 0 | return ASN1_i2d_bio_of(RSA, i2d_RSA_PUBKEY, bp, rsa); |
438 | 0 | } |
439 | | |
440 | | #ifndef OPENSSL_NO_DSA |
441 | | #ifndef OPENSSL_NO_STDIO |
442 | | DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) |
443 | 0 | { |
444 | 0 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSAPrivateKey, fp, dsa); |
445 | 0 | } |
446 | | |
447 | | int i2d_DSAPrivateKey_fp(FILE *fp, const DSA *dsa) |
448 | 0 | { |
449 | 0 | return ASN1_i2d_fp_of(DSA, i2d_DSAPrivateKey, fp, dsa); |
450 | 0 | } |
451 | | |
452 | | DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) |
453 | 0 | { |
454 | 0 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSA_PUBKEY, fp, dsa); |
455 | 0 | } |
456 | | |
457 | | int i2d_DSA_PUBKEY_fp(FILE *fp, const DSA *dsa) |
458 | 0 | { |
459 | 0 | return ASN1_i2d_fp_of(DSA, i2d_DSA_PUBKEY, fp, dsa); |
460 | 0 | } |
461 | | #endif |
462 | | |
463 | | DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) |
464 | 0 | { |
465 | 0 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSAPrivateKey, bp, dsa); |
466 | 0 | } |
467 | | |
468 | | int i2d_DSAPrivateKey_bio(BIO *bp, const DSA *dsa) |
469 | 0 | { |
470 | 0 | return ASN1_i2d_bio_of(DSA, i2d_DSAPrivateKey, bp, dsa); |
471 | 0 | } |
472 | | |
473 | | DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) |
474 | 0 | { |
475 | 0 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSA_PUBKEY, bp, dsa); |
476 | 0 | } |
477 | | |
478 | | int i2d_DSA_PUBKEY_bio(BIO *bp, const DSA *dsa) |
479 | 0 | { |
480 | 0 | return ASN1_i2d_bio_of(DSA, i2d_DSA_PUBKEY, bp, dsa); |
481 | 0 | } |
482 | | |
483 | | #endif |
484 | | |
485 | | #ifndef OPENSSL_NO_EC |
486 | | #ifndef OPENSSL_NO_STDIO |
487 | | EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey) |
488 | 0 | { |
489 | 0 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, fp, eckey); |
490 | 0 | } |
491 | | |
492 | | int i2d_EC_PUBKEY_fp(FILE *fp, const EC_KEY *eckey) |
493 | 0 | { |
494 | 0 | return ASN1_i2d_fp_of(EC_KEY, i2d_EC_PUBKEY, fp, eckey); |
495 | 0 | } |
496 | | |
497 | | EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey) |
498 | 0 | { |
499 | 0 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, fp, eckey); |
500 | 0 | } |
501 | | |
502 | | int i2d_ECPrivateKey_fp(FILE *fp, const EC_KEY *eckey) |
503 | 0 | { |
504 | 0 | return ASN1_i2d_fp_of(EC_KEY, i2d_ECPrivateKey, fp, eckey); |
505 | 0 | } |
506 | | #endif |
507 | | EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey) |
508 | 0 | { |
509 | 0 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, bp, eckey); |
510 | 0 | } |
511 | | |
512 | | int i2d_EC_PUBKEY_bio(BIO *bp, const EC_KEY *ecdsa) |
513 | 0 | { |
514 | 0 | return ASN1_i2d_bio_of(EC_KEY, i2d_EC_PUBKEY, bp, ecdsa); |
515 | 0 | } |
516 | | |
517 | | EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey) |
518 | 0 | { |
519 | 0 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, bp, eckey); |
520 | 0 | } |
521 | | |
522 | | int i2d_ECPrivateKey_bio(BIO *bp, const EC_KEY *eckey) |
523 | 0 | { |
524 | 0 | return ASN1_i2d_bio_of(EC_KEY, i2d_ECPrivateKey, bp, eckey); |
525 | 0 | } |
526 | | #endif |
527 | | |
528 | | int X509_pubkey_digest(const X509 *data, const EVP_MD *type, |
529 | | unsigned char *md, unsigned int *len) |
530 | 0 | { |
531 | 0 | const ASN1_BIT_STRING *key = X509_get0_pubkey_bitstr(data); |
532 | |
|
533 | 0 | if (key == NULL) |
534 | 0 | return 0; |
535 | 0 | return EVP_Digest(key->data, key->length, md, len, type, NULL); |
536 | 0 | } |
537 | | |
538 | | int X509_digest(const X509 *cert, const EVP_MD *md, unsigned char *data, |
539 | | unsigned int *len) |
540 | 0 | { |
541 | 0 | if (EVP_MD_is_a(md, SN_sha1) && (cert->ex_flags & EXFLAG_SET) != 0 |
542 | 0 | && (cert->ex_flags & EXFLAG_NO_FINGERPRINT) == 0) { |
543 | | /* Asking for SHA1 and we already computed it. */ |
544 | 0 | if (len != NULL) |
545 | 0 | *len = sizeof(cert->sha1_hash); |
546 | 0 | memcpy(data, cert->sha1_hash, sizeof(cert->sha1_hash)); |
547 | 0 | return 1; |
548 | 0 | } |
549 | 0 | return ossl_asn1_item_digest_ex(ASN1_ITEM_rptr(X509), md, (char *)cert, |
550 | 0 | data, len, cert->libctx, cert->propq); |
551 | 0 | } |
552 | | |
553 | | /* calculate cert digest using the same hash algorithm as in its signature */ |
554 | | ASN1_OCTET_STRING *X509_digest_sig(const X509 *cert, |
555 | | EVP_MD **md_used, int *md_is_fallback) |
556 | 0 | { |
557 | 0 | unsigned int len; |
558 | 0 | unsigned char hash[EVP_MAX_MD_SIZE]; |
559 | 0 | int mdnid, pknid; |
560 | 0 | EVP_MD *md = NULL; |
561 | 0 | const char *md_name; |
562 | 0 | ASN1_OCTET_STRING *new; |
563 | |
|
564 | 0 | if (md_used != NULL) |
565 | 0 | *md_used = NULL; |
566 | 0 | if (md_is_fallback != NULL) |
567 | 0 | *md_is_fallback = 0; |
568 | |
|
569 | 0 | if (cert == NULL) { |
570 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
571 | 0 | return NULL; |
572 | 0 | } |
573 | | |
574 | 0 | if (!OBJ_find_sigid_algs(X509_get_signature_nid(cert), &mdnid, &pknid)) { |
575 | 0 | ERR_raise(ERR_LIB_X509, X509_R_UNKNOWN_SIGID_ALGS); |
576 | 0 | return NULL; |
577 | 0 | } |
578 | | |
579 | 0 | if (mdnid == NID_undef) { |
580 | 0 | if (pknid == EVP_PKEY_RSA_PSS) { |
581 | 0 | RSA_PSS_PARAMS *pss = ossl_rsa_pss_decode(&cert->sig_alg); |
582 | 0 | const EVP_MD *mgf1md, *mmd = NULL; |
583 | 0 | int saltlen, trailerfield; |
584 | |
|
585 | 0 | if (pss == NULL |
586 | 0 | || !ossl_rsa_pss_get_param_unverified(pss, &mmd, &mgf1md, |
587 | 0 | &saltlen, |
588 | 0 | &trailerfield) |
589 | 0 | || mmd == NULL) { |
590 | 0 | RSA_PSS_PARAMS_free(pss); |
591 | 0 | ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_ALGORITHM); |
592 | 0 | return NULL; |
593 | 0 | } |
594 | 0 | RSA_PSS_PARAMS_free(pss); |
595 | | /* Fetch explicitly and do not fallback */ |
596 | 0 | if ((md = EVP_MD_fetch(cert->libctx, EVP_MD_get0_name(mmd), |
597 | 0 | cert->propq)) |
598 | 0 | == NULL) |
599 | | /* Error code from fetch is sufficient */ |
600 | 0 | return NULL; |
601 | 0 | } else if (pknid != NID_undef) { |
602 | | /* A known algorithm, but without a digest */ |
603 | 0 | switch (pknid) { |
604 | 0 | case NID_ED25519: /* Follow CMS default given in RFC8419 */ |
605 | 0 | md_name = "SHA512"; |
606 | 0 | break; |
607 | 0 | case NID_ED448: /* Follow CMS default given in RFC8419 */ |
608 | 0 | md_name = "SHAKE256"; |
609 | 0 | break; |
610 | 0 | default: /* Fall back to SHA-256 */ |
611 | 0 | md_name = "SHA256"; |
612 | 0 | break; |
613 | 0 | } |
614 | 0 | if ((md = EVP_MD_fetch(cert->libctx, md_name, |
615 | 0 | cert->propq)) |
616 | 0 | == NULL) |
617 | 0 | return NULL; |
618 | 0 | if (md_is_fallback != NULL) |
619 | 0 | *md_is_fallback = 1; |
620 | 0 | } else { |
621 | | /* A completely unknown algorithm */ |
622 | 0 | ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_ALGORITHM); |
623 | 0 | return NULL; |
624 | 0 | } |
625 | 0 | } else if ((md = EVP_MD_fetch(cert->libctx, OBJ_nid2sn(mdnid), |
626 | 0 | cert->propq)) |
627 | 0 | == NULL) { |
628 | 0 | ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_ALGORITHM); |
629 | 0 | return NULL; |
630 | 0 | } |
631 | 0 | if (!X509_digest(cert, md, hash, &len) |
632 | 0 | || (new = ASN1_OCTET_STRING_new()) == NULL) |
633 | 0 | goto err; |
634 | 0 | if (ASN1_OCTET_STRING_set(new, hash, len)) { |
635 | 0 | if (md_used != NULL) |
636 | 0 | *md_used = md; |
637 | 0 | else |
638 | 0 | EVP_MD_free(md); |
639 | 0 | return new; |
640 | 0 | } |
641 | 0 | ASN1_OCTET_STRING_free(new); |
642 | 0 | err: |
643 | 0 | EVP_MD_free(md); |
644 | 0 | return NULL; |
645 | 0 | } |
646 | | |
647 | | int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, |
648 | | unsigned char *md, unsigned int *len) |
649 | 0 | { |
650 | 0 | if (type == NULL) { |
651 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); |
652 | 0 | return 0; |
653 | 0 | } |
654 | 0 | if (EVP_MD_is_a(type, SN_sha1) |
655 | 0 | && (data->flags & EXFLAG_SET) != 0 |
656 | 0 | && (data->flags & EXFLAG_NO_FINGERPRINT) == 0) { |
657 | | /* Asking for SHA1; always computed in CRL d2i. */ |
658 | 0 | if (len != NULL) |
659 | 0 | *len = sizeof(data->sha1_hash); |
660 | 0 | memcpy(md, data->sha1_hash, sizeof(data->sha1_hash)); |
661 | 0 | return 1; |
662 | 0 | } |
663 | 0 | return ossl_asn1_item_digest_ex(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, |
664 | 0 | md, len, data->libctx, data->propq); |
665 | 0 | } |
666 | | |
667 | | int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, |
668 | | unsigned char *md, unsigned int *len) |
669 | 0 | { |
670 | 0 | return ossl_asn1_item_digest_ex(ASN1_ITEM_rptr(X509_REQ), type, (char *)data, |
671 | 0 | md, len, data->libctx, data->propq); |
672 | 0 | } |
673 | | |
674 | | int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, |
675 | | unsigned char *md, unsigned int *len) |
676 | 0 | { |
677 | 0 | return ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME), type, (char *)data, |
678 | 0 | md, len); |
679 | 0 | } |
680 | | |
681 | | int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, |
682 | | const EVP_MD *type, unsigned char *md, |
683 | | unsigned int *len) |
684 | 0 | { |
685 | 0 | return ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL), type, |
686 | 0 | (char *)data, md, len); |
687 | 0 | } |
688 | | |
689 | | #ifndef OPENSSL_NO_STDIO |
690 | | X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) |
691 | 0 | { |
692 | 0 | return ASN1_d2i_fp_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, fp, p8); |
693 | 0 | } |
694 | | |
695 | | int i2d_PKCS8_fp(FILE *fp, const X509_SIG *p8) |
696 | 0 | { |
697 | 0 | return ASN1_i2d_fp_of(X509_SIG, i2d_X509_SIG, fp, p8); |
698 | 0 | } |
699 | | #endif |
700 | | |
701 | | X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) |
702 | 0 | { |
703 | 0 | return ASN1_d2i_bio_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, bp, p8); |
704 | 0 | } |
705 | | |
706 | | int i2d_PKCS8_bio(BIO *bp, const X509_SIG *p8) |
707 | 0 | { |
708 | 0 | return ASN1_i2d_bio_of(X509_SIG, i2d_X509_SIG, bp, p8); |
709 | 0 | } |
710 | | |
711 | | #ifndef OPENSSL_NO_STDIO |
712 | | X509_PUBKEY *d2i_X509_PUBKEY_fp(FILE *fp, X509_PUBKEY **xpk) |
713 | 0 | { |
714 | 0 | return ASN1_d2i_fp_of(X509_PUBKEY, X509_PUBKEY_new, d2i_X509_PUBKEY, |
715 | 0 | fp, xpk); |
716 | 0 | } |
717 | | |
718 | | int i2d_X509_PUBKEY_fp(FILE *fp, const X509_PUBKEY *xpk) |
719 | 0 | { |
720 | 0 | return ASN1_i2d_fp_of(X509_PUBKEY, i2d_X509_PUBKEY, fp, xpk); |
721 | 0 | } |
722 | | #endif |
723 | | |
724 | | X509_PUBKEY *d2i_X509_PUBKEY_bio(BIO *bp, X509_PUBKEY **xpk) |
725 | 0 | { |
726 | 0 | return ASN1_d2i_bio_of(X509_PUBKEY, X509_PUBKEY_new, d2i_X509_PUBKEY, |
727 | 0 | bp, xpk); |
728 | 0 | } |
729 | | |
730 | | int i2d_X509_PUBKEY_bio(BIO *bp, const X509_PUBKEY *xpk) |
731 | 0 | { |
732 | 0 | return ASN1_i2d_bio_of(X509_PUBKEY, i2d_X509_PUBKEY, bp, xpk); |
733 | 0 | } |
734 | | |
735 | | #ifndef OPENSSL_NO_STDIO |
736 | | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, |
737 | | PKCS8_PRIV_KEY_INFO **p8inf) |
738 | 0 | { |
739 | 0 | return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, |
740 | 0 | d2i_PKCS8_PRIV_KEY_INFO, fp, p8inf); |
741 | 0 | } |
742 | | |
743 | | int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, const PKCS8_PRIV_KEY_INFO *p8inf) |
744 | 0 | { |
745 | 0 | return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, fp, |
746 | 0 | p8inf); |
747 | 0 | } |
748 | | |
749 | | int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, const EVP_PKEY *key) |
750 | 0 | { |
751 | 0 | PKCS8_PRIV_KEY_INFO *p8inf; |
752 | 0 | int ret; |
753 | |
|
754 | 0 | p8inf = EVP_PKEY2PKCS8(key); |
755 | 0 | if (p8inf == NULL) |
756 | 0 | return 0; |
757 | 0 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); |
758 | 0 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
759 | 0 | return ret; |
760 | 0 | } |
761 | | |
762 | | int i2d_PrivateKey_fp(FILE *fp, const EVP_PKEY *pkey) |
763 | 0 | { |
764 | 0 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PrivateKey, fp, pkey); |
765 | 0 | } |
766 | | |
767 | | EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) |
768 | 0 | { |
769 | 0 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, fp, a); |
770 | 0 | } |
771 | | |
772 | | EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, |
773 | | const char *propq) |
774 | 0 | { |
775 | 0 | BIO *b; |
776 | 0 | void *ret; |
777 | |
|
778 | 0 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
779 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_BUF_LIB); |
780 | 0 | return NULL; |
781 | 0 | } |
782 | 0 | BIO_set_fp(b, fp, BIO_NOCLOSE); |
783 | 0 | ret = d2i_PrivateKey_ex_bio(b, a, libctx, propq); |
784 | 0 | BIO_free(b); |
785 | 0 | return ret; |
786 | 0 | } |
787 | | |
788 | | int i2d_PUBKEY_fp(FILE *fp, const EVP_PKEY *pkey) |
789 | 0 | { |
790 | 0 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PUBKEY, fp, pkey); |
791 | 0 | } |
792 | | |
793 | | EVP_PKEY *d2i_PUBKEY_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, |
794 | | const char *propq) |
795 | 0 | { |
796 | 0 | BIO *b; |
797 | 0 | void *ret; |
798 | |
|
799 | 0 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
800 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_BUF_LIB); |
801 | 0 | return NULL; |
802 | 0 | } |
803 | 0 | BIO_set_fp(b, fp, BIO_NOCLOSE); |
804 | 0 | ret = d2i_PUBKEY_ex_bio(b, a, libctx, propq); |
805 | 0 | BIO_free(b); |
806 | 0 | return ret; |
807 | 0 | } |
808 | | |
809 | | EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) |
810 | 0 | { |
811 | 0 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, fp, a); |
812 | 0 | } |
813 | | |
814 | | #endif |
815 | | |
816 | | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, |
817 | | PKCS8_PRIV_KEY_INFO **p8inf) |
818 | 0 | { |
819 | 0 | return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, |
820 | 0 | d2i_PKCS8_PRIV_KEY_INFO, bp, p8inf); |
821 | 0 | } |
822 | | |
823 | | int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, const PKCS8_PRIV_KEY_INFO *p8inf) |
824 | 0 | { |
825 | 0 | return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, bp, |
826 | 0 | p8inf); |
827 | 0 | } |
828 | | |
829 | | int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, const EVP_PKEY *key) |
830 | 0 | { |
831 | 0 | PKCS8_PRIV_KEY_INFO *p8inf; |
832 | 0 | int ret; |
833 | |
|
834 | 0 | p8inf = EVP_PKEY2PKCS8(key); |
835 | 0 | if (p8inf == NULL) |
836 | 0 | return 0; |
837 | 0 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); |
838 | 0 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
839 | 0 | return ret; |
840 | 0 | } |
841 | | |
842 | | int i2d_PrivateKey_bio(BIO *bp, const EVP_PKEY *pkey) |
843 | 0 | { |
844 | 0 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PrivateKey, bp, pkey); |
845 | 0 | } |
846 | | |
847 | | EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) |
848 | 0 | { |
849 | 0 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, bp, a); |
850 | 0 | } |
851 | | |
852 | | EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, |
853 | | const char *propq) |
854 | 0 | { |
855 | 0 | BUF_MEM *b = NULL; |
856 | 0 | const unsigned char *p; |
857 | 0 | void *ret = NULL; |
858 | 0 | int len; |
859 | |
|
860 | 0 | len = asn1_d2i_read_bio(bp, &b); |
861 | 0 | if (len < 0) |
862 | 0 | goto err; |
863 | | |
864 | 0 | p = (unsigned char *)b->data; |
865 | 0 | ret = d2i_AutoPrivateKey_ex(a, &p, len, libctx, propq); |
866 | 0 | err: |
867 | 0 | BUF_MEM_free(b); |
868 | 0 | return ret; |
869 | 0 | } |
870 | | |
871 | | int i2d_PUBKEY_bio(BIO *bp, const EVP_PKEY *pkey) |
872 | 0 | { |
873 | 0 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PUBKEY, bp, pkey); |
874 | 0 | } |
875 | | |
876 | | EVP_PKEY *d2i_PUBKEY_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, |
877 | | const char *propq) |
878 | 0 | { |
879 | 0 | BUF_MEM *b = NULL; |
880 | 0 | const unsigned char *p; |
881 | 0 | void *ret = NULL; |
882 | 0 | int len; |
883 | |
|
884 | 0 | len = asn1_d2i_read_bio(bp, &b); |
885 | 0 | if (len < 0) |
886 | 0 | goto err; |
887 | | |
888 | 0 | p = (unsigned char *)b->data; |
889 | 0 | ret = d2i_PUBKEY_ex(a, &p, len, libctx, propq); |
890 | 0 | err: |
891 | 0 | BUF_MEM_free(b); |
892 | 0 | return ret; |
893 | 0 | } |
894 | | |
895 | | EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) |
896 | 0 | { |
897 | 0 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, bp, a); |
898 | 0 | } |
899 | | |
900 | | #ifndef OPENSSL_NO_STDIO |
901 | | X509_ACERT *d2i_X509_ACERT_fp(FILE *fp, X509_ACERT **acert) |
902 | 0 | { |
903 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_ACERT), fp, acert); |
904 | 0 | } |
905 | | |
906 | | int i2d_X509_ACERT_fp(FILE *fp, const X509_ACERT *acert) |
907 | 0 | { |
908 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_ACERT), fp, acert); |
909 | 0 | } |
910 | | #endif |
911 | | |
912 | | X509_ACERT *d2i_X509_ACERT_bio(BIO *bp, X509_ACERT **acert) |
913 | 0 | { |
914 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_ACERT), bp, acert); |
915 | 0 | } |
916 | | |
917 | | int i2d_X509_ACERT_bio(BIO *bp, const X509_ACERT *acert) |
918 | 0 | { |
919 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_ACERT), bp, acert); |
920 | 0 | } |