blob: 9e4a9e1729983273a8a17fde10ee82ca3ac560ba [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 ||
Paul Bakker66d5d072014-06-17 16:39:18 +0200466 memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200467 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468 mbedtls_x509_crl_free( crl );
469 return( MBEDTLS_ERR_X509_SIG_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200470 }
471
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200472 if( ( ret = mbedtls_x509_get_sig( &p, end, &crl->sig ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200473 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200474 mbedtls_x509_crl_free( crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200475 return( ret );
476 }
477
478 if( p != end )
479 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200480 mbedtls_x509_crl_free( crl );
481 return( MBEDTLS_ERR_X509_INVALID_FORMAT +
482 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200483 }
484
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100485 return( 0 );
486}
487
488/*
489 * Parse one or more CRLs and add them to the chained list
490 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen )
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100492{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200493#if defined(MBEDTLS_PEM_PARSE_C)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100494 int ret;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100495 size_t use_len;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200496 mbedtls_pem_context pem;
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100497 int is_pem = 0;
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100498
499 if( chain == NULL || buf == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200500 return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100501
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100502 do
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200503 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200504 mbedtls_pem_init( &pem );
505 ret = mbedtls_pem_read_buffer( &pem,
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100506 "-----BEGIN X509 CRL-----",
507 "-----END X509 CRL-----",
508 buf, NULL, 0, &use_len );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200509
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100510 if( ret == 0 )
511 {
512 /*
513 * Was PEM encoded
514 */
515 is_pem = 1;
516
517 buflen -= use_len;
518 buf += use_len;
519
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200520 if( ( ret = mbedtls_x509_crl_parse_der( chain,
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100521 pem.buf, pem.buflen ) ) != 0 )
522 {
523 return( ret );
524 }
525
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526 mbedtls_pem_free( &pem );
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100527 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200528 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100529 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530 mbedtls_pem_free( &pem );
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100531 return( ret );
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100532 }
533 }
534 while( is_pem && buflen > 0 );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200535
Manuel Pégourié-Gonnard6ed2d922014-11-19 19:05:03 +0100536 if( is_pem )
537 return( 0 );
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100538 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539#endif /* MBEDTLS_PEM_PARSE_C */
540 return( mbedtls_x509_crl_parse_der( chain, buf, buflen ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200541}
542
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200543#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200544/*
545 * Load one or more CRLs and add them to the chained list
546 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200548{
549 int ret;
550 size_t n;
551 unsigned char *buf;
552
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200553 if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200554 return( ret );
555
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556 ret = mbedtls_x509_crl_parse( chain, buf, n );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200557
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558 mbedtls_zeroize( buf, n + 1 );
559 mbedtls_free( buf );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200560
561 return( ret );
562}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200564
Paul Bakker6edcd412013-10-29 15:22:54 +0100565#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
566 !defined(EFI32)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200567#include <stdarg.h>
568
569#if !defined vsnprintf
570#define vsnprintf _vsnprintf
571#endif // vsnprintf
572
573/*
574 * Windows _snprintf and _vsnprintf are not compatible to linux versions.
575 * Result value is not size of buffer needed, but -1 if no fit is possible.
576 *
577 * This fuction tries to 'fix' this by at least suggesting enlarging the
578 * size by 20.
579 */
Paul Bakker66d5d072014-06-17 16:39:18 +0200580static int compat_snprintf( char *str, size_t size, const char *format, ... )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200581{
582 va_list ap;
583 int res = -1;
584
585 va_start( ap, format );
586
587 res = vsnprintf( str, size, format, ap );
588
589 va_end( ap );
590
591 // No quick fix possible
Paul Bakker66d5d072014-06-17 16:39:18 +0200592 if( res < 0 )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200593 return( (int) size + 20 );
594
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200595 return( res );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200596}
597
598#define snprintf compat_snprintf
Paul Bakker9af723c2014-05-01 13:03:14 +0200599#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200600
Manuel Pégourié-Gonnard8408a942015-04-09 12:14:31 +0200601#define ERR_BUF_TOO_SMALL -2
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200602
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200603#define SAFE_SNPRINTF() \
604{ \
605 if( ret == -1 ) \
606 return( -1 ); \
607 \
Paul Bakker66d5d072014-06-17 16:39:18 +0200608 if( (unsigned int) ret > n ) { \
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200609 p[n - 1] = '\0'; \
Manuel Pégourié-Gonnard8408a942015-04-09 12:14:31 +0200610 return( ERR_BUF_TOO_SMALL ); \
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200611 } \
612 \
613 n -= (unsigned int) ret; \
614 p += (unsigned int) ret; \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200615}
616
617/*
618 * Return an informational string about the certificate.
619 */
620#define BEFORE_COLON 14
621#define BC "14"
622/*
623 * Return an informational string about the CRL.
624 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200625int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
626 const mbedtls_x509_crl *crl )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200627{
628 int ret;
629 size_t n;
630 char *p;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200631 const mbedtls_x509_crl_entry *entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200632
633 p = buf;
634 n = size;
635
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200636 ret = mbedtls_snprintf( p, n, "%sCRL version : %d",
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200637 prefix, crl->version );
638 SAFE_SNPRINTF();
639
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200640 ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200641 SAFE_SNPRINTF();
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200642 ret = mbedtls_x509_dn_gets( p, n, &crl->issuer );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200643 SAFE_SNPRINTF();
644
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200645 ret = mbedtls_snprintf( p, n, "\n%sthis update : " \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200646 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
647 crl->this_update.year, crl->this_update.mon,
648 crl->this_update.day, crl->this_update.hour,
649 crl->this_update.min, crl->this_update.sec );
650 SAFE_SNPRINTF();
651
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652 ret = mbedtls_snprintf( p, n, "\n%snext update : " \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200653 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
654 crl->next_update.year, crl->next_update.mon,
655 crl->next_update.day, crl->next_update.hour,
656 crl->next_update.min, crl->next_update.sec );
657 SAFE_SNPRINTF();
658
659 entry = &crl->entry;
660
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661 ret = mbedtls_snprintf( p, n, "\n%sRevoked certificates:",
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200662 prefix );
663 SAFE_SNPRINTF();
664
665 while( entry != NULL && entry->raw.len != 0 )
666 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200667 ret = mbedtls_snprintf( p, n, "\n%sserial number: ",
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200668 prefix );
669 SAFE_SNPRINTF();
670
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200671 ret = mbedtls_x509_serial_gets( p, n, &entry->serial );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200672 SAFE_SNPRINTF();
673
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674 ret = mbedtls_snprintf( p, n, " revocation date: " \
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200675 "%04d-%02d-%02d %02d:%02d:%02d",
676 entry->revocation_date.year, entry->revocation_date.mon,
677 entry->revocation_date.day, entry->revocation_date.hour,
678 entry->revocation_date.min, entry->revocation_date.sec );
679 SAFE_SNPRINTF();
680
681 entry = entry->next;
682 }
683
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200684 ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200685 SAFE_SNPRINTF();
686
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200687 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 +0200688 crl->sig_opts );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200689 SAFE_SNPRINTF();
690
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200691 ret = mbedtls_snprintf( p, n, "\n" );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200692 SAFE_SNPRINTF();
693
694 return( (int) ( size - n ) );
695}
696
697/*
Paul Bakker369d2eb2013-09-18 11:58:25 +0200698 * Initialize a CRL chain
699 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700void mbedtls_x509_crl_init( mbedtls_x509_crl *crl )
Paul Bakker369d2eb2013-09-18 11:58:25 +0200701{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200702 memset( crl, 0, sizeof(mbedtls_x509_crl) );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200703}
704
705/*
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200706 * Unallocate all CRL data
707 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200709{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200710 mbedtls_x509_crl *crl_cur = crl;
711 mbedtls_x509_crl *crl_prv;
712 mbedtls_x509_name *name_cur;
713 mbedtls_x509_name *name_prv;
714 mbedtls_x509_crl_entry *entry_cur;
715 mbedtls_x509_crl_entry *entry_prv;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200716
717 if( crl == NULL )
718 return;
719
720 do
721 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200722#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
723 mbedtls_free( crl_cur->sig_opts );
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +0200724#endif
725
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200726 name_cur = crl_cur->issuer.next;
727 while( name_cur != NULL )
728 {
729 name_prv = name_cur;
730 name_cur = name_cur->next;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200731 mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
732 mbedtls_free( name_prv );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200733 }
734
735 entry_cur = crl_cur->entry.next;
736 while( entry_cur != NULL )
737 {
738 entry_prv = entry_cur;
739 entry_cur = entry_cur->next;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200740 mbedtls_zeroize( entry_prv, sizeof( mbedtls_x509_crl_entry ) );
741 mbedtls_free( entry_prv );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200742 }
743
744 if( crl_cur->raw.p != NULL )
745 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200746 mbedtls_zeroize( crl_cur->raw.p, crl_cur->raw.len );
747 mbedtls_free( crl_cur->raw.p );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200748 }
749
750 crl_cur = crl_cur->next;
751 }
752 while( crl_cur != NULL );
753
754 crl_cur = crl;
755 do
756 {
757 crl_prv = crl_cur;
758 crl_cur = crl_cur->next;
759
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200760 mbedtls_zeroize( crl_prv, sizeof( mbedtls_x509_crl ) );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200761 if( crl_prv != crl )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200762 mbedtls_free( crl_prv );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200763 }
764 while( crl_cur != NULL );
765}
766
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200767#endif /* MBEDTLS_X509_CRL_PARSE_C */