blob: bf9e3befa8551d6c0f83cc55d6e17c3353947fbf [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
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_X509_CRL_H
25#define MBEDTLS_X509_CRL_H
Paul Bakker7c6b2c32013-09-16 13:49:26 +020026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020032
33#include "x509.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/**
40 * \addtogroup x509_module
41 * \{ */
42
43/**
44 * \name Structures and functions for parsing CRLs
45 * \{
46 */
47
48/**
49 * Certificate revocation list entry.
50 * Contains the CA-specific serial numbers and revocation dates.
51 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052typedef struct mbedtls_x509_crl_entry
Paul Bakker7c6b2c32013-09-16 13:49:26 +020053{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054 mbedtls_x509_buf raw;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056 mbedtls_x509_buf serial;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020057
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058 mbedtls_x509_time revocation_date;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020061
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062 struct mbedtls_x509_crl_entry *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020063}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020065
66/**
67 * Certificate revocation list structure.
68 * Every CRL may have multiple entries.
69 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070typedef struct mbedtls_x509_crl
Paul Bakker7c6b2c32013-09-16 13:49:26 +020071{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
73 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020074
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +020075 int version; /**< CRL version (1=v1, 2=v2) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020077
Hanno Beckera632e362019-02-20 13:44:36 +000078 mbedtls_x509_buf_raw issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020079
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020081
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082 mbedtls_x509_time this_update;
83 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020084
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020088
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089 mbedtls_x509_buf sig_oid2;
90 mbedtls_x509_buf sig;
91 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
92 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
93 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 +020094
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095 struct mbedtls_x509_crl *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020096}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020098
99/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100100 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200101 *
102 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100103 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +0000104 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +0100105 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100106 *
107 * \return 0 if successful, or a specific X509 or PEM error code
108 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100110 const unsigned char *buf, size_t buflen );
111/**
112 * \brief Parse one or more CRLs and append them to the chained list
113 *
Antonin Décimod5f47592019-01-23 15:24:37 +0100114 * \note Multiple CRLs are accepted only if using PEM format
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100115 *
116 * \param chain points to the start of the chain
117 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200118 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200119 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200120 *
121 * \return 0 if successful, or a specific X509 or PEM error code
122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200126/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100127 * \brief Load one or more CRLs and append them to the chained list
128 *
Antonin Décimod5f47592019-01-23 15:24:37 +0100129 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200130 *
131 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100132 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200133 *
134 * \return 0 if successful, or a specific X509 or PEM error code
135 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
137#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200138
Hanno Becker02a21932019-06-10 15:08:43 +0100139#if !defined(MBEDTLS_X509_REMOVE_INFO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200140/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200141 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200142 *
143 * \param buf Buffer to write to
144 * \param size Maximum size of buffer
145 * \param prefix A line prefix
146 * \param crl The X509 CRL to represent
147 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200148 * \return The length of the string written (not including the
149 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200150 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
152 const mbedtls_x509_crl *crl );
Hanno Beckerc6043f22019-06-14 17:21:24 +0100153#endif /* !MBEDTLS_X509_REMOVE_INFO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200154
155/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200156 * \brief Initialize a CRL (chain)
157 *
158 * \param crl CRL chain to initialize
159 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200161
162/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200163 * \brief Unallocate all CRL data
164 *
165 * \param crl CRL chain to free
166 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200168
169/* \} name */
170/* \} addtogroup x509_module */
171
172#ifdef __cplusplus
173}
174#endif
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#endif /* mbedtls_x509_crl.h */