| 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 | 7ff7965 | 2023-11-03 12:04:52 +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 | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 12 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 13 | #if !defined(MBEDTLS_CONFIG_FILE) | 
| Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 14 | #include "mbedtls/config.h" | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 15 | #else | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 16 | #include MBEDTLS_CONFIG_FILE | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 17 | #endif | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 18 |  | 
| Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 19 | #include "mbedtls/x509.h" | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 20 |  | 
|  | 21 | #ifdef __cplusplus | 
|  | 22 | extern "C" { | 
|  | 23 | #endif | 
|  | 24 |  | 
|  | 25 | /** | 
|  | 26 | * \addtogroup x509_module | 
|  | 27 | * \{ */ | 
|  | 28 |  | 
|  | 29 | /** | 
|  | 30 | * \name Structures and functions for parsing CRLs | 
|  | 31 | * \{ | 
|  | 32 | */ | 
|  | 33 |  | 
|  | 34 | /** | 
|  | 35 | * Certificate revocation list entry. | 
|  | 36 | * Contains the CA-specific serial numbers and revocation dates. | 
|  | 37 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 38 | typedef struct mbedtls_x509_crl_entry { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 39 | mbedtls_x509_buf raw; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 40 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 41 | mbedtls_x509_buf serial; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 42 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | mbedtls_x509_time revocation_date; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 44 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 45 | mbedtls_x509_buf entry_ext; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 46 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 47 | struct mbedtls_x509_crl_entry *next; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 48 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | mbedtls_x509_crl_entry; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 50 |  | 
|  | 51 | /** | 
|  | 52 | * Certificate revocation list structure. | 
|  | 53 | * Every CRL may have multiple entries. | 
|  | 54 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 55 | typedef struct mbedtls_x509_crl { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | mbedtls_x509_buf raw;           /**< The raw certificate data (DER). */ | 
|  | 57 | 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] | 58 |  | 
| Manuel Pégourié-Gonnard | f4e1b64 | 2014-06-19 11:39:46 +0200 | [diff] [blame] | 59 | int version;            /**< CRL version (1=v1, 2=v2) */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | mbedtls_x509_buf sig_oid;       /**< CRL signature type identifier */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 61 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | mbedtls_x509_buf issuer_raw;    /**< The raw issuer data (DER). */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 63 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 64 | mbedtls_x509_name issuer;       /**< The parsed issuer data (named information object). */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 65 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | mbedtls_x509_time this_update; | 
|  | 67 | mbedtls_x509_time next_update; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 68 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | 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] | 70 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 71 | mbedtls_x509_buf crl_ext; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 72 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 73 | mbedtls_x509_buf sig_oid2; | 
|  | 74 | mbedtls_x509_buf sig; | 
|  | 75 | mbedtls_md_type_t sig_md;           /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */ | 
|  | 76 | mbedtls_pk_type_t sig_pk;           /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */ | 
|  | 77 | void *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] | 78 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 79 | struct mbedtls_x509_crl *next; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 80 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 81 | mbedtls_x509_crl; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 82 |  | 
|  | 83 | /** | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 84 | * \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] | 85 | * | 
| Gilles Peskine | 07ae208 | 2023-03-07 20:22:51 +0100 | [diff] [blame] | 86 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 87 | *                 subsystem must have been initialized by calling | 
|  | 88 | *                 psa_crypto_init() before calling this function. | 
|  | 89 | * | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 90 | * \param chain    points to the start of the chain | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 91 | * \param buf      buffer holding the CRL data in DER format | 
| Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 92 | * \param buflen   size of the buffer | 
| Manuel Pégourié-Gonnard | ddbb166 | 2016-01-04 12:40:15 +0100 | [diff] [blame] | 93 | *                 (including the terminating null byte for PEM data) | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 94 | * | 
|  | 95 | * \return         0 if successful, or a specific X509 or PEM error code | 
|  | 96 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 97 | int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain, | 
|  | 98 | const unsigned char *buf, size_t buflen); | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 99 | /** | 
|  | 100 | * \brief          Parse one or more CRLs and append them to the chained list | 
|  | 101 | * | 
| Antonin Décimo | 36e89b5 | 2019-01-23 15:24:37 +0100 | [diff] [blame] | 102 | * \note           Multiple CRLs are accepted only if using PEM format | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 103 | * | 
| Gilles Peskine | 07ae208 | 2023-03-07 20:22:51 +0100 | [diff] [blame] | 104 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 105 | *                 subsystem must have been initialized by calling | 
|  | 106 | *                 psa_crypto_init() before calling this function. | 
|  | 107 | * | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 108 | * \param chain    points to the start of the chain | 
|  | 109 | * \param buf      buffer holding the CRL data in PEM or DER format | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 110 | * \param buflen   size of the buffer | 
| Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 111 | *                 (including the terminating null byte for PEM data) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 112 | * | 
|  | 113 | * \return         0 if successful, or a specific X509 or PEM error code | 
|  | 114 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 115 | 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] | 116 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 117 | #if defined(MBEDTLS_FS_IO) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 118 | /** | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 119 | * \brief          Load one or more CRLs and append them to the chained list | 
|  | 120 | * | 
| Antonin Décimo | 36e89b5 | 2019-01-23 15:24:37 +0100 | [diff] [blame] | 121 | * \note           Multiple CRLs are accepted only if using PEM format | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 122 | * | 
| Gilles Peskine | 07ae208 | 2023-03-07 20:22:51 +0100 | [diff] [blame] | 123 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 124 | *                 subsystem must have been initialized by calling | 
|  | 125 | *                 psa_crypto_init() before calling this function. | 
|  | 126 | * | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 127 | * \param chain    points to the start of the chain | 
| Manuel Pégourié-Gonnard | 426d4ae | 2014-11-19 16:58:28 +0100 | [diff] [blame] | 128 | * \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] | 129 | * | 
|  | 130 | * \return         0 if successful, or a specific X509 or PEM error code | 
|  | 131 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 132 | 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] | 133 | #endif /* MBEDTLS_FS_IO */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 134 |  | 
|  | 135 | /** | 
| Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 136 | * \brief          Returns an informational string about the CRL. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 137 | * | 
|  | 138 | * \param buf      Buffer to write to | 
|  | 139 | * \param size     Maximum size of buffer | 
|  | 140 | * \param prefix   A line prefix | 
|  | 141 | * \param crl      The X509 CRL to represent | 
|  | 142 | * | 
| Manuel Pégourié-Gonnard | e244f9f | 2015-06-23 12:10:45 +0200 | [diff] [blame] | 143 | * \return         The length of the string written (not including the | 
|  | 144 | *                 terminated nul byte), or a negative error code. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 145 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 146 | int mbedtls_x509_crl_info(char *buf, size_t size, const char *prefix, | 
|  | 147 | const mbedtls_x509_crl *crl); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 148 |  | 
|  | 149 | /** | 
| Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 150 | * \brief          Initialize a CRL (chain) | 
|  | 151 | * | 
|  | 152 | * \param crl      CRL chain to initialize | 
|  | 153 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 154 | void mbedtls_x509_crl_init(mbedtls_x509_crl *crl); | 
| Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 155 |  | 
|  | 156 | /** | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 157 | * \brief          Unallocate all CRL data | 
|  | 158 | * | 
|  | 159 | * \param crl      CRL chain to free | 
|  | 160 | */ | 
| Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 161 | void mbedtls_x509_crl_free(mbedtls_x509_crl *crl); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 162 |  | 
| Andrzej Kurek | 73afe27 | 2022-01-24 10:31:06 -0500 | [diff] [blame] | 163 | /** \} name Structures and functions for parsing CRLs */ | 
|  | 164 | /** \} addtogroup x509_module */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 165 |  | 
|  | 166 | #ifdef __cplusplus | 
|  | 167 | } | 
|  | 168 | #endif | 
|  | 169 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 170 | #endif /* mbedtls_x509_crl.h */ |