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