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