blob: 7988439900316abb035ccc95738777e2f455ef59 [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file x509_crl.h
Paul Bakker7c6b2c32013-09-16 13:49:26 +02003 *
4 * \brief X.509 certificate revocation list parsing
5 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_X509_CRL_H
24#define MBEDTLS_X509_CRL_H
Paul Bakker7c6b2c32013-09-16 13:49:26 +020025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020027#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020031
32#include "x509.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * \addtogroup x509_module
40 * \{ */
41
42/**
43 * \name Structures and functions for parsing CRLs
44 * \{
45 */
46
47/**
48 * Certificate revocation list entry.
49 * Contains the CA-specific serial numbers and revocation dates.
50 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051typedef struct mbedtls_x509_crl_entry
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053 mbedtls_x509_buf raw;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055 mbedtls_x509_buf serial;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057 mbedtls_x509_time revocation_date;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061 struct mbedtls_x509_crl_entry *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020062}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020064
65/**
66 * Certificate revocation list structure.
67 * Every CRL may have multiple entries.
68 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069typedef struct mbedtls_x509_crl
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
72 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020073
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +020074 int version; /**< CRL version (1=v1, 2=v2) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020076
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020080
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081 mbedtls_x509_time this_update;
82 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020083
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020085
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020087
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088 mbedtls_x509_buf sig_oid2;
89 mbedtls_x509_buf sig;
90 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
91 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
92 void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020093
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094 struct mbedtls_x509_crl *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020095}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020097
98/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010099 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100 *
101 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100102 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +0000103 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +0100104 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100105 *
106 * \return 0 if successful, or a specific X509 or PEM error code
107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100109 const unsigned char *buf, size_t buflen );
110/**
111 * \brief Parse one or more CRLs and append them to the chained list
112 *
113 * \note Mutliple CRLs are accepted only if using PEM format
114 *
115 * \param chain points to the start of the chain
116 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200117 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200118 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200119 *
120 * \return 0 if successful, or a specific X509 or PEM error code
121 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200125/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100126 * \brief Load one or more CRLs and append them to the chained list
127 *
128 * \note Mutliple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200129 *
130 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100131 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200132 *
133 * \return 0 if successful, or a specific X509 or PEM error code
134 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
136#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200137
138/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200139 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200140 *
141 * \param buf Buffer to write to
142 * \param size Maximum size of buffer
143 * \param prefix A line prefix
144 * \param crl The X509 CRL to represent
145 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200146 * \return The length of the string written (not including the
147 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200148 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
150 const mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200151
152/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200153 * \brief Initialize a CRL (chain)
154 *
155 * \param crl CRL chain to initialize
156 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200158
159/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200160 * \brief Unallocate all CRL data
161 *
162 * \param crl CRL chain to free
163 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200165
166/* \} name */
167/* \} addtogroup x509_module */
168
169#ifdef __cplusplus
170}
171#endif
172
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173#endif /* mbedtls_x509_crl.h */