blob: e59d16502dd786b1c564b2504d0d80177b6ad26c [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
Dave Rodgman16799db2023-11-02 19:47:20 +00008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker7c6b2c32013-09-16 13:49:26 +02009 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#ifndef MBEDTLS_X509_CRL_H
11#define MBEDTLS_X509_CRL_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020012#include "mbedtls/private_access.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020013
Bence Szépkútic662b362021-05-27 11:25:03 +020014#include "mbedtls/build_info.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020015
Jaeden Amero6609aef2019-07-04 20:01:14 +010016#include "mbedtls/x509.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020017
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * \addtogroup x509_module
24 * \{ */
25
26/**
27 * \name Structures and functions for parsing CRLs
28 * \{
29 */
30
31/**
32 * Certificate revocation list entry.
33 * Contains the CA-specific serial numbers and revocation dates.
Gilles Peskine842edf42021-08-04 21:56:10 +020034 *
35 * Some fields of this structure are publicly readable. Do not modify
36 * them except via Mbed TLS library functions: the effect of modifying
37 * those fields or the data that those fields points to is unspecified.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020038 */
Gilles Peskine449bd832023-01-11 14:50:10 +010039typedef struct mbedtls_x509_crl_entry {
Gilles Peskine842edf42021-08-04 21:56:10 +020040 /** Direct access to the whole entry inside the containing buffer. */
41 mbedtls_x509_buf raw;
42 /** The serial number of the revoked certificate. */
43 mbedtls_x509_buf serial;
44 /** The revocation date of this entry. */
45 mbedtls_x509_time revocation_date;
46 /** Direct access to the list of CRL entry extensions
47 * (an ASN.1 constructed sequence).
48 *
49 * If there are no extensions, `entry_ext.len == 0` and
50 * `entry_ext.p == NULL`. */
51 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052
Gilles Peskineca939952021-08-31 23:18:07 +020053 /** Next element in the linked list of entries.
54 * \p NULL indicates the end of the list.
55 * Do not modify this field directly. */
56 struct mbedtls_x509_crl_entry *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020057}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020059
60/**
61 * Certificate revocation list structure.
62 * Every CRL may have multiple entries.
63 */
Gilles Peskine449bd832023-01-11 14:50:10 +010064typedef struct mbedtls_x509_crl {
Gilles Peskine842edf42021-08-04 21:56:10 +020065 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
66 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020067
Gilles Peskine842edf42021-08-04 21:56:10 +020068 int version; /**< CRL version (1=v1, 2=v2) */
69 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070
Gilles Peskine842edf42021-08-04 21:56:10 +020071 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020072
Gilles Peskine842edf42021-08-04 21:56:10 +020073 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020074
Gilles Peskine842edf42021-08-04 21:56:10 +020075 mbedtls_x509_time this_update;
76 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020077
Gilles Peskine842edf42021-08-04 21:56:10 +020078 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020079
Gilles Peskine842edf42021-08-04 21:56:10 +020080 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020081
Mateusz Starzyk846f0212021-05-19 19:44:07 +020082 mbedtls_x509_buf MBEDTLS_PRIVATE(sig_oid2);
83 mbedtls_x509_buf MBEDTLS_PRIVATE(sig);
84 mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
85 mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020086
Gilles Peskineca939952021-08-31 23:18:07 +020087 /** Next element in the linked list of CRL.
88 * \p NULL indicates the end of the list.
89 * Do not modify this field directly. */
90 struct mbedtls_x509_crl *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020091}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020093
94/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010095 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +020096 *
Janos Follath582ecd02024-11-19 16:17:07 +000097 * \note The PSA crypto subsystem must have been initialized by
98 * calling psa_crypto_init() before calling this function.
Gilles Peskine5b7e1642022-08-04 23:44:59 +020099 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100101 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +0000102 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +0100103 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100104 *
105 * \return 0 if successful, or a specific X509 or PEM error code
106 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100107int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain,
108 const unsigned char *buf, size_t buflen);
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100109/**
110 * \brief Parse one or more CRLs and append them to the chained list
111 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100112 * \note Multiple CRLs are accepted only if using PEM format
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100113 *
Janos Follath582ecd02024-11-19 16:17:07 +0000114 * \note The PSA crypto subsystem must have been initialized by
115 * calling psa_crypto_init() before calling this function.
Gilles Peskine5b7e1642022-08-04 23:44:59 +0200116 *
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100117 * \param chain points to the start of the chain
118 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200119 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200120 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200121 *
122 * \return 0 if successful, or a specific X509 or PEM error code
123 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100124int mbedtls_x509_crl_parse(mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200127/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100128 * \brief Load one or more CRLs and append them to the chained list
129 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100130 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200131 *
Janos Follath582ecd02024-11-19 16:17:07 +0000132 * \note The PSA crypto subsystem must have been initialized by
133 * calling psa_crypto_init() before calling this function.
Gilles Peskine5b7e1642022-08-04 23:44:59 +0200134 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200135 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100136 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200137 *
138 * \return 0 if successful, or a specific X509 or PEM error code
139 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100140int mbedtls_x509_crl_parse_file(mbedtls_x509_crl *chain, const char *path);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200142
Hanno Becker612a2f12020-10-09 09:19:39 +0100143#if !defined(MBEDTLS_X509_REMOVE_INFO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200144/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200145 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200146 *
147 * \param buf Buffer to write to
148 * \param size Maximum size of buffer
149 * \param prefix A line prefix
150 * \param crl The X509 CRL to represent
151 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200152 * \return The length of the string written (not including the
153 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200154 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100155int mbedtls_x509_crl_info(char *buf, size_t size, const char *prefix,
156 const mbedtls_x509_crl *crl);
Hanno Becker88c2bf32019-06-14 17:21:24 +0100157#endif /* !MBEDTLS_X509_REMOVE_INFO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200158
159/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200160 * \brief Initialize a CRL (chain)
161 *
162 * \param crl CRL chain to initialize
163 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100164void mbedtls_x509_crl_init(mbedtls_x509_crl *crl);
Paul Bakker369d2eb2013-09-18 11:58:25 +0200165
166/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200167 * \brief Unallocate all CRL data
168 *
169 * \param crl CRL chain to free
170 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100171void mbedtls_x509_crl_free(mbedtls_x509_crl *crl);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200172
Andrzej Kurek38d4fdd2021-12-28 16:22:52 +0100173/** \} name Structures and functions for parsing CRLs */
174/** \} addtogroup x509_module */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200175
176#ifdef __cplusplus
177}
178#endif
179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#endif /* mbedtls_x509_crl.h */