blob: d5357ea4e8fb4c267bb8704ab9ea4df191d27aa0 [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/*
Tom Cosgrove49f99bc2022-12-04 16:44:21 +00002 * X.509 Certificate Revocation List (CRL) parsing
Paul Bakker7c6b2c32013-09-16 13:49:26 +02003 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020018 */
19/*
20 * The ITU-T X.509 standard defines a certificate format for PKI.
21 *
Manuel Pégourié-Gonnard1c082f32014-06-12 22:34:55 +020022 * http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs)
23 * http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs)
24 * http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020025 *
26 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
27 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
28 */
29
Gilles Peskinedb09ef62020-06-03 01:43:33 +020030#include "common.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_X509_CRL_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020033
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000034#include "mbedtls/x509_crl.h"
Janos Follath73c616b2019-12-18 15:07:04 +000035#include "mbedtls/error.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000036#include "mbedtls/oid.h"
Andres Amaya Garcia1f6301b2018-04-17 09:51:09 -050037#include "mbedtls/platform_util.h"
Rich Evans00ab4702015-02-06 13:43:58 +000038
39#include <string.h>
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#if defined(MBEDTLS_PEM_PARSE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000042#include "mbedtls/pem.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020043#endif
44
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/platform.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020046
Daniel Axtens301db662020-05-28 11:43:41 +100047#if defined(MBEDTLS_HAVE_TIME)
Paul Bakkerfa6a6202013-10-28 18:48:30 +010048#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020049#include <windows.h>
50#else
51#include <time.h>
52#endif
Daniel Axtens301db662020-05-28 11:43:41 +100053#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020056#include <stdio.h>
57#endif
58
59/*
60 * Version ::= INTEGER { v1(0), v2(1) }
61 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010062static int x509_crl_get_version(unsigned char **p,
63 const unsigned char *end,
64 int *ver)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020065{
Janos Follath865b3eb2019-12-16 11:46:15 +000066 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020067
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010068 if ((ret = mbedtls_asn1_get_int(p, end, ver)) != 0) {
69 if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070 *ver = 0;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010071 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020072 }
73
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010074 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_VERSION, ret);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020075 }
76
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010077 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020078}
79
80/*
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +010081 * X.509 CRL v2 extensions
82 *
83 * We currently don't parse any extension's content, but we do check that the
84 * list of extensions is well-formed and abort on critical extensions (that
85 * are unsupported as we don't support any extension so far)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020086 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010087static int x509_get_crl_ext(unsigned char **p,
88 const unsigned char *end,
89 mbedtls_x509_buf *ext)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020090{
Janos Follath865b3eb2019-12-16 11:46:15 +000091 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020092
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010093 if (*p == end) {
94 return 0;
95 }
Hanno Becker12f62fb2019-02-12 17:22:36 +000096
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +010097 /*
98 * crlExtensions [0] EXPLICIT Extensions OPTIONAL
99 * -- if present, version MUST be v2
100 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100101 if ((ret = mbedtls_x509_get_ext(p, end, ext, 0)) != 0) {
102 return ret;
103 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200104
Hanno Becker12f62fb2019-02-12 17:22:36 +0000105 end = ext->p + ext->len;
106
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100107 while (*p < end) {
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100108 /*
109 * Extension ::= SEQUENCE {
110 * extnID OBJECT IDENTIFIER,
111 * critical BOOLEAN DEFAULT FALSE,
112 * extnValue OCTET STRING }
113 */
114 int is_critical = 0;
115 const unsigned char *end_ext_data;
116 size_t len;
117
118 /* Get enclosing sequence tag */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100119 if ((ret = mbedtls_asn1_get_tag(p, end, &len,
120 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
121 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
122 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200123
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100124 end_ext_data = *p + len;
125
126 /* Get OID (currently ignored) */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100127 if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
128 MBEDTLS_ASN1_OID)) != 0) {
129 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100130 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200131 *p += len;
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100132
133 /* Get optional critical */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100134 if ((ret = mbedtls_asn1_get_bool(p, end_ext_data,
135 &is_critical)) != 0 &&
136 (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) {
137 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100138 }
139
140 /* Data should be octet string type */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100141 if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
142 MBEDTLS_ASN1_OCTET_STRING)) != 0) {
143 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
144 }
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100145
146 /* Ignore data so far and just check its length */
147 *p += len;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100148 if (*p != end_ext_data) {
149 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
150 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
151 }
Manuel Pégourié-Gonnardfd3e4fb2018-03-13 11:53:30 +0100152
153 /* Abort on (unsupported) critical extensions */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100154 if (is_critical) {
155 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
156 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
157 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200158 }
159
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100160 if (*p != end) {
161 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
162 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
163 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200164
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100165 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200166}
167
168/*
169 * X.509 CRL v2 entry extensions (no extensions parsed yet.)
170 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100171static int x509_get_crl_entry_ext(unsigned char **p,
172 const unsigned char *end,
173 mbedtls_x509_buf *ext)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200174{
Janos Follath865b3eb2019-12-16 11:46:15 +0000175 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200176 size_t len = 0;
177
178 /* OPTIONAL */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100179 if (end <= *p) {
180 return 0;
181 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200182
183 ext->tag = **p;
184 ext->p = *p;
185
186 /*
187 * Get CRL-entry extension sequence header
188 * crlEntryExtensions Extensions OPTIONAL -- if present, MUST be v2
189 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100190 if ((ret = mbedtls_asn1_get_tag(p, end, &ext->len,
191 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
192 if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200193 ext->p = NULL;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100194 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200195 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100196 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200197 }
198
Paul Bakker9af723c2014-05-01 13:03:14 +0200199 end = *p + ext->len;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200200
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100201 if (end != *p + ext->len) {
202 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
203 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
204 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200205
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100206 while (*p < end) {
207 if ((ret = mbedtls_asn1_get_tag(p, end, &len,
208 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
209 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
210 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200211
212 *p += len;
213 }
214
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100215 if (*p != end) {
216 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
217 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
218 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200219
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100220 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200221}
222
223/*
224 * X.509 CRL Entries
225 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100226static int x509_get_entries(unsigned char **p,
227 const unsigned char *end,
228 mbedtls_x509_crl_entry *entry)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200229{
Janos Follath865b3eb2019-12-16 11:46:15 +0000230 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200231 size_t entry_len;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232 mbedtls_x509_crl_entry *cur_entry = entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200233
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100234 if (*p == end) {
235 return 0;
236 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200237
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100238 if ((ret = mbedtls_asn1_get_tag(p, end, &entry_len,
239 MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED)) != 0) {
240 if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
241 return 0;
242 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200243
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100244 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200245 }
246
247 end = *p + entry_len;
248
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100249 while (*p < end) {
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200250 size_t len2;
251 const unsigned char *end2;
252
Gilles Peskine5dd5a492020-07-16 18:26:29 +0200253 cur_entry->raw.tag = **p;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100254 if ((ret = mbedtls_asn1_get_tag(p, end, &len2,
255 MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED)) != 0) {
256 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200257 }
258
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200259 cur_entry->raw.p = *p;
260 cur_entry->raw.len = len2;
261 end2 = *p + len2;
262
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100263 if ((ret = mbedtls_x509_get_serial(p, end2, &cur_entry->serial)) != 0) {
264 return ret;
265 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200266
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100267 if ((ret = mbedtls_x509_get_time(p, end2,
268 &cur_entry->revocation_date)) != 0) {
269 return ret;
270 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200271
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100272 if ((ret = x509_get_crl_entry_ext(p, end2,
273 &cur_entry->entry_ext)) != 0) {
274 return ret;
275 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200276
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100277 if (*p < end) {
278 cur_entry->next = mbedtls_calloc(1, sizeof(mbedtls_x509_crl_entry));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200279
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100280 if (cur_entry->next == NULL) {
281 return MBEDTLS_ERR_X509_ALLOC_FAILED;
282 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200283
284 cur_entry = cur_entry->next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200285 }
286 }
287
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100288 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200289}
290
291/*
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100292 * Parse one CRLs in DER format and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200293 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100294int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain,
295 const unsigned char *buf, size_t buflen)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200296{
Janos Follath865b3eb2019-12-16 11:46:15 +0000297 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200298 size_t len;
Andres Amaya Garciaf1ee6352017-07-06 10:06:58 +0100299 unsigned char *p = NULL, *end = NULL;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300 mbedtls_x509_buf sig_params1, sig_params2, sig_oid2;
301 mbedtls_x509_crl *crl = chain;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200302
303 /*
304 * Check for valid input
305 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100306 if (crl == NULL || buf == NULL) {
307 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
308 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200309
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100310 memset(&sig_params1, 0, sizeof(mbedtls_x509_buf));
311 memset(&sig_params2, 0, sizeof(mbedtls_x509_buf));
312 memset(&sig_oid2, 0, sizeof(mbedtls_x509_buf));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200313
314 /*
315 * Add new CRL on the end of the chain if needed.
316 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100317 while (crl->version != 0 && crl->next != NULL) {
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100318 crl = crl->next;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100319 }
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100320
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100321 if (crl->version != 0 && crl->next == NULL) {
322 crl->next = mbedtls_calloc(1, sizeof(mbedtls_x509_crl));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200323
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100324 if (crl->next == NULL) {
325 mbedtls_x509_crl_free(crl);
326 return MBEDTLS_ERR_X509_ALLOC_FAILED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200327 }
328
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100329 mbedtls_x509_crl_init(crl->next);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200330 crl = crl->next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200331 }
332
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100333 /*
334 * Copy raw DER-encoded CRL
335 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100336 if (buflen == 0) {
337 return MBEDTLS_ERR_X509_INVALID_FORMAT;
338 }
Andres Amaya Garciac9d62262017-12-12 20:15:03 +0000339
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100340 p = mbedtls_calloc(1, buflen);
341 if (p == NULL) {
342 return MBEDTLS_ERR_X509_ALLOC_FAILED;
343 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200344
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100345 memcpy(p, buf, buflen);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200346
347 crl->raw.p = p;
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100348 crl->raw.len = buflen;
349
350 end = p + buflen;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200351
352 /*
353 * CertificateList ::= SEQUENCE {
354 * tbsCertList TBSCertList,
355 * signatureAlgorithm AlgorithmIdentifier,
356 * signatureValue BIT STRING }
357 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100358 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
359 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
360 mbedtls_x509_crl_free(crl);
361 return MBEDTLS_ERR_X509_INVALID_FORMAT;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200362 }
363
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100364 if (len != (size_t) (end - p)) {
365 mbedtls_x509_crl_free(crl);
366 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
367 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200368 }
369
370 /*
371 * TBSCertList ::= SEQUENCE {
372 */
373 crl->tbs.p = p;
374
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100375 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
376 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
377 mbedtls_x509_crl_free(crl);
378 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200379 }
380
381 end = p + len;
382 crl->tbs.len = end - crl->tbs.p;
383
384 /*
385 * Version ::= INTEGER OPTIONAL { v1(0), v2(1) }
386 * -- if present, MUST be v2
387 *
388 * signature AlgorithmIdentifier
389 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100390 if ((ret = x509_crl_get_version(&p, end, &crl->version)) != 0 ||
391 (ret = mbedtls_x509_get_alg(&p, end, &crl->sig_oid, &sig_params1)) != 0) {
392 mbedtls_x509_crl_free(crl);
393 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200394 }
395
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100396 if (crl->version < 0 || crl->version > 1) {
397 mbedtls_x509_crl_free(crl);
398 return MBEDTLS_ERR_X509_UNKNOWN_VERSION;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200399 }
400
Andres AG4f753c12017-02-10 14:39:58 +0000401 crl->version++;
402
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100403 if ((ret = mbedtls_x509_get_sig_alg(&crl->sig_oid, &sig_params1,
404 &crl->sig_md, &crl->sig_pk,
405 &crl->sig_opts)) != 0) {
406 mbedtls_x509_crl_free(crl);
407 return MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200408 }
409
410 /*
411 * issuer Name
412 */
413 crl->issuer_raw.p = p;
414
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100415 if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
416 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
417 mbedtls_x509_crl_free(crl);
418 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200419 }
420
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100421 if ((ret = mbedtls_x509_get_name(&p, p + len, &crl->issuer)) != 0) {
422 mbedtls_x509_crl_free(crl);
423 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200424 }
425
426 crl->issuer_raw.len = p - crl->issuer_raw.p;
427
428 /*
429 * thisUpdate Time
430 * nextUpdate Time OPTIONAL
431 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100432 if ((ret = mbedtls_x509_get_time(&p, end, &crl->this_update)) != 0) {
433 mbedtls_x509_crl_free(crl);
434 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200435 }
436
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100437 if ((ret = mbedtls_x509_get_time(&p, end, &crl->next_update)) != 0) {
438 if (ret != (MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
439 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) &&
440 ret != (MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
441 MBEDTLS_ERR_ASN1_OUT_OF_DATA))) {
442 mbedtls_x509_crl_free(crl);
443 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200444 }
445 }
446
447 /*
448 * revokedCertificates SEQUENCE OF SEQUENCE {
449 * userCertificate CertificateSerialNumber,
450 * revocationDate Time,
451 * crlEntryExtensions Extensions OPTIONAL
452 * -- if present, MUST be v2
453 * } OPTIONAL
454 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100455 if ((ret = x509_get_entries(&p, end, &crl->entry)) != 0) {
456 mbedtls_x509_crl_free(crl);
457 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200458 }
459
460 /*
461 * crlExtensions EXPLICIT Extensions OPTIONAL
462 * -- if present, MUST be v2
463 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100464 if (crl->version == 2) {
465 ret = x509_get_crl_ext(&p, end, &crl->crl_ext);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200466
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100467 if (ret != 0) {
468 mbedtls_x509_crl_free(crl);
469 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200470 }
471 }
472
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100473 if (p != end) {
474 mbedtls_x509_crl_free(crl);
475 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
476 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200477 }
478
479 end = crl->raw.p + crl->raw.len;
480
481 /*
482 * signatureAlgorithm AlgorithmIdentifier,
483 * signatureValue BIT STRING
484 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100485 if ((ret = mbedtls_x509_get_alg(&p, end, &sig_oid2, &sig_params2)) != 0) {
486 mbedtls_x509_crl_free(crl);
487 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200488 }
489
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100490 if (crl->sig_oid.len != sig_oid2.len ||
491 memcmp(crl->sig_oid.p, sig_oid2.p, crl->sig_oid.len) != 0 ||
Manuel Pégourié-Gonnarddddbb1d2014-06-05 17:02:24 +0200492 sig_params1.len != sig_params2.len ||
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100493 (sig_params1.len != 0 &&
494 memcmp(sig_params1.p, sig_params2.p, sig_params1.len) != 0)) {
495 mbedtls_x509_crl_free(crl);
496 return MBEDTLS_ERR_X509_SIG_MISMATCH;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200497 }
498
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100499 if ((ret = mbedtls_x509_get_sig(&p, end, &crl->sig)) != 0) {
500 mbedtls_x509_crl_free(crl);
501 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200502 }
503
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100504 if (p != end) {
505 mbedtls_x509_crl_free(crl);
506 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
507 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200508 }
509
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100510 return 0;
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100511}
512
513/*
514 * Parse one or more CRLs and add them to the chained list
515 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100516int mbedtls_x509_crl_parse(mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100517{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200518#if defined(MBEDTLS_PEM_PARSE_C)
Janos Follath865b3eb2019-12-16 11:46:15 +0000519 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Benjamin Kier36050732019-05-30 14:49:17 -0400520 size_t use_len = 0;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521 mbedtls_pem_context pem;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100522 int is_pem = 0;
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100523
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100524 if (chain == NULL || buf == NULL) {
525 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
526 }
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100527
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100528 do {
529 mbedtls_pem_init(&pem);
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200530
Simon Butcher97e82902016-05-19 00:22:37 +0100531 // Avoid calling mbedtls_pem_read_buffer() on non-null-terminated
532 // string
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100533 if (buflen == 0 || buf[buflen - 1] != '\0') {
Simon Butcher97e82902016-05-19 00:22:37 +0100534 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100535 } else {
536 ret = mbedtls_pem_read_buffer(&pem,
537 "-----BEGIN X509 CRL-----",
538 "-----END X509 CRL-----",
539 buf, NULL, 0, &use_len);
540 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200541
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100542 if (ret == 0) {
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100543 /*
544 * Was PEM encoded
545 */
546 is_pem = 1;
547
548 buflen -= use_len;
549 buf += use_len;
550
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100551 if ((ret = mbedtls_x509_crl_parse_der(chain,
552 pem.buf, pem.buflen)) != 0) {
553 mbedtls_pem_free(&pem);
554 return ret;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100555 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100556 } else if (is_pem) {
557 mbedtls_pem_free(&pem);
558 return ret;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100559 }
Andres AG5708dcb2016-12-08 17:19:21 +0000560
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100561 mbedtls_pem_free(&pem);
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100562 }
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200563 /* In the PEM case, buflen is 1 at the end, for the terminated NULL byte.
564 * And a valid CRL cannot be less than 1 byte anyway. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100565 while (is_pem && buflen > 1);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200566
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100567 if (is_pem) {
568 return 0;
569 } else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200570#endif /* MBEDTLS_PEM_PARSE_C */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100571 return mbedtls_x509_crl_parse_der(chain, buf, buflen);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200572}
573
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200575/*
576 * Load one or more CRLs and add them to the chained list
577 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100578int mbedtls_x509_crl_parse_file(mbedtls_x509_crl *chain, const char *path)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200579{
Janos Follath865b3eb2019-12-16 11:46:15 +0000580 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200581 size_t n;
582 unsigned char *buf;
583
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100584 if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) {
585 return ret;
586 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200587
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100588 ret = mbedtls_x509_crl_parse(chain, buf, n);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200589
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100590 mbedtls_platform_zeroize(buf, n);
591 mbedtls_free(buf);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200592
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100593 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200594}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200596
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200597/*
598 * Return an informational string about the certificate.
599 */
600#define BEFORE_COLON 14
601#define BC "14"
602/*
603 * Return an informational string about the CRL.
604 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100605int mbedtls_x509_crl_info(char *buf, size_t size, const char *prefix,
606 const mbedtls_x509_crl *crl)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200607{
Janos Follath865b3eb2019-12-16 11:46:15 +0000608 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200609 size_t n;
610 char *p;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200611 const mbedtls_x509_crl_entry *entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200612
613 p = buf;
614 n = size;
615
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100616 ret = mbedtls_snprintf(p, n, "%sCRL version : %d",
617 prefix, crl->version);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200618 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200619
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100620 ret = mbedtls_snprintf(p, n, "\n%sissuer name : ", prefix);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200621 MBEDTLS_X509_SAFE_SNPRINTF;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100622 ret = mbedtls_x509_dn_gets(p, n, &crl->issuer);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200623 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200624
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100625 ret = mbedtls_snprintf(p, n, "\n%sthis update : " \
626 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
627 crl->this_update.year, crl->this_update.mon,
628 crl->this_update.day, crl->this_update.hour,
629 crl->this_update.min, crl->this_update.sec);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200630 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200631
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100632 ret = mbedtls_snprintf(p, n, "\n%snext update : " \
633 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
634 crl->next_update.year, crl->next_update.mon,
635 crl->next_update.day, crl->next_update.hour,
636 crl->next_update.min, crl->next_update.sec);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200637 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200638
639 entry = &crl->entry;
640
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100641 ret = mbedtls_snprintf(p, n, "\n%sRevoked certificates:",
642 prefix);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200643 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200644
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100645 while (entry != NULL && entry->raw.len != 0) {
646 ret = mbedtls_snprintf(p, n, "\n%sserial number: ",
647 prefix);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200648 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200649
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100650 ret = mbedtls_x509_serial_gets(p, n, &entry->serial);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200651 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200652
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100653 ret = mbedtls_snprintf(p, n, " revocation date: " \
654 "%04d-%02d-%02d %02d:%02d:%02d",
655 entry->revocation_date.year, entry->revocation_date.mon,
656 entry->revocation_date.day, entry->revocation_date.hour,
657 entry->revocation_date.min, entry->revocation_date.sec);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200658 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200659
660 entry = entry->next;
661 }
662
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100663 ret = mbedtls_snprintf(p, n, "\n%ssigned using : ", prefix);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200664 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200665
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100666 ret = mbedtls_x509_sig_alg_gets(p, n, &crl->sig_oid, crl->sig_pk, crl->sig_md,
667 crl->sig_opts);
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200668 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200669
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100670 ret = mbedtls_snprintf(p, n, "\n");
Manuel Pégourié-Gonnard16853682015-06-22 11:12:02 +0200671 MBEDTLS_X509_SAFE_SNPRINTF;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200672
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100673 return (int) (size - n);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200674}
675
676/*
Paul Bakker369d2eb2013-09-18 11:58:25 +0200677 * Initialize a CRL chain
678 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100679void mbedtls_x509_crl_init(mbedtls_x509_crl *crl)
Paul Bakker369d2eb2013-09-18 11:58:25 +0200680{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100681 memset(crl, 0, sizeof(mbedtls_x509_crl));
Paul Bakker369d2eb2013-09-18 11:58:25 +0200682}
683
684/*
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200685 * Unallocate all CRL data
686 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100687void mbedtls_x509_crl_free(mbedtls_x509_crl *crl)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200688{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200689 mbedtls_x509_crl *crl_cur = crl;
690 mbedtls_x509_crl *crl_prv;
691 mbedtls_x509_name *name_cur;
692 mbedtls_x509_name *name_prv;
693 mbedtls_x509_crl_entry *entry_cur;
694 mbedtls_x509_crl_entry *entry_prv;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200695
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100696 if (crl == NULL) {
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200697 return;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100698 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200699
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100700 do {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100702 mbedtls_free(crl_cur->sig_opts);
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +0200703#endif
704
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200705 name_cur = crl_cur->issuer.next;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100706 while (name_cur != NULL) {
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200707 name_prv = name_cur;
708 name_cur = name_cur->next;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100709 mbedtls_platform_zeroize(name_prv, sizeof(mbedtls_x509_name));
710 mbedtls_free(name_prv);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200711 }
712
713 entry_cur = crl_cur->entry.next;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100714 while (entry_cur != NULL) {
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200715 entry_prv = entry_cur;
716 entry_cur = entry_cur->next;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100717 mbedtls_platform_zeroize(entry_prv,
718 sizeof(mbedtls_x509_crl_entry));
719 mbedtls_free(entry_prv);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200720 }
721
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100722 if (crl_cur->raw.p != NULL) {
723 mbedtls_platform_zeroize(crl_cur->raw.p, crl_cur->raw.len);
724 mbedtls_free(crl_cur->raw.p);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200725 }
726
727 crl_cur = crl_cur->next;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100728 } while (crl_cur != NULL);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200729
730 crl_cur = crl;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100731 do {
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200732 crl_prv = crl_cur;
733 crl_cur = crl_cur->next;
734
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100735 mbedtls_platform_zeroize(crl_prv, sizeof(mbedtls_x509_crl));
736 if (crl_prv != crl) {
737 mbedtls_free(crl_prv);
738 }
739 } while (crl_cur != NULL);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200740}
741
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200742#endif /* MBEDTLS_X509_CRL_PARSE_C */