blob: fc4b2dfdffb56ca1313dc54f2f4db25987c5b62c [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/*
Manuel Pégourié-Gonnard1c082f32014-06-12 22:34:55 +02002 * X.509 Certidicate Revocation List (CRL) parsing
Paul Bakker7c6b2c32013-09-16 13:49:26 +02003 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakker7c6b2c32013-09-16 13:49:26 +02005 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00006 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker7c6b2c32013-09-16 13:49:26 +02007 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +02008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22/*
23 * The ITU-T X.509 standard defines a certificate format for PKI.
24 *
Manuel Pégourié-Gonnard1c082f32014-06-12 22:34:55 +020025 * http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs)
26 * http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs)
27 * http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020028 *
29 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
30 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
31 */
32
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000034#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020037#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020038
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_X509_CRL_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020040
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/x509_crl.h"
42#include "mbedtls/oid.h"
Rich Evans00ab4702015-02-06 13:43:58 +000043
44#include <string.h>
45
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020046#if defined(MBEDTLS_PEM_PARSE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000047#include "mbedtls/pem.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020048#endif
49
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000051#include "mbedtls/platform.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052#else
Rich Evans00ab4702015-02-06 13:43:58 +000053#include <stdlib.h>
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +000054#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#define mbedtls_free free
56#define mbedtls_malloc malloc
57#define mbedtls_snprintf snprintf
Paul Bakker7c6b2c32013-09-16 13:49:26 +020058#endif
59
Paul Bakkerfa6a6202013-10-28 18:48:30 +010060#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020061#include <windows.h>
62#else
63#include <time.h>
64#endif
65
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066#if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020067#include <stdio.h>
68#endif
69
Paul Bakker34617722014-06-13 17:20:13 +020070/* Implementation that should never be optimized out by the compiler */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071static void mbedtls_zeroize( void *v, size_t n ) {
Paul Bakker34617722014-06-13 17:20:13 +020072 volatile unsigned char *p = v; while( n-- ) *p++ = 0;
73}
74
Paul Bakker7c6b2c32013-09-16 13:49:26 +020075/*
76 * Version ::= INTEGER { v1(0), v2(1) }
77 */
78static int x509_crl_get_version( unsigned char **p,
79 const unsigned char *end,
80 int *ver )
81{
82 int ret;
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084 if( ( ret = mbedtls_asn1_get_int( p, end, ver ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +020085 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086 if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
Paul Bakker7c6b2c32013-09-16 13:49:26 +020087 {
88 *ver = 0;
89 return( 0 );
90 }
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092 return( MBEDTLS_ERR_X509_INVALID_VERSION + ret );
Paul Bakker7c6b2c32013-09-16 13:49:26 +020093 }
94
95 return( 0 );
96}
97
98/*
99 * X.509 CRL v2 extensions (no extensions parsed yet.)
100 */
101static int x509_get_crl_ext( unsigned char **p,
102 const unsigned char *end,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103 mbedtls_x509_buf *ext )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200104{
105 int ret;
106 size_t len = 0;
107
108 /* Get explicit tag */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109 if( ( ret = mbedtls_x509_get_ext( p, end, ext, 0) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200110 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111 if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200112 return( 0 );
113
114 return( ret );
115 }
116
117 while( *p < end )
118 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119 if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
120 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
121 return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122
123 *p += len;
124 }
125
126 if( *p != end )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
128 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200129
130 return( 0 );
131}
132
133/*
134 * X.509 CRL v2 entry extensions (no extensions parsed yet.)
135 */
136static int x509_get_crl_entry_ext( unsigned char **p,
137 const unsigned char *end,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 mbedtls_x509_buf *ext )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200139{
140 int ret;
141 size_t len = 0;
142
143 /* OPTIONAL */
Paul Bakker66d5d072014-06-17 16:39:18 +0200144 if( end <= *p )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200145 return( 0 );
146
147 ext->tag = **p;
148 ext->p = *p;
149
150 /*
151 * Get CRL-entry extension sequence header
152 * crlEntryExtensions Extensions OPTIONAL -- if present, MUST be v2
153 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154 if( ( ret = mbedtls_asn1_get_tag( p, end, &ext->len,
155 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200156 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157 if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200158 {
159 ext->p = NULL;
160 return( 0 );
161 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162 return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200163 }
164
Paul Bakker9af723c2014-05-01 13:03:14 +0200165 end = *p + ext->len;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200166
167 if( end != *p + ext->len )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168 return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
169 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200170
171 while( *p < end )
172 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173 if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
174 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
175 return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200176
177 *p += len;
178 }
179
180 if( *p != end )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181 return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
182 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200183
184 return( 0 );
185}
186
187/*
188 * X.509 CRL Entries
189 */
190static int x509_get_entries( unsigned char **p,
191 const unsigned char *end,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192 mbedtls_x509_crl_entry *entry )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200193{
194 int ret;
195 size_t entry_len;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196 mbedtls_x509_crl_entry *cur_entry = entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200197
198 if( *p == end )
199 return( 0 );
200
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201 if( ( ret = mbedtls_asn1_get_tag( p, end, &entry_len,
202 MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200203 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204 if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200205 return( 0 );
206
207 return( ret );
208 }
209
210 end = *p + entry_len;
211
212 while( *p < end )
213 {
214 size_t len2;
215 const unsigned char *end2;
216
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217 if( ( ret = mbedtls_asn1_get_tag( p, end, &len2,
218 MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200219 {
220 return( ret );
221 }
222
223 cur_entry->raw.tag = **p;
224 cur_entry->raw.p = *p;
225 cur_entry->raw.len = len2;
226 end2 = *p + len2;
227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228 if( ( ret = mbedtls_x509_get_serial( p, end2, &cur_entry->serial ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200229 return( ret );
230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231 if( ( ret = mbedtls_x509_get_time( p, end2,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200232 &cur_entry->revocation_date ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200233 return( ret );
234
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200235 if( ( ret = x509_get_crl_entry_ext( p, end2,
236 &cur_entry->entry_ext ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200237 return( ret );
238
Paul Bakker66d5d072014-06-17 16:39:18 +0200239 if( *p < end )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200240 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241 cur_entry->next = mbedtls_malloc( sizeof( mbedtls_x509_crl_entry ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200242
243 if( cur_entry->next == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244 return( MBEDTLS_ERR_X509_MALLOC_FAILED );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200245
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246 memset( cur_entry->next, 0, sizeof( mbedtls_x509_crl_entry ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200247 cur_entry = cur_entry->next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200248 }
249 }
250
251 return( 0 );
252}
253
254/*
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100255 * Parse one CRLs in DER format and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200256 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100258 const unsigned char *buf, size_t buflen )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200259{
260 int ret;
261 size_t len;
262 unsigned char *p, *end;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263 mbedtls_x509_buf sig_params1, sig_params2, sig_oid2;
264 mbedtls_x509_crl *crl = chain;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200265
266 /*
267 * Check for valid input
268 */
269 if( crl == NULL || buf == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270 return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200271
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272 memset( &sig_params1, 0, sizeof( mbedtls_x509_buf ) );
273 memset( &sig_params2, 0, sizeof( mbedtls_x509_buf ) );
274 memset( &sig_oid2, 0, sizeof( mbedtls_x509_buf ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200275
276 /*
277 * Add new CRL on the end of the chain if needed.
278 */
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100279 while( crl->version != 0 && crl->next != NULL )
280 crl = crl->next;
281
Paul Bakker66d5d072014-06-17 16:39:18 +0200282 if( crl->version != 0 && crl->next == NULL )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200283 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284 crl->next = mbedtls_malloc( sizeof( mbedtls_x509_crl ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200285
286 if( crl->next == NULL )
287 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200288 mbedtls_x509_crl_free( crl );
289 return( MBEDTLS_ERR_X509_MALLOC_FAILED );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200290 }
291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292 mbedtls_x509_crl_init( crl->next );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200293 crl = crl->next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200294 }
295
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100296 /*
297 * Copy raw DER-encoded CRL
298 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200299 if( ( p = mbedtls_malloc( buflen ) ) == NULL )
300 return( MBEDTLS_ERR_X509_MALLOC_FAILED );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200301
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100302 memcpy( p, buf, buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200303
304 crl->raw.p = p;
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100305 crl->raw.len = buflen;
306
307 end = p + buflen;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200308
309 /*
310 * CertificateList ::= SEQUENCE {
311 * tbsCertList TBSCertList,
312 * signatureAlgorithm AlgorithmIdentifier,
313 * signatureValue BIT STRING }
314 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
316 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200317 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318 mbedtls_x509_crl_free( crl );
319 return( MBEDTLS_ERR_X509_INVALID_FORMAT );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200320 }
321
322 if( len != (size_t) ( end - p ) )
323 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324 mbedtls_x509_crl_free( crl );
325 return( MBEDTLS_ERR_X509_INVALID_FORMAT +
326 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200327 }
328
329 /*
330 * TBSCertList ::= SEQUENCE {
331 */
332 crl->tbs.p = p;
333
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
335 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200336 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200337 mbedtls_x509_crl_free( crl );
338 return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200339 }
340
341 end = p + len;
342 crl->tbs.len = end - crl->tbs.p;
343
344 /*
345 * Version ::= INTEGER OPTIONAL { v1(0), v2(1) }
346 * -- if present, MUST be v2
347 *
348 * signature AlgorithmIdentifier
349 */
350 if( ( ret = x509_crl_get_version( &p, end, &crl->version ) ) != 0 ||
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351 ( ret = mbedtls_x509_get_alg( &p, end, &crl->sig_oid, &sig_params1 ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200352 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200353 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200354 return( ret );
355 }
356
357 crl->version++;
358
359 if( crl->version > 2 )
360 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361 mbedtls_x509_crl_free( crl );
362 return( MBEDTLS_ERR_X509_UNKNOWN_VERSION );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200363 }
364
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200365 if( ( ret = mbedtls_x509_get_sig_alg( &crl->sig_oid, &sig_params1,
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +0200366 &crl->sig_md, &crl->sig_pk,
367 &crl->sig_opts ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200368 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200369 mbedtls_x509_crl_free( crl );
370 return( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200371 }
372
373 /*
374 * issuer Name
375 */
376 crl->issuer_raw.p = p;
377
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200378 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
379 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200380 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200381 mbedtls_x509_crl_free( crl );
382 return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200383 }
384
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200385 if( ( ret = mbedtls_x509_get_name( &p, p + len, &crl->issuer ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200386 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200387 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200388 return( ret );
389 }
390
391 crl->issuer_raw.len = p - crl->issuer_raw.p;
392
393 /*
394 * thisUpdate Time
395 * nextUpdate Time OPTIONAL
396 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200397 if( ( ret = mbedtls_x509_get_time( &p, end, &crl->this_update ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200398 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200400 return( ret );
401 }
402
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200403 if( ( ret = mbedtls_x509_get_time( &p, end, &crl->next_update ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200404 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405 if( ret != ( MBEDTLS_ERR_X509_INVALID_DATE +
406 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) &&
407 ret != ( MBEDTLS_ERR_X509_INVALID_DATE +
408 MBEDTLS_ERR_ASN1_OUT_OF_DATA ) )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200409 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200410 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200411 return( ret );
412 }
413 }
414
415 /*
416 * revokedCertificates SEQUENCE OF SEQUENCE {
417 * userCertificate CertificateSerialNumber,
418 * revocationDate Time,
419 * crlEntryExtensions Extensions OPTIONAL
420 * -- if present, MUST be v2
421 * } OPTIONAL
422 */
423 if( ( ret = x509_get_entries( &p, end, &crl->entry ) ) != 0 )
424 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200425 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200426 return( ret );
427 }
428
429 /*
430 * crlExtensions EXPLICIT Extensions OPTIONAL
431 * -- if present, MUST be v2
432 */
433 if( crl->version == 2 )
434 {
435 ret = x509_get_crl_ext( &p, end, &crl->crl_ext );
436
437 if( ret != 0 )
438 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200439 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200440 return( ret );
441 }
442 }
443
444 if( p != end )
445 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200446 mbedtls_x509_crl_free( crl );
447 return( MBEDTLS_ERR_X509_INVALID_FORMAT +
448 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200449 }
450
451 end = crl->raw.p + crl->raw.len;
452
453 /*
454 * signatureAlgorithm AlgorithmIdentifier,
455 * signatureValue BIT STRING
456 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457 if( ( ret = mbedtls_x509_get_alg( &p, end, &sig_oid2, &sig_params2 ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200458 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200459 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200460 return( ret );
461 }
462
Manuel Pégourié-Gonnard1022fed2015-03-27 16:30:47 +0100463 if( crl->sig_oid.len != sig_oid2.len ||
464 memcmp( crl->sig_oid.p, sig_oid2.p, crl->sig_oid.len ) != 0 ||
Manuel Pégourié-Gonnarddddbb1d2014-06-05 17:02:24 +0200465 sig_params1.len != sig_params2.len ||
Manuel Pégourié-Gonnard159c5242015-04-30 11:15:22 +0200466 ( sig_params1.len != 0 &&
467 memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 ) )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200468 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200469 mbedtls_x509_crl_free( crl );
470 return( MBEDTLS_ERR_X509_SIG_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200471 }
472
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200473 if( ( ret = mbedtls_x509_get_sig( &p, end, &crl->sig ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200474 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200475 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200476 return( ret );
477 }
478
479 if( p != end )
480 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200481 mbedtls_x509_crl_free( crl );
482 return( MBEDTLS_ERR_X509_INVALID_FORMAT +
483 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200484 }
485
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100486 return( 0 );
487}
488
489/*
490 * Parse one or more CRLs and add them to the chained list
491 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200492int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen )
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100493{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200494#if defined(MBEDTLS_PEM_PARSE_C)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100495 int ret;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100496 size_t use_len;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200497 mbedtls_pem_context pem;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100498 int is_pem = 0;
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100499
500 if( chain == NULL || buf == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200501 return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100502
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100503 do
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200504 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200505 mbedtls_pem_init( &pem );
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200506
507 /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
508 if( buf[buflen - 1] != '\0' )
509 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
510 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200511 ret = mbedtls_pem_read_buffer( &pem,
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100512 "-----BEGIN X509 CRL-----",
513 "-----END X509 CRL-----",
514 buf, NULL, 0, &use_len );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200515
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100516 if( ret == 0 )
517 {
518 /*
519 * Was PEM encoded
520 */
521 is_pem = 1;
522
523 buflen -= use_len;
524 buf += use_len;
525
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526 if( ( ret = mbedtls_x509_crl_parse_der( chain,
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100527 pem.buf, pem.buflen ) ) != 0 )
528 {
529 return( ret );
530 }
531
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532 mbedtls_pem_free( &pem );
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100533 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200534 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100535 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536 mbedtls_pem_free( &pem );
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100537 return( ret );
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100538 }
539 }
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200540 /* In the PEM case, buflen is 1 at the end, for the terminated NULL byte.
541 * And a valid CRL cannot be less than 1 byte anyway. */
542 while( is_pem && buflen > 1 );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200543
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100544 if( is_pem )
545 return( 0 );
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100546 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547#endif /* MBEDTLS_PEM_PARSE_C */
548 return( mbedtls_x509_crl_parse_der( chain, buf, buflen ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200549}
550
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200552/*
553 * Load one or more CRLs and add them to the chained list
554 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200556{
557 int ret;
558 size_t n;
559 unsigned char *buf;
560
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561 if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200562 return( ret );
563
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200564 ret = mbedtls_x509_crl_parse( chain, buf, n );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200565
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200566 mbedtls_zeroize( buf, n );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200567 mbedtls_free( buf );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200568
569 return( ret );
570}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200571#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200572
Paul Bakker6edcd412013-10-29 15:22:54 +0100573#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
574 !defined(EFI32)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200575#include <stdarg.h>
576
577#if !defined vsnprintf
578#define vsnprintf _vsnprintf
579#endif // vsnprintf
580
581/*
582 * Windows _snprintf and _vsnprintf are not compatible to linux versions.
583 * Result value is not size of buffer needed, but -1 if no fit is possible.
584 *
585 * This fuction tries to 'fix' this by at least suggesting enlarging the
586 * size by 20.
587 */
Paul Bakker66d5d072014-06-17 16:39:18 +0200588static int compat_snprintf( char *str, size_t size, const char *format, ... )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200589{
590 va_list ap;
591 int res = -1;
592
593 va_start( ap, format );
594
595 res = vsnprintf( str, size, format, ap );
596
597 va_end( ap );
598
599 // No quick fix possible
Paul Bakker66d5d072014-06-17 16:39:18 +0200600 if( res < 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200601 return( (int) size + 20 );
602
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200603 return( res );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200604}
605
606#define snprintf compat_snprintf
Paul Bakker9af723c2014-05-01 13:03:14 +0200607#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200608
Manuel Pégourié-Gonnard8408a942015-04-09 12:14:31 +0200609#define ERR_BUF_TOO_SMALL -2
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200610
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200611#define SAFE_SNPRINTF() \
612{ \
613 if( ret == -1 ) \
614 return( -1 ); \
615 \
Paul Bakker66d5d072014-06-17 16:39:18 +0200616 if( (unsigned int) ret > n ) { \
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200617 p[n - 1] = '\0'; \
Manuel Pégourié-Gonnard8408a942015-04-09 12:14:31 +0200618 return( ERR_BUF_TOO_SMALL ); \
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200619 } \
620 \
621 n -= (unsigned int) ret; \
622 p += (unsigned int) ret; \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200623}
624
625/*
626 * Return an informational string about the certificate.
627 */
628#define BEFORE_COLON 14
629#define BC "14"
630/*
631 * Return an informational string about the CRL.
632 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200633int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
634 const mbedtls_x509_crl *crl )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200635{
636 int ret;
637 size_t n;
638 char *p;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200639 const mbedtls_x509_crl_entry *entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200640
641 p = buf;
642 n = size;
643
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200644 ret = mbedtls_snprintf( p, n, "%sCRL version : %d",
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200645 prefix, crl->version );
646 SAFE_SNPRINTF();
647
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648 ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200649 SAFE_SNPRINTF();
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200650 ret = mbedtls_x509_dn_gets( p, n, &crl->issuer );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200651 SAFE_SNPRINTF();
652
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200653 ret = mbedtls_snprintf( p, n, "\n%sthis update : " \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200654 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
655 crl->this_update.year, crl->this_update.mon,
656 crl->this_update.day, crl->this_update.hour,
657 crl->this_update.min, crl->this_update.sec );
658 SAFE_SNPRINTF();
659
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200660 ret = mbedtls_snprintf( p, n, "\n%snext update : " \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200661 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
662 crl->next_update.year, crl->next_update.mon,
663 crl->next_update.day, crl->next_update.hour,
664 crl->next_update.min, crl->next_update.sec );
665 SAFE_SNPRINTF();
666
667 entry = &crl->entry;
668
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200669 ret = mbedtls_snprintf( p, n, "\n%sRevoked certificates:",
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200670 prefix );
671 SAFE_SNPRINTF();
672
673 while( entry != NULL && entry->raw.len != 0 )
674 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675 ret = mbedtls_snprintf( p, n, "\n%sserial number: ",
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200676 prefix );
677 SAFE_SNPRINTF();
678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200679 ret = mbedtls_x509_serial_gets( p, n, &entry->serial );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200680 SAFE_SNPRINTF();
681
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682 ret = mbedtls_snprintf( p, n, " revocation date: " \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200683 "%04d-%02d-%02d %02d:%02d:%02d",
684 entry->revocation_date.year, entry->revocation_date.mon,
685 entry->revocation_date.day, entry->revocation_date.hour,
686 entry->revocation_date.min, entry->revocation_date.sec );
687 SAFE_SNPRINTF();
688
689 entry = entry->next;
690 }
691
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692 ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200693 SAFE_SNPRINTF();
694
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200695 ret = mbedtls_x509_sig_alg_gets( p, n, &crl->sig_oid, crl->sig_pk, crl->sig_md,
Manuel Pégourié-Gonnardbf696d02014-06-05 17:07:30 +0200696 crl->sig_opts );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200697 SAFE_SNPRINTF();
698
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699 ret = mbedtls_snprintf( p, n, "\n" );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200700 SAFE_SNPRINTF();
701
702 return( (int) ( size - n ) );
703}
704
705/*
Paul Bakker369d2eb2013-09-18 11:58:25 +0200706 * Initialize a CRL chain
707 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708void mbedtls_x509_crl_init( mbedtls_x509_crl *crl )
Paul Bakker369d2eb2013-09-18 11:58:25 +0200709{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200710 memset( crl, 0, sizeof(mbedtls_x509_crl) );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200711}
712
713/*
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200714 * Unallocate all CRL data
715 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200717{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200718 mbedtls_x509_crl *crl_cur = crl;
719 mbedtls_x509_crl *crl_prv;
720 mbedtls_x509_name *name_cur;
721 mbedtls_x509_name *name_prv;
722 mbedtls_x509_crl_entry *entry_cur;
723 mbedtls_x509_crl_entry *entry_prv;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200724
725 if( crl == NULL )
726 return;
727
728 do
729 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200730#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
731 mbedtls_free( crl_cur->sig_opts );
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +0200732#endif
733
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200734 name_cur = crl_cur->issuer.next;
735 while( name_cur != NULL )
736 {
737 name_prv = name_cur;
738 name_cur = name_cur->next;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739 mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
740 mbedtls_free( name_prv );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200741 }
742
743 entry_cur = crl_cur->entry.next;
744 while( entry_cur != NULL )
745 {
746 entry_prv = entry_cur;
747 entry_cur = entry_cur->next;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200748 mbedtls_zeroize( entry_prv, sizeof( mbedtls_x509_crl_entry ) );
749 mbedtls_free( entry_prv );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200750 }
751
752 if( crl_cur->raw.p != NULL )
753 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200754 mbedtls_zeroize( crl_cur->raw.p, crl_cur->raw.len );
755 mbedtls_free( crl_cur->raw.p );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200756 }
757
758 crl_cur = crl_cur->next;
759 }
760 while( crl_cur != NULL );
761
762 crl_cur = crl;
763 do
764 {
765 crl_prv = crl_cur;
766 crl_cur = crl_cur->next;
767
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768 mbedtls_zeroize( crl_prv, sizeof( mbedtls_x509_crl ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200769 if( crl_prv != crl )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200770 mbedtls_free( crl_prv );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200771 }
772 while( crl_cur != NULL );
773}
774
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200775#endif /* MBEDTLS_X509_CRL_PARSE_C */