Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1 | /** |
Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 2 | * \file x509_crl.h |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 3 | * |
| 4 | * \brief X.509 certificate revocation list parsing |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 9 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 10 | #ifndef MBEDTLS_X509_CRL_H |
| 11 | #define MBEDTLS_X509_CRL_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 12 | #include "mbedtls/private_access.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 13 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 14 | #include "mbedtls/build_info.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 15 | |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 16 | #include "mbedtls/x509.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "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 Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 34 | * |
| 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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 38 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 39 | typedef struct mbedtls_x509_crl_entry { |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 40 | /** 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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 52 | |
Gilles Peskine | ca93995 | 2021-08-31 23:18:07 +0200 | [diff] [blame] | 53 | /** 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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 57 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | mbedtls_x509_crl_entry; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Certificate revocation list structure. |
| 62 | * Every CRL may have multiple entries. |
| 63 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 64 | typedef struct mbedtls_x509_crl { |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 65 | 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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 67 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 68 | int version; /**< CRL version (1=v1, 2=v2) */ |
| 69 | mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 70 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 71 | mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 72 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 73 | mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 74 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 75 | mbedtls_x509_time this_update; |
| 76 | mbedtls_x509_time next_update; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 77 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 78 | mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 79 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 80 | mbedtls_x509_buf crl_ext; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 81 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 82 | 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 */ |
| 86 | void *MBEDTLS_PRIVATE(sig_opts); /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 87 | |
Gilles Peskine | ca93995 | 2021-08-31 23:18:07 +0200 | [diff] [blame] | 88 | /** Next element in the linked list of CRL. |
| 89 | * \p NULL indicates the end of the list. |
| 90 | * Do not modify this field directly. */ |
| 91 | struct mbedtls_x509_crl *next; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 92 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | mbedtls_x509_crl; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 94 | |
| 95 | /** |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 96 | * \brief Parse a DER-encoded CRL and append it to the chained list |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 97 | * |
Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 98 | * \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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 102 | * \param chain points to the start of the chain |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 103 | * \param buf buffer holding the CRL data in DER format |
Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 104 | * \param buflen size of the buffer |
Manuel Pégourié-Gonnard | ddbb166 | 2016-01-04 12:40:15 +0100 | [diff] [blame] | 105 | * (including the terminating null byte for PEM data) |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 106 | * |
| 107 | * \return 0 if successful, or a specific X509 or PEM error code |
| 108 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 109 | int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain, |
| 110 | const unsigned char *buf, size_t buflen); |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 111 | /** |
| 112 | * \brief Parse one or more CRLs and append them to the chained list |
| 113 | * |
Antonin Décimo | 36e89b5 | 2019-01-23 15:24:37 +0100 | [diff] [blame] | 114 | * \note Multiple CRLs are accepted only if using PEM format |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 115 | * |
Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 116 | * \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é-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 120 | * \param chain points to the start of the chain |
| 121 | * \param buf buffer holding the CRL data in PEM or DER format |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 122 | * \param buflen size of the buffer |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 123 | * (including the terminating null byte for PEM data) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 124 | * |
| 125 | * \return 0 if successful, or a specific X509 or PEM error code |
| 126 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 127 | int mbedtls_x509_crl_parse(mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 128 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 129 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 130 | /** |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 131 | * \brief Load one or more CRLs and append them to the chained list |
| 132 | * |
Antonin Décimo | 36e89b5 | 2019-01-23 15:24:37 +0100 | [diff] [blame] | 133 | * \note Multiple CRLs are accepted only if using PEM format |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 134 | * |
Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 135 | * \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 Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 139 | * \param chain points to the start of the chain |
Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 140 | * \param path filename to read the CRLs from (in PEM or DER encoding) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 141 | * |
| 142 | * \return 0 if successful, or a specific X509 or PEM error code |
| 143 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 144 | int mbedtls_x509_crl_parse_file(mbedtls_x509_crl *chain, const char *path); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 145 | #endif /* MBEDTLS_FS_IO */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 146 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 147 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 148 | /** |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 149 | * \brief Returns an informational string about the CRL. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 150 | * |
| 151 | * \param buf Buffer to write to |
| 152 | * \param size Maximum size of buffer |
| 153 | * \param prefix A line prefix |
| 154 | * \param crl The X509 CRL to represent |
| 155 | * |
Manuel Pégourié-Gonnard | e244f9f | 2015-06-23 12:10:45 +0200 | [diff] [blame] | 156 | * \return The length of the string written (not including the |
| 157 | * terminated nul byte), or a negative error code. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 158 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 159 | int mbedtls_x509_crl_info(char *buf, size_t size, const char *prefix, |
| 160 | const mbedtls_x509_crl *crl); |
Hanno Becker | 88c2bf3 | 2019-06-14 17:21:24 +0100 | [diff] [blame] | 161 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 162 | |
| 163 | /** |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 164 | * \brief Initialize a CRL (chain) |
| 165 | * |
| 166 | * \param crl CRL chain to initialize |
| 167 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 168 | void mbedtls_x509_crl_init(mbedtls_x509_crl *crl); |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 169 | |
| 170 | /** |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 171 | * \brief Unallocate all CRL data |
| 172 | * |
| 173 | * \param crl CRL chain to free |
| 174 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 175 | void mbedtls_x509_crl_free(mbedtls_x509_crl *crl); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 176 | |
Andrzej Kurek | 38d4fdd | 2021-12-28 16:22:52 +0100 | [diff] [blame] | 177 | /** \} name Structures and functions for parsing CRLs */ |
| 178 | /** \} addtogroup x509_module */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 179 | |
| 180 | #ifdef __cplusplus |
| 181 | } |
| 182 | #endif |
| 183 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 184 | #endif /* mbedtls_x509_crl.h */ |