blob: 1405021407111a0bc8bf6ba0978204132a761d4f [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/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
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é-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#ifndef MBEDTLS_X509_CRL_H
23#define MBEDTLS_X509_CRL_H
Paul Bakker7c6b2c32013-09-16 13:49:26 +020024
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero6609aef2019-07-04 20:01:14 +010026#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020030
Jaeden Amero6609aef2019-07-04 20:01:14 +010031#include "mbedtls/x509.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020032
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/**
38 * \addtogroup x509_module
39 * \{ */
40
41/**
42 * \name Structures and functions for parsing CRLs
43 * \{
44 */
45
46/**
47 * Certificate revocation list entry.
48 * Contains the CA-specific serial numbers and revocation dates.
49 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010050typedef struct mbedtls_x509_crl_entry {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051 mbedtls_x509_buf raw;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053 mbedtls_x509_buf serial;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055 mbedtls_x509_time revocation_date;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059 struct mbedtls_x509_crl_entry *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020060}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020062
63/**
64 * Certificate revocation list structure.
65 * Every CRL may have multiple entries.
66 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010067typedef struct mbedtls_x509_crl {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
69 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +020071 int version; /**< CRL version (1=v1, 2=v2) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020073
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020075
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020077
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078 mbedtls_x509_time this_update;
79 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020080
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020084
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085 mbedtls_x509_buf sig_oid2;
86 mbedtls_x509_buf sig;
87 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
88 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
89 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 +020090
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091 struct mbedtls_x509_crl *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020092}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020094
95/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010096 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +020097 *
Gilles Peskine07ae2082023-03-07 20:22:51 +010098 * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
99 * subsystem must have been initialized by calling
100 * psa_crypto_init() before calling this function.
101 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200102 * \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 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100109int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain,
110 const unsigned char *buf, size_t buflen);
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100111/**
112 * \brief Parse one or more CRLs and append them to the chained list
113 *
Antonin Décimo36e89b52019-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 *
Gilles Peskine07ae2082023-03-07 20:22:51 +0100116 * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
117 * subsystem must have been initialized by calling
118 * psa_crypto_init() before calling this function.
119 *
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100120 * \param chain points to the start of the chain
121 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200123 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200124 *
125 * \return 0 if successful, or a specific X509 or PEM error code
126 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100127int mbedtls_x509_crl_parse(mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200130/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100131 * \brief Load one or more CRLs and append them to the chained list
132 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100133 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200134 *
Gilles Peskine07ae2082023-03-07 20:22:51 +0100135 * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
136 * subsystem must have been initialized by calling
137 * psa_crypto_init() before calling this function.
138 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200139 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100140 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200141 *
142 * \return 0 if successful, or a specific X509 or PEM error code
143 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100144int mbedtls_x509_crl_parse_file(mbedtls_x509_crl *chain, const char *path);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200146
147/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200148 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200149 *
150 * \param buf Buffer to write to
151 * \param size Maximum size of buffer
152 * \param prefix A line prefix
153 * \param crl The X509 CRL to represent
154 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200155 * \return The length of the string written (not including the
156 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200157 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100158int mbedtls_x509_crl_info(char *buf, size_t size, const char *prefix,
159 const mbedtls_x509_crl *crl);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200160
161/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200162 * \brief Initialize a CRL (chain)
163 *
164 * \param crl CRL chain to initialize
165 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100166void mbedtls_x509_crl_init(mbedtls_x509_crl *crl);
Paul Bakker369d2eb2013-09-18 11:58:25 +0200167
168/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200169 * \brief Unallocate all CRL data
170 *
171 * \param crl CRL chain to free
172 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100173void mbedtls_x509_crl_free(mbedtls_x509_crl *crl);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200174
Andrzej Kurek73afe272022-01-24 10:31:06 -0500175/** \} name Structures and functions for parsing CRLs */
176/** \} addtogroup x509_module */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200177
178#ifdef __cplusplus
179}
180#endif
181
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200182#endif /* mbedtls_x509_crl.h */