This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
maclobdell
Date:
Wed May 18 19:06:32 2016 +0000
Revision:
0:f7c60d3e7b8a
clean version

Who changed what in which revision?

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