scorpiox-bot-plugin-fetch
←x509_csr.cc
648 lines · 19 KBHEADBlameDownload
1/*
2 * X.509 Certificate Signing Request (CSR) parsing
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 */
7/*
8 * The ITU-T X.509 standard defines a certificate format for PKI.
9 *
10 * http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs)
11 * http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs)
12 * http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10)
13 *
14 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
15 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
16 */
17
18#include "common.h"
19
20#if defined(MBEDTLS_X509_CSR_PARSE_C)
21
22#include "mbedtls/x509_csr.h"
23#include "x509_internal.h"
24#include "mbedtls/error.h"
25#include "mbedtls/oid.h"
26#include "mbedtls/platform_util.h"
27
28#include <string.h>
29
30#if defined(MBEDTLS_PEM_PARSE_C)
31#include "mbedtls/pem.h"
32#endif
33
34#include "mbedtls/platform.h"
35
36#if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32)
37#include <stdio.h>
38#endif
39
40/*
41 * Version ::= INTEGER { v1(0) }
42 */
43static int x509_csr_get_version(unsigned char **p,
44 const unsigned char *end,
45 int *ver)
46{
47 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
48
49 if ((ret = mbedtls_asn1_get_int(p, end, ver)) != 0) {
50 if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
51 *ver = 0;
52 return 0;
53 }
54
55 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_VERSION, ret);
56 }
57
58 return 0;
59}
60
61/*
62 * Parse CSR extension requests in DER format
63 */
64static int x509_csr_parse_extensions(mbedtls_x509_csr *csr,
65 unsigned char **p, const unsigned char *end,
66 mbedtls_x509_csr_ext_cb_t cb,
67 void *p_ctx)
68{
69 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
70 size_t len;
71 unsigned char *end_ext_data, *end_ext_octet;
72
73 while (*p < end) {
74 mbedtls_x509_buf extn_oid = { 0, 0, NULL };
75 int is_critical = 0; /* DEFAULT FALSE */
76 int ext_type = 0;
77
78 /* Read sequence tag */
79 if ((ret = mbedtls_asn1_get_tag(p, end, &len,
80 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
81 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
82 }
83
84 end_ext_data = *p + len;
85
86 /* Get extension ID */
87 if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &extn_oid.len,
88 MBEDTLS_ASN1_OID)) != 0) {
89 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
90 }
91
92 extn_oid.tag = MBEDTLS_ASN1_OID;
93 extn_oid.p = *p;
94 *p += extn_oid.len;
95
96 /* Get optional critical */
97 if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 &&
98 (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) {
99 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
100 }
101
102 /* Data should be octet string type */
103 if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
104 MBEDTLS_ASN1_OCTET_STRING)) != 0) {
105 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
106 }
107
108 end_ext_octet = *p + len;
109
110 if (end_ext_octet != end_ext_data) {
111 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
112 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
113 }
114
115 /*
116 * Detect supported extensions and skip unsupported extensions
117 */
118 ret = mbedtls_oid_get_x509_ext_type(&extn_oid, &ext_type);
119
120 if (ret != 0) {
121 /* Give the callback (if any) a chance to handle the extension */
122 if (cb != NULL) {
123 ret = cb(p_ctx, csr, &extn_oid, is_critical, *p, end_ext_octet);
124 if (ret != 0 && is_critical) {
125 return ret;
126 }
127 *p = end_ext_octet;
128 continue;
129 }
130
131 /* No parser found, skip extension */
132 *p = end_ext_octet;
133
134 if (is_critical) {
135 /* Data is marked as critical: fail */
136 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
137 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
138 }
139 continue;
140 }
141
142 /* Forbid repeated extensions */
143 if ((csr->ext_types & ext_type) != 0) {
144 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
145 MBEDTLS_ERR_ASN1_INVALID_DATA);
146 }
147
148 csr->ext_types |= ext_type;
149
150 switch (ext_type) {
151 case MBEDTLS_X509_EXT_KEY_USAGE:
152 /* Parse key usage */
153 if ((ret = mbedtls_x509_get_key_usage(p, end_ext_data,
154 &csr->key_usage)) != 0) {
155 return ret;
156 }
157 break;
158
159 case MBEDTLS_X509_EXT_SUBJECT_ALT_NAME:
160 /* Parse subject alt name */
161 if ((ret = mbedtls_x509_get_subject_alt_name(p, end_ext_data,
162 &csr->subject_alt_names)) != 0) {
163 return ret;
164 }
165 break;
166
167 case MBEDTLS_X509_EXT_NS_CERT_TYPE:
168 /* Parse netscape certificate type */
169 if ((ret = mbedtls_x509_get_ns_cert_type(p, end_ext_data,
170 &csr->ns_cert_type)) != 0) {
171 return ret;
172 }
173 break;
174 default:
175 /*
176 * If this is a non-critical extension, which the oid layer
177 * supports, but there isn't an x509 parser for it,
178 * skip the extension.
179 */
180 if (is_critical) {
181 return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
182 } else {
183 *p = end_ext_octet;
184 }
185 }
186 }
187
188 if (*p != end) {
189 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
190 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
191 }
192
193 return 0;
194}
195
196/*
197 * Parse CSR attributes in DER format
198 */
199static int x509_csr_parse_attributes(mbedtls_x509_csr *csr,
200 const unsigned char *start, const unsigned char *end,
201 mbedtls_x509_csr_ext_cb_t cb,
202 void *p_ctx)
203{
204 int ret;
205 size_t len;
206 unsigned char *end_attr_data;
207 unsigned char **p = (unsigned char **) &start;
208
209 while (*p < end) {
210 mbedtls_x509_buf attr_oid = { 0, 0, NULL };
211
212 if ((ret = mbedtls_asn1_get_tag(p, end, &len,
213 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
214 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
215 }
216 end_attr_data = *p + len;
217
218 /* Get attribute ID */
219 if ((ret = mbedtls_asn1_get_tag(p, end_attr_data, &attr_oid.len,
220 MBEDTLS_ASN1_OID)) != 0) {
221 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
222 }
223
224 attr_oid.tag = MBEDTLS_ASN1_OID;
225 attr_oid.p = *p;
226 *p += attr_oid.len;
227
228 /* Check that this is an extension-request attribute */
229 if (MBEDTLS_OID_CMP(MBEDTLS_OID_PKCS9_CSR_EXT_REQ, &attr_oid) == 0) {
230 if ((ret = mbedtls_asn1_get_tag(p, end_attr_data, &len,
231 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
232 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
233 }
234
235 const unsigned char *end_set = *p + len;
236 if (end_set != end_attr_data) {
237 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
238 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
239 }
240
241 if ((ret = mbedtls_asn1_get_tag(p, end_set, &len,
242 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) !=
243 0) {
244 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
245 }
246
247 const unsigned char *end_exts = *p + len;
248 if (end_exts != end_set) {
249 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
250 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
251 }
252
253 if ((ret = x509_csr_parse_extensions(csr, p, end_exts, cb, p_ctx)) != 0) {
254 return ret;
255 }
256 /* x509_csr_parse_extensions() guarantees *p == end_exts
257 * on success */
258 }
259
260 *p = end_attr_data;
261 }
262
263 if (*p != end) {
264 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
265 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
266 }
267
268 return 0;
269}
270
271/*
272 * Parse a CSR in DER format
273 */
274static int mbedtls_x509_csr_parse_der_internal(mbedtls_x509_csr *csr,
275 const unsigned char *buf, size_t buflen,
276 mbedtls_x509_csr_ext_cb_t cb,
277 void *p_ctx)
278{
279 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
280 size_t len;
281 unsigned char *p, *end;
282 mbedtls_x509_buf sig_params;
283
284 memset(&sig_params, 0, sizeof(mbedtls_x509_buf));
285
286 /*
287 * Check for valid input
288 */
289 if (csr == NULL || buf == NULL || buflen == 0) {
290 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
291 }
292
293 mbedtls_x509_csr_init(csr);
294
295 /*
296 * first copy the raw DER data
297 */
298 p = mbedtls_calloc(1, len = buflen);
299
300 if (p == NULL) {
301 return MBEDTLS_ERR_X509_ALLOC_FAILED;
302 }
303
304 memcpy(p, buf, buflen);
305
306 csr->raw.p = p;
307 csr->raw.len = len;
308 end = p + len;
309
310 /*
311 * CertificationRequest ::= SEQUENCE {
312 * certificationRequestInfo CertificationRequestInfo,
313 * signatureAlgorithm AlgorithmIdentifier,
314 * signature BIT STRING
315 * }
316 */
317 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
318 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
319 mbedtls_x509_csr_free(csr);
320 return MBEDTLS_ERR_X509_INVALID_FORMAT;
321 }
322
323 if (len != (size_t) (end - p)) {
324 mbedtls_x509_csr_free(csr);
325 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
326 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
327 }
328
329 /*
330 * CertificationRequestInfo ::= SEQUENCE {
331 */
332 csr->cri.p = p;
333
334 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
335 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
336 mbedtls_x509_csr_free(csr);
337 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
338 }
339
340 end = p + len;
341 csr->cri.len = (size_t) (end - csr->cri.p);
342
343 /*
344 * Version ::= INTEGER { v1(0) }
345 */
346 if ((ret = x509_csr_get_version(&p, end, &csr->version)) != 0) {
347 mbedtls_x509_csr_free(csr);
348 return ret;
349 }
350
351 if (csr->version != 0) {
352 mbedtls_x509_csr_free(csr);
353 return MBEDTLS_ERR_X509_UNKNOWN_VERSION;
354 }
355
356 csr->version++;
357
358 /*
359 * subject Name
360 */
361 csr->subject_raw.p = p;
362
363 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
364 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
365 mbedtls_x509_csr_free(csr);
366 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
367 }
368
369 if ((ret = mbedtls_x509_get_name(&p, p + len, &csr->subject)) != 0) {
370 mbedtls_x509_csr_free(csr);
371 return ret;
372 }
373
374 csr->subject_raw.len = (size_t) (p - csr->subject_raw.p);
375
376 /*
377 * subjectPKInfo SubjectPublicKeyInfo
378 */
379 if ((ret = mbedtls_pk_parse_subpubkey(&p, end, &csr->pk)) != 0) {
380 mbedtls_x509_csr_free(csr);
381 return ret;
382 }
383
384 /*
385 * attributes [0] Attributes
386 *
387 * The list of possible attributes is open-ended, though RFC 2985
388 * (PKCS#9) defines a few in section 5.4. We currently don't support any,
389 * so we just ignore them. This is a safe thing to do as the worst thing
390 * that could happen is that we issue a certificate that does not match
391 * the requester's expectations - this cannot cause a violation of our
392 * signature policies.
393 */
394 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
395 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC)) !=
396 0) {
397 mbedtls_x509_csr_free(csr);
398 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
399 }
400
401 if ((ret = x509_csr_parse_attributes(csr, p, p + len, cb, p_ctx)) != 0) {
402 mbedtls_x509_csr_free(csr);
403 return ret;
404 }
405
406 p += len;
407
408 end = csr->raw.p + csr->raw.len;
409
410 /*
411 * signatureAlgorithm AlgorithmIdentifier,
412 * signature BIT STRING
413 */
414 if ((ret = mbedtls_x509_get_alg(&p, end, &csr->sig_oid, &sig_params)) != 0) {
415 mbedtls_x509_csr_free(csr);
416 return ret;
417 }
418
419 if ((ret = mbedtls_x509_get_sig_alg(&csr->sig_oid, &sig_params,
420 &csr->sig_md, &csr->sig_pk,
421 &csr->sig_opts)) != 0) {
422 mbedtls_x509_csr_free(csr);
423 return MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG;
424 }
425
426 if ((ret = mbedtls_x509_get_sig(&p, end, &csr->sig)) != 0) {
427 mbedtls_x509_csr_free(csr);
428 return ret;
429 }
430
431 if (p != end) {
432 mbedtls_x509_csr_free(csr);
433 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
434 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
435 }
436
437 return 0;
438}
439
440/*
441 * Parse a CSR in DER format
442 */
443int mbedtls_x509_csr_parse_der(mbedtls_x509_csr *csr,
444 const unsigned char *buf, size_t buflen)
445{
446 return mbedtls_x509_csr_parse_der_internal(csr, buf, buflen, NULL, NULL);
447}
448
449/*
450 * Parse a CSR in DER format with callback for unknown extensions
451 */
452int mbedtls_x509_csr_parse_der_with_ext_cb(mbedtls_x509_csr *csr,
453 const unsigned char *buf, size_t buflen,
454 mbedtls_x509_csr_ext_cb_t cb,
455 void *p_ctx)
456{
457 return mbedtls_x509_csr_parse_der_internal(csr, buf, buflen, cb, p_ctx);
458}
459
460/*
461 * Parse a CSR, allowing for PEM or raw DER encoding
462 */
463int mbedtls_x509_csr_parse(mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen)
464{
465#if defined(MBEDTLS_PEM_PARSE_C)
466 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
467 size_t use_len;
468 mbedtls_pem_context pem;
469#endif
470
471 /*
472 * Check for valid input
473 */
474 if (csr == NULL || buf == NULL || buflen == 0) {
475 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
476 }
477
478#if defined(MBEDTLS_PEM_PARSE_C)
479 /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
480 if (buf[buflen - 1] == '\0') {
481 mbedtls_pem_init(&pem);
482 ret = mbedtls_pem_read_buffer(&pem,
483 "-----BEGIN CERTIFICATE REQUEST-----",
484 "-----END CERTIFICATE REQUEST-----",
485 buf, NULL, 0, &use_len);
486 if (ret == MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
487 ret = mbedtls_pem_read_buffer(&pem,
488 "-----BEGIN NEW CERTIFICATE REQUEST-----",
489 "-----END NEW CERTIFICATE REQUEST-----",
490 buf, NULL, 0, &use_len);
491 }
492
493 if (ret == 0) {
494 /*
495 * Was PEM encoded, parse the result
496 */
497 ret = mbedtls_x509_csr_parse_der(csr, pem.buf, pem.buflen);
498 }
499
500 mbedtls_pem_free(&pem);
501 if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
502 return ret;
503 }
504 }
505#endif /* MBEDTLS_PEM_PARSE_C */
506 return mbedtls_x509_csr_parse_der(csr, buf, buflen);
507}
508
509#if defined(MBEDTLS_FS_IO)
510/*
511 * Load a CSR into the structure
512 */
513int mbedtls_x509_csr_parse_file(mbedtls_x509_csr *csr, const char *path)
514{
515 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
516 size_t n;
517 unsigned char *buf;
518
519 if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) {
520 return ret;
521 }
522
523 ret = mbedtls_x509_csr_parse(csr, buf, n);
524
525 mbedtls_zeroize_and_free(buf, n);
526
527 return ret;
528}
529#endif /* MBEDTLS_FS_IO */
530
531#if !defined(MBEDTLS_X509_REMOVE_INFO)
532#define MBEDTLS_BEFORE_COLON 14
533#define MBEDTLS_BEFORE_COLON_STR "14"
534/*
535 * Return an informational string about the CSR.
536 */
537int mbedtls_x509_csr_info(char *buf, size_t size, const char *prefix,
538 const mbedtls_x509_csr *csr)
539{
540 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
541 size_t n;
542 char *p;
543 char key_size_str[MBEDTLS_BEFORE_COLON];
544
545 p = buf;
546 n = size;
547
548 ret = mbedtls_snprintf(p, n, "%sCSR version : %d",
549 prefix, csr->version);
550 MBEDTLS_X509_SAFE_SNPRINTF;
551
552 ret = mbedtls_snprintf(p, n, "\n%ssubject name : ", prefix);
553 MBEDTLS_X509_SAFE_SNPRINTF;
554 ret = mbedtls_x509_dn_gets(p, n, &csr->subject);
555 MBEDTLS_X509_SAFE_SNPRINTF;
556
557 ret = mbedtls_snprintf(p, n, "\n%ssigned using : ", prefix);
558 MBEDTLS_X509_SAFE_SNPRINTF;
559
560 ret = mbedtls_x509_sig_alg_gets(p, n, &csr->sig_oid, csr->sig_pk, csr->sig_md,
561 csr->sig_opts);
562 MBEDTLS_X509_SAFE_SNPRINTF;
563
564 if ((ret = mbedtls_x509_key_size_helper(key_size_str, MBEDTLS_BEFORE_COLON,
565 mbedtls_pk_get_name(&csr->pk))) != 0) {
566 return ret;
567 }
568
569 ret = mbedtls_snprintf(p, n, "\n%s%-" MBEDTLS_BEFORE_COLON_STR "s: %d bits\n",
570 prefix, key_size_str, (int) mbedtls_pk_get_bitlen(&csr->pk));
571 MBEDTLS_X509_SAFE_SNPRINTF;
572
573 /*
574 * Optional extensions
575 */
576
577 if (csr->ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) {
578 ret = mbedtls_snprintf(p, n, "\n%ssubject alt name :", prefix);
579 MBEDTLS_X509_SAFE_SNPRINTF;
580
581 if ((ret = mbedtls_x509_info_subject_alt_name(&p, &n,
582 &csr->subject_alt_names,
583 prefix)) != 0) {
584 return ret;
585 }
586 }
587
588 if (csr->ext_types & MBEDTLS_X509_EXT_NS_CERT_TYPE) {
589 ret = mbedtls_snprintf(p, n, "\n%scert. type : ", prefix);
590 MBEDTLS_X509_SAFE_SNPRINTF;
591
592 if ((ret = mbedtls_x509_info_cert_type(&p, &n, csr->ns_cert_type)) != 0) {
593 return ret;
594 }
595 }
596
597 if (csr->ext_types & MBEDTLS_X509_EXT_KEY_USAGE) {
598 ret = mbedtls_snprintf(p, n, "\n%skey usage : ", prefix);
599 MBEDTLS_X509_SAFE_SNPRINTF;
600
601 if ((ret = mbedtls_x509_info_key_usage(&p, &n, csr->key_usage)) != 0) {
602 return ret;
603 }
604 }
605
606 if (csr->ext_types != 0) {
607 ret = mbedtls_snprintf(p, n, "\n");
608 MBEDTLS_X509_SAFE_SNPRINTF;
609 }
610
611 return (int) (size - n);
612}
613#endif /* MBEDTLS_X509_REMOVE_INFO */
614
615/*
616 * Initialize a CSR
617 */
618void mbedtls_x509_csr_init(mbedtls_x509_csr *csr)
619{
620 memset(csr, 0, sizeof(mbedtls_x509_csr));
621}
622
623/*
624 * Unallocate all CSR data
625 */
626void mbedtls_x509_csr_free(mbedtls_x509_csr *csr)
627{
628 if (csr == NULL) {
629 return;
630 }
631
632 mbedtls_pk_free(&csr->pk);
633
634#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
635 mbedtls_free(csr->sig_opts);
636#endif
637
638 mbedtls_asn1_free_named_data_list_shallow(csr->subject.next);
639 mbedtls_asn1_sequence_free(csr->subject_alt_names.next);
640
641 if (csr->raw.p != NULL) {
642 mbedtls_zeroize_and_free(csr->raw.p, csr->raw.len);
643 }
644
645 mbedtls_platform_zeroize(csr, sizeof(mbedtls_x509_csr));
646}
647
648#endif /* MBEDTLS_X509_CSR_PARSE_C */