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