Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1 | /* |
Manuel Pégourié-Gonnard | 1c082f3 | 2014-06-12 22:34:55 +0200 | [diff] [blame] | 2 | * X.509 Certidicate Revocation List (CRL) parsing |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 3 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 5 | * 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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 18 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 20 | */ |
| 21 | /* |
| 22 | * The ITU-T X.509 standard defines a certificate format for PKI. |
| 23 | * |
Manuel Pégourié-Gonnard | 1c082f3 | 2014-06-12 22:34:55 +0200 | [diff] [blame] | 24 | * http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs) |
| 25 | * http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs) |
| 26 | * http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 27 | * |
| 28 | * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf |
| 29 | * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf |
| 30 | */ |
| 31 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 32 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 33 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 34 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 35 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 36 | #endif |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 37 | |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 38 | #include "mbedtls/error.h" |
| 39 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #if defined(MBEDTLS_X509_CRL_PARSE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 41 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 42 | #include "mbedtls/x509_crl.h" |
| 43 | #include "mbedtls/oid.h" |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 44 | #include "mbedtls/platform_util.h" |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 45 | |
| 46 | #include <string.h> |
| 47 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 48 | #if defined(MBEDTLS_PEM_PARSE_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 49 | #include "mbedtls/pem.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 50 | #endif |
| 51 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 53 | #include "mbedtls/platform.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 54 | #else |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 55 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 981732b | 2015-02-17 15:46:45 +0000 | [diff] [blame] | 56 | #include <stdio.h> |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 58 | #define mbedtls_calloc calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 59 | #define mbedtls_snprintf snprintf |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 60 | #endif |
| 61 | |
Paul Bakker | fa6a620 | 2013-10-28 18:48:30 +0100 | [diff] [blame] | 62 | #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 63 | #include <windows.h> |
| 64 | #else |
| 65 | #include <time.h> |
| 66 | #endif |
| 67 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 68 | #if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 69 | #include <stdio.h> |
| 70 | #endif |
| 71 | |
| 72 | /* |
| 73 | * Version ::= INTEGER { v1(0), v2(1) } |
| 74 | */ |
| 75 | static int x509_crl_get_version( unsigned char **p, |
| 76 | const unsigned char *end, |
| 77 | int *ver ) |
| 78 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 79 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 80 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 81 | if( ( ret = mbedtls_asn1_get_int( p, end, ver ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 82 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 83 | if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 84 | { |
| 85 | *ver = 0; |
| 86 | return( 0 ); |
| 87 | } |
| 88 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 89 | return( MBEDTLS_ERR_X509_INVALID_VERSION + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | return( 0 ); |
| 93 | } |
| 94 | |
| 95 | /* |
Manuel Pégourié-Gonnard | fd3e4fb | 2018-03-13 11:53:30 +0100 | [diff] [blame] | 96 | * X.509 CRL v2 extensions |
| 97 | * |
| 98 | * We currently don't parse any extension's content, but we do check that the |
| 99 | * list of extensions is well-formed and abort on critical extensions (that |
| 100 | * are unsupported as we don't support any extension so far) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 101 | */ |
| 102 | static int x509_get_crl_ext( unsigned char **p, |
| 103 | const unsigned char *end, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | mbedtls_x509_buf *ext ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 105 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 106 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 107 | |
Hanno Becker | 12f62fb | 2019-02-12 17:22:36 +0000 | [diff] [blame] | 108 | if( *p == end ) |
| 109 | return( 0 ); |
| 110 | |
Manuel Pégourié-Gonnard | fd3e4fb | 2018-03-13 11:53:30 +0100 | [diff] [blame] | 111 | /* |
| 112 | * crlExtensions [0] EXPLICIT Extensions OPTIONAL |
| 113 | * -- if present, version MUST be v2 |
| 114 | */ |
| 115 | if( ( ret = mbedtls_x509_get_ext( p, end, ext, 0 ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 116 | return( ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 117 | |
Hanno Becker | 12f62fb | 2019-02-12 17:22:36 +0000 | [diff] [blame] | 118 | end = ext->p + ext->len; |
| 119 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 120 | while( *p < end ) |
| 121 | { |
Manuel Pégourié-Gonnard | fd3e4fb | 2018-03-13 11:53:30 +0100 | [diff] [blame] | 122 | /* |
| 123 | * Extension ::= SEQUENCE { |
| 124 | * extnID OBJECT IDENTIFIER, |
| 125 | * critical BOOLEAN DEFAULT FALSE, |
| 126 | * extnValue OCTET STRING } |
| 127 | */ |
| 128 | int is_critical = 0; |
| 129 | const unsigned char *end_ext_data; |
| 130 | size_t len; |
| 131 | |
| 132 | /* Get enclosing sequence tag */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 133 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, |
| 134 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
| 135 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 136 | |
Manuel Pégourié-Gonnard | fd3e4fb | 2018-03-13 11:53:30 +0100 | [diff] [blame] | 137 | end_ext_data = *p + len; |
| 138 | |
| 139 | /* Get OID (currently ignored) */ |
| 140 | if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len, |
| 141 | MBEDTLS_ASN1_OID ) ) != 0 ) |
| 142 | { |
| 143 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); |
| 144 | } |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 145 | *p += len; |
Manuel Pégourié-Gonnard | fd3e4fb | 2018-03-13 11:53:30 +0100 | [diff] [blame] | 146 | |
| 147 | /* Get optional critical */ |
| 148 | if( ( ret = mbedtls_asn1_get_bool( p, end_ext_data, |
| 149 | &is_critical ) ) != 0 && |
| 150 | ( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) |
| 151 | { |
| 152 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); |
| 153 | } |
| 154 | |
| 155 | /* Data should be octet string type */ |
| 156 | if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len, |
| 157 | MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) |
| 158 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); |
| 159 | |
| 160 | /* Ignore data so far and just check its length */ |
| 161 | *p += len; |
| 162 | if( *p != end_ext_data ) |
| 163 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + |
| 164 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
| 165 | |
| 166 | /* Abort on (unsupported) critical extensions */ |
| 167 | if( is_critical ) |
| 168 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + |
| 169 | MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | if( *p != end ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 173 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + |
| 174 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 175 | |
| 176 | return( 0 ); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * X.509 CRL v2 entry extensions (no extensions parsed yet.) |
| 181 | */ |
| 182 | static int x509_get_crl_entry_ext( unsigned char **p, |
| 183 | const unsigned char *end, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 184 | mbedtls_x509_buf *ext ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 185 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 186 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 187 | size_t len = 0; |
| 188 | |
| 189 | /* OPTIONAL */ |
Paul Bakker | 66d5d07 | 2014-06-17 16:39:18 +0200 | [diff] [blame] | 190 | if( end <= *p ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 191 | return( 0 ); |
| 192 | |
| 193 | ext->tag = **p; |
| 194 | ext->p = *p; |
| 195 | |
| 196 | /* |
| 197 | * Get CRL-entry extension sequence header |
| 198 | * crlEntryExtensions Extensions OPTIONAL -- if present, MUST be v2 |
| 199 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 200 | if( ( ret = mbedtls_asn1_get_tag( p, end, &ext->len, |
| 201 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 202 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 203 | if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 204 | { |
| 205 | ext->p = NULL; |
| 206 | return( 0 ); |
| 207 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 208 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 211 | end = *p + ext->len; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 212 | |
| 213 | if( end != *p + ext->len ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 214 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + |
| 215 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 216 | |
| 217 | while( *p < end ) |
| 218 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 219 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len, |
| 220 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
| 221 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 222 | |
| 223 | *p += len; |
| 224 | } |
| 225 | |
| 226 | if( *p != end ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 227 | return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + |
| 228 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 229 | |
| 230 | return( 0 ); |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * X.509 CRL Entries |
| 235 | */ |
| 236 | static int x509_get_entries( unsigned char **p, |
| 237 | const unsigned char *end, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 238 | mbedtls_x509_crl_entry *entry ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 239 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 240 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 241 | size_t entry_len; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 242 | mbedtls_x509_crl_entry *cur_entry = entry; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 243 | |
| 244 | if( *p == end ) |
| 245 | return( 0 ); |
| 246 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 247 | if( ( ret = mbedtls_asn1_get_tag( p, end, &entry_len, |
| 248 | MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 249 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 250 | if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 251 | return( 0 ); |
| 252 | |
| 253 | return( ret ); |
| 254 | } |
| 255 | |
| 256 | end = *p + entry_len; |
| 257 | |
| 258 | while( *p < end ) |
| 259 | { |
| 260 | size_t len2; |
| 261 | const unsigned char *end2; |
| 262 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 263 | if( ( ret = mbedtls_asn1_get_tag( p, end, &len2, |
| 264 | MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 265 | { |
| 266 | return( ret ); |
| 267 | } |
| 268 | |
| 269 | cur_entry->raw.tag = **p; |
| 270 | cur_entry->raw.p = *p; |
| 271 | cur_entry->raw.len = len2; |
| 272 | end2 = *p + len2; |
| 273 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 274 | if( ( ret = mbedtls_x509_get_serial( p, end2, &cur_entry->serial ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 275 | return( ret ); |
| 276 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 277 | if( ( ret = mbedtls_x509_get_time( p, end2, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 278 | &cur_entry->revocation_date ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 279 | return( ret ); |
| 280 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 281 | if( ( ret = x509_get_crl_entry_ext( p, end2, |
| 282 | &cur_entry->entry_ext ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 283 | return( ret ); |
| 284 | |
Paul Bakker | 66d5d07 | 2014-06-17 16:39:18 +0200 | [diff] [blame] | 285 | if( *p < end ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 286 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 287 | cur_entry->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl_entry ) ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 288 | |
| 289 | if( cur_entry->next == NULL ) |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 290 | return( MBEDTLS_ERR_X509_ALLOC_FAILED ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 291 | |
| 292 | cur_entry = cur_entry->next; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | return( 0 ); |
| 297 | } |
| 298 | |
| 299 | /* |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 300 | * Parse one CRLs in DER format and append it to the chained list |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 301 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 302 | int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain, |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 303 | const unsigned char *buf, size_t buflen ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 304 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 305 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 306 | size_t len; |
Andres Amaya Garcia | f1ee635 | 2017-07-06 10:06:58 +0100 | [diff] [blame] | 307 | unsigned char *p = NULL, *end = NULL; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 308 | mbedtls_x509_buf sig_params1, sig_params2, sig_oid2; |
| 309 | mbedtls_x509_crl *crl = chain; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | * Check for valid input |
| 313 | */ |
| 314 | if( crl == NULL || buf == NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 315 | return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 316 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 317 | memset( &sig_params1, 0, sizeof( mbedtls_x509_buf ) ); |
| 318 | memset( &sig_params2, 0, sizeof( mbedtls_x509_buf ) ); |
| 319 | memset( &sig_oid2, 0, sizeof( mbedtls_x509_buf ) ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 320 | |
| 321 | /* |
| 322 | * Add new CRL on the end of the chain if needed. |
| 323 | */ |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 324 | while( crl->version != 0 && crl->next != NULL ) |
| 325 | crl = crl->next; |
| 326 | |
Paul Bakker | 66d5d07 | 2014-06-17 16:39:18 +0200 | [diff] [blame] | 327 | if( crl->version != 0 && crl->next == NULL ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 328 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 329 | crl->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl ) ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 330 | |
| 331 | if( crl->next == NULL ) |
| 332 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 333 | mbedtls_x509_crl_free( crl ); |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 334 | return( MBEDTLS_ERR_X509_ALLOC_FAILED ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 337 | mbedtls_x509_crl_init( crl->next ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 338 | crl = crl->next; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 341 | /* |
| 342 | * Copy raw DER-encoded CRL |
| 343 | */ |
Andres Amaya Garcia | cb5123f | 2017-12-06 09:39:23 +0000 | [diff] [blame] | 344 | if( buflen == 0 ) |
| 345 | return( MBEDTLS_ERR_X509_INVALID_FORMAT ); |
Andres Amaya Garcia | c9d6226 | 2017-12-12 20:15:03 +0000 | [diff] [blame] | 346 | |
| 347 | p = mbedtls_calloc( 1, buflen ); |
| 348 | if( p == NULL ) |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 349 | return( MBEDTLS_ERR_X509_ALLOC_FAILED ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 350 | |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 351 | memcpy( p, buf, buflen ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 352 | |
| 353 | crl->raw.p = p; |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 354 | crl->raw.len = buflen; |
| 355 | |
| 356 | end = p + buflen; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 357 | |
| 358 | /* |
| 359 | * CertificateList ::= SEQUENCE { |
| 360 | * tbsCertList TBSCertList, |
| 361 | * signatureAlgorithm AlgorithmIdentifier, |
| 362 | * signatureValue BIT STRING } |
| 363 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 364 | if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, |
| 365 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 366 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 367 | mbedtls_x509_crl_free( crl ); |
| 368 | return( MBEDTLS_ERR_X509_INVALID_FORMAT ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | if( len != (size_t) ( end - p ) ) |
| 372 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 373 | mbedtls_x509_crl_free( crl ); |
| 374 | return( MBEDTLS_ERR_X509_INVALID_FORMAT + |
| 375 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* |
| 379 | * TBSCertList ::= SEQUENCE { |
| 380 | */ |
| 381 | crl->tbs.p = p; |
| 382 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 383 | if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, |
| 384 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 385 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 386 | mbedtls_x509_crl_free( crl ); |
| 387 | return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | end = p + len; |
| 391 | crl->tbs.len = end - crl->tbs.p; |
| 392 | |
| 393 | /* |
| 394 | * Version ::= INTEGER OPTIONAL { v1(0), v2(1) } |
| 395 | * -- if present, MUST be v2 |
| 396 | * |
| 397 | * signature AlgorithmIdentifier |
| 398 | */ |
| 399 | if( ( ret = x509_crl_get_version( &p, end, &crl->version ) ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 400 | ( ret = mbedtls_x509_get_alg( &p, end, &crl->sig_oid, &sig_params1 ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 401 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 402 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 403 | return( ret ); |
| 404 | } |
| 405 | |
Andres AG | 4f753c1 | 2017-02-10 14:39:58 +0000 | [diff] [blame] | 406 | if( crl->version < 0 || crl->version > 1 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 407 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 408 | mbedtls_x509_crl_free( crl ); |
| 409 | return( MBEDTLS_ERR_X509_UNKNOWN_VERSION ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Andres AG | 4f753c1 | 2017-02-10 14:39:58 +0000 | [diff] [blame] | 412 | crl->version++; |
| 413 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 414 | if( ( ret = mbedtls_x509_get_sig_alg( &crl->sig_oid, &sig_params1, |
Manuel Pégourié-Gonnard | f75f2f7 | 2014-06-05 15:14:28 +0200 | [diff] [blame] | 415 | &crl->sig_md, &crl->sig_pk, |
| 416 | &crl->sig_opts ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 417 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 418 | mbedtls_x509_crl_free( crl ); |
| 419 | return( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* |
| 423 | * issuer Name |
| 424 | */ |
| 425 | crl->issuer_raw.p = p; |
| 426 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 427 | if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, |
| 428 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 429 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 430 | mbedtls_x509_crl_free( crl ); |
| 431 | return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 432 | } |
| 433 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 434 | if( ( ret = mbedtls_x509_get_name( &p, p + len, &crl->issuer ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 435 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 436 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 437 | return( ret ); |
| 438 | } |
| 439 | |
| 440 | crl->issuer_raw.len = p - crl->issuer_raw.p; |
| 441 | |
| 442 | /* |
| 443 | * thisUpdate Time |
| 444 | * nextUpdate Time OPTIONAL |
| 445 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 446 | if( ( ret = mbedtls_x509_get_time( &p, end, &crl->this_update ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 447 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 448 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 449 | return( ret ); |
| 450 | } |
| 451 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 452 | if( ( ret = mbedtls_x509_get_time( &p, end, &crl->next_update ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 453 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 454 | if( ret != ( MBEDTLS_ERR_X509_INVALID_DATE + |
| 455 | MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) && |
| 456 | ret != ( MBEDTLS_ERR_X509_INVALID_DATE + |
| 457 | MBEDTLS_ERR_ASN1_OUT_OF_DATA ) ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 458 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 459 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 460 | return( ret ); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * revokedCertificates SEQUENCE OF SEQUENCE { |
| 466 | * userCertificate CertificateSerialNumber, |
| 467 | * revocationDate Time, |
| 468 | * crlEntryExtensions Extensions OPTIONAL |
| 469 | * -- if present, MUST be v2 |
| 470 | * } OPTIONAL |
| 471 | */ |
| 472 | if( ( ret = x509_get_entries( &p, end, &crl->entry ) ) != 0 ) |
| 473 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 474 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 475 | return( ret ); |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * crlExtensions EXPLICIT Extensions OPTIONAL |
| 480 | * -- if present, MUST be v2 |
| 481 | */ |
| 482 | if( crl->version == 2 ) |
| 483 | { |
| 484 | ret = x509_get_crl_ext( &p, end, &crl->crl_ext ); |
| 485 | |
| 486 | if( ret != 0 ) |
| 487 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 488 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 489 | return( ret ); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | if( p != end ) |
| 494 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 495 | mbedtls_x509_crl_free( crl ); |
| 496 | return( MBEDTLS_ERR_X509_INVALID_FORMAT + |
| 497 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | end = crl->raw.p + crl->raw.len; |
| 501 | |
| 502 | /* |
| 503 | * signatureAlgorithm AlgorithmIdentifier, |
| 504 | * signatureValue BIT STRING |
| 505 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 506 | if( ( ret = mbedtls_x509_get_alg( &p, end, &sig_oid2, &sig_params2 ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 507 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 508 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 509 | return( ret ); |
| 510 | } |
| 511 | |
Manuel Pégourié-Gonnard | 1022fed | 2015-03-27 16:30:47 +0100 | [diff] [blame] | 512 | if( crl->sig_oid.len != sig_oid2.len || |
| 513 | memcmp( crl->sig_oid.p, sig_oid2.p, crl->sig_oid.len ) != 0 || |
Manuel Pégourié-Gonnard | dddbb1d | 2014-06-05 17:02:24 +0200 | [diff] [blame] | 514 | sig_params1.len != sig_params2.len || |
Manuel Pégourié-Gonnard | 159c524 | 2015-04-30 11:15:22 +0200 | [diff] [blame] | 515 | ( sig_params1.len != 0 && |
| 516 | memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 ) ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 517 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 518 | mbedtls_x509_crl_free( crl ); |
| 519 | return( MBEDTLS_ERR_X509_SIG_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 522 | if( ( ret = mbedtls_x509_get_sig( &p, end, &crl->sig ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 523 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 524 | mbedtls_x509_crl_free( crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 525 | return( ret ); |
| 526 | } |
| 527 | |
| 528 | if( p != end ) |
| 529 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 530 | mbedtls_x509_crl_free( crl ); |
| 531 | return( MBEDTLS_ERR_X509_INVALID_FORMAT + |
| 532 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 533 | } |
| 534 | |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 535 | return( 0 ); |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * Parse one or more CRLs and add them to the chained list |
| 540 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 541 | int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen ) |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 542 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 543 | #if defined(MBEDTLS_PEM_PARSE_C) |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 544 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 545 | size_t use_len; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 546 | mbedtls_pem_context pem; |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 547 | int is_pem = 0; |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 548 | |
| 549 | if( chain == NULL || buf == NULL ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 550 | return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 551 | |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 552 | do |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 553 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 554 | mbedtls_pem_init( &pem ); |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 555 | |
Simon Butcher | 97e8290 | 2016-05-19 00:22:37 +0100 | [diff] [blame] | 556 | // Avoid calling mbedtls_pem_read_buffer() on non-null-terminated |
| 557 | // string |
| 558 | if( buflen == 0 || buf[buflen - 1] != '\0' ) |
| 559 | ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; |
| 560 | else |
| 561 | ret = mbedtls_pem_read_buffer( &pem, |
| 562 | "-----BEGIN X509 CRL-----", |
| 563 | "-----END X509 CRL-----", |
| 564 | buf, NULL, 0, &use_len ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 565 | |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 566 | if( ret == 0 ) |
| 567 | { |
| 568 | /* |
| 569 | * Was PEM encoded |
| 570 | */ |
| 571 | is_pem = 1; |
| 572 | |
| 573 | buflen -= use_len; |
| 574 | buf += use_len; |
| 575 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 576 | if( ( ret = mbedtls_x509_crl_parse_der( chain, |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 577 | pem.buf, pem.buflen ) ) != 0 ) |
| 578 | { |
Andres AG | 5708dcb | 2016-12-08 17:19:21 +0000 | [diff] [blame] | 579 | mbedtls_pem_free( &pem ); |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 580 | return( ret ); |
| 581 | } |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 582 | } |
Andres AG | 939954c | 2016-12-08 17:08:44 +0000 | [diff] [blame] | 583 | else if( is_pem ) |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 584 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 585 | mbedtls_pem_free( &pem ); |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 586 | return( ret ); |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 587 | } |
Andres AG | 5708dcb | 2016-12-08 17:19:21 +0000 | [diff] [blame] | 588 | |
| 589 | mbedtls_pem_free( &pem ); |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 590 | } |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 591 | /* In the PEM case, buflen is 1 at the end, for the terminated NULL byte. |
| 592 | * And a valid CRL cannot be less than 1 byte anyway. */ |
| 593 | while( is_pem && buflen > 1 ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 594 | |
Manuel Pégourié-Gonnard | 6ed2d92 | 2014-11-19 19:05:03 +0100 | [diff] [blame] | 595 | if( is_pem ) |
| 596 | return( 0 ); |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 597 | else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 598 | #endif /* MBEDTLS_PEM_PARSE_C */ |
| 599 | return( mbedtls_x509_crl_parse_der( chain, buf, buflen ) ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 602 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 603 | /* |
| 604 | * Load one or more CRLs and add them to the chained list |
| 605 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 606 | int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 607 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 608 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 609 | size_t n; |
| 610 | unsigned char *buf; |
| 611 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 612 | if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 613 | return( ret ); |
| 614 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 615 | ret = mbedtls_x509_crl_parse( chain, buf, n ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 616 | |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 617 | mbedtls_platform_zeroize( buf, n ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 618 | mbedtls_free( buf ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 619 | |
| 620 | return( ret ); |
| 621 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 622 | #endif /* MBEDTLS_FS_IO */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 623 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 624 | /* |
| 625 | * Return an informational string about the certificate. |
| 626 | */ |
| 627 | #define BEFORE_COLON 14 |
| 628 | #define BC "14" |
| 629 | /* |
| 630 | * Return an informational string about the CRL. |
| 631 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 632 | int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix, |
| 633 | const mbedtls_x509_crl *crl ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 634 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame^] | 635 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 636 | size_t n; |
| 637 | char *p; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 638 | const mbedtls_x509_crl_entry *entry; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 639 | |
| 640 | p = buf; |
| 641 | n = size; |
| 642 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 643 | ret = mbedtls_snprintf( p, n, "%sCRL version : %d", |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 644 | prefix, crl->version ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 645 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 646 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 647 | ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 648 | MBEDTLS_X509_SAFE_SNPRINTF; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 649 | ret = mbedtls_x509_dn_gets( p, n, &crl->issuer ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 650 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 651 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 652 | ret = mbedtls_snprintf( p, n, "\n%sthis update : " \ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 653 | "%04d-%02d-%02d %02d:%02d:%02d", prefix, |
| 654 | crl->this_update.year, crl->this_update.mon, |
| 655 | crl->this_update.day, crl->this_update.hour, |
| 656 | crl->this_update.min, crl->this_update.sec ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 657 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 658 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 659 | ret = mbedtls_snprintf( p, n, "\n%snext update : " \ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 660 | "%04d-%02d-%02d %02d:%02d:%02d", prefix, |
| 661 | crl->next_update.year, crl->next_update.mon, |
| 662 | crl->next_update.day, crl->next_update.hour, |
| 663 | crl->next_update.min, crl->next_update.sec ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 664 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 665 | |
| 666 | entry = &crl->entry; |
| 667 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 668 | ret = mbedtls_snprintf( p, n, "\n%sRevoked certificates:", |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 669 | prefix ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 670 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 671 | |
| 672 | while( entry != NULL && entry->raw.len != 0 ) |
| 673 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 674 | ret = mbedtls_snprintf( p, n, "\n%sserial number: ", |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 675 | prefix ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 676 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 677 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 678 | ret = mbedtls_x509_serial_gets( p, n, &entry->serial ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 679 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 680 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 681 | ret = mbedtls_snprintf( p, n, " revocation date: " \ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 682 | "%04d-%02d-%02d %02d:%02d:%02d", |
| 683 | entry->revocation_date.year, entry->revocation_date.mon, |
| 684 | entry->revocation_date.day, entry->revocation_date.hour, |
| 685 | entry->revocation_date.min, entry->revocation_date.sec ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 686 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 687 | |
| 688 | entry = entry->next; |
| 689 | } |
| 690 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 691 | ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 692 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 693 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 694 | ret = mbedtls_x509_sig_alg_gets( p, n, &crl->sig_oid, crl->sig_pk, crl->sig_md, |
Manuel Pégourié-Gonnard | bf696d0 | 2014-06-05 17:07:30 +0200 | [diff] [blame] | 695 | crl->sig_opts ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 696 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 697 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 698 | ret = mbedtls_snprintf( p, n, "\n" ); |
Manuel Pégourié-Gonnard | 1685368 | 2015-06-22 11:12:02 +0200 | [diff] [blame] | 699 | MBEDTLS_X509_SAFE_SNPRINTF; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 700 | |
| 701 | return( (int) ( size - n ) ); |
| 702 | } |
| 703 | |
| 704 | /* |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 705 | * Initialize a CRL chain |
| 706 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 707 | void mbedtls_x509_crl_init( mbedtls_x509_crl *crl ) |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 708 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 709 | memset( crl, 0, sizeof(mbedtls_x509_crl) ); |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /* |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 713 | * Unallocate all CRL data |
| 714 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 715 | void mbedtls_x509_crl_free( mbedtls_x509_crl *crl ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 716 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 717 | mbedtls_x509_crl *crl_cur = crl; |
| 718 | mbedtls_x509_crl *crl_prv; |
| 719 | mbedtls_x509_name *name_cur; |
| 720 | mbedtls_x509_name *name_prv; |
| 721 | mbedtls_x509_crl_entry *entry_cur; |
| 722 | mbedtls_x509_crl_entry *entry_prv; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 723 | |
| 724 | if( crl == NULL ) |
| 725 | return; |
| 726 | |
| 727 | do |
| 728 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 729 | #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) |
| 730 | mbedtls_free( crl_cur->sig_opts ); |
Manuel Pégourié-Gonnard | f75f2f7 | 2014-06-05 15:14:28 +0200 | [diff] [blame] | 731 | #endif |
| 732 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 733 | name_cur = crl_cur->issuer.next; |
| 734 | while( name_cur != NULL ) |
| 735 | { |
| 736 | name_prv = name_cur; |
| 737 | name_cur = name_cur->next; |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 738 | mbedtls_platform_zeroize( name_prv, sizeof( mbedtls_x509_name ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 739 | mbedtls_free( name_prv ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | entry_cur = crl_cur->entry.next; |
| 743 | while( entry_cur != NULL ) |
| 744 | { |
| 745 | entry_prv = entry_cur; |
| 746 | entry_cur = entry_cur->next; |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 747 | mbedtls_platform_zeroize( entry_prv, |
| 748 | sizeof( mbedtls_x509_crl_entry ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 749 | mbedtls_free( entry_prv ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | if( crl_cur->raw.p != NULL ) |
| 753 | { |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 754 | mbedtls_platform_zeroize( crl_cur->raw.p, crl_cur->raw.len ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 755 | mbedtls_free( crl_cur->raw.p ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 756 | } |
| 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 | |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 768 | mbedtls_platform_zeroize( crl_prv, sizeof( mbedtls_x509_crl ) ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 769 | if( crl_prv != crl ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 770 | mbedtls_free( crl_prv ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 771 | } |
| 772 | while( crl_cur != NULL ); |
| 773 | } |
| 774 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 775 | #endif /* MBEDTLS_X509_CRL_PARSE_C */ |