blob: 9f755f8535c596c7054f4c91d8b41a7a0b92d09e [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 Rodgman7ff79652023-11-03 12:04:52 +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
Paul Bakker7c6b2c32013-09-16 13:49:26 +020012
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020013#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero6609aef2019-07-04 20:01:14 +010014#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020015#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020016#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020017#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020018
Jaeden Amero6609aef2019-07-04 20:01:14 +010019#include "mbedtls/x509.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020020
21#ifdef __cplusplus
22extern "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 Peskine1b6c09a2023-01-11 14:52:35 +010038typedef struct mbedtls_x509_crl_entry {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039 mbedtls_x509_buf raw;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020040
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041 mbedtls_x509_buf serial;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020042
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043 mbedtls_x509_time revocation_date;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020044
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020046
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047 struct mbedtls_x509_crl_entry *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020048}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020050
51/**
52 * Certificate revocation list structure.
53 * Every CRL may have multiple entries.
54 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010055typedef struct mbedtls_x509_crl {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056 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 Bakker7c6b2c32013-09-16 13:49:26 +020058
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +020059 int version; /**< CRL version (1=v1, 2=v2) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020061
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020063
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020065
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066 mbedtls_x509_time this_update;
67 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020068
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020072
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073 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 Bakker7c6b2c32013-09-16 13:49:26 +020078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 struct mbedtls_x509_crl *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020080}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020082
83/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010084 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +020085 *
Gilles Peskine07ae2082023-03-07 20:22:51 +010086 * \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 Bakker7c6b2c32013-09-16 13:49:26 +020090 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010091 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +000092 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +010093 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010094 *
95 * \return 0 if successful, or a specific X509 or PEM error code
96 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010097int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain,
98 const unsigned char *buf, size_t buflen);
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010099/**
100 * \brief Parse one or more CRLs and append them to the chained list
101 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100102 * \note Multiple CRLs are accepted only if using PEM format
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100103 *
Gilles Peskine07ae2082023-03-07 20:22:51 +0100104 * \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é-Gonnard426d4ae2014-11-19 16:58:28 +0100108 * \param chain points to the start of the chain
109 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200110 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200111 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200112 *
113 * \return 0 if successful, or a specific X509 or PEM error code
114 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100115int mbedtls_x509_crl_parse(mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200116
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200118/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100119 * \brief Load one or more CRLs and append them to the chained list
120 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100121 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122 *
Gilles Peskine07ae2082023-03-07 20:22:51 +0100123 * \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 Bakker7c6b2c32013-09-16 13:49:26 +0200127 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100128 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200129 *
130 * \return 0 if successful, or a specific X509 or PEM error code
131 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100132int mbedtls_x509_crl_parse_file(mbedtls_x509_crl *chain, const char *path);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200134
135/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200136 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200137 *
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é-Gonnarde244f9f2015-06-23 12:10:45 +0200143 * \return The length of the string written (not including the
144 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200145 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100146int mbedtls_x509_crl_info(char *buf, size_t size, const char *prefix,
147 const mbedtls_x509_crl *crl);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200148
149/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200150 * \brief Initialize a CRL (chain)
151 *
152 * \param crl CRL chain to initialize
153 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100154void mbedtls_x509_crl_init(mbedtls_x509_crl *crl);
Paul Bakker369d2eb2013-09-18 11:58:25 +0200155
156/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200157 * \brief Unallocate all CRL data
158 *
159 * \param crl CRL chain to free
160 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100161void mbedtls_x509_crl_free(mbedtls_x509_crl *crl);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200162
Andrzej Kurek73afe272022-01-24 10:31:06 -0500163/** \} name Structures and functions for parsing CRLs */
164/** \} addtogroup x509_module */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200165
166#ifdef __cplusplus
167}
168#endif
169
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170#endif /* mbedtls_x509_crl.h */