blob: 440da12166cef6ce8cc23cfcd99ae28b1989421f [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
Mateusz Starzyk846f0212021-05-19 19:44:07 +020024#include "mbedtls/private_access.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero6609aef2019-07-04 20:01:14 +010027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020031
Jaeden Amero6609aef2019-07-04 20:01:14 +010032#include "mbedtls/x509.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020033
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * \addtogroup x509_module
40 * \{ */
41
42/**
43 * \name Structures and functions for parsing CRLs
44 * \{
45 */
46
47/**
48 * Certificate revocation list entry.
49 * Contains the CA-specific serial numbers and revocation dates.
50 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051typedef struct mbedtls_x509_crl_entry
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020053 mbedtls_x509_buf MBEDTLS_PRIVATE(raw);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020054
Mateusz Starzyk846f0212021-05-19 19:44:07 +020055 mbedtls_x509_buf MBEDTLS_PRIVATE(serial);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020056
Mateusz Starzyk846f0212021-05-19 19:44:07 +020057 mbedtls_x509_time MBEDTLS_PRIVATE(revocation_date);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020058
Mateusz Starzyk846f0212021-05-19 19:44:07 +020059 mbedtls_x509_buf MBEDTLS_PRIVATE(entry_ext);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020060
Mateusz Starzyk846f0212021-05-19 19:44:07 +020061 struct mbedtls_x509_crl_entry *MBEDTLS_PRIVATE(next);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020062}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020064
65/**
66 * Certificate revocation list structure.
67 * Every CRL may have multiple entries.
68 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069typedef struct mbedtls_x509_crl
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020071 mbedtls_x509_buf MBEDTLS_PRIVATE(raw); /**< The raw certificate data (DER). */
72 mbedtls_x509_buf MBEDTLS_PRIVATE(tbs); /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020073
Mateusz Starzyk846f0212021-05-19 19:44:07 +020074 int MBEDTLS_PRIVATE(version); /**< CRL version (1=v1, 2=v2) */
75 mbedtls_x509_buf MBEDTLS_PRIVATE(sig_oid); /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020076
Mateusz Starzyk846f0212021-05-19 19:44:07 +020077 mbedtls_x509_buf MBEDTLS_PRIVATE(issuer_raw); /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020078
Mateusz Starzyk846f0212021-05-19 19:44:07 +020079 mbedtls_x509_name MBEDTLS_PRIVATE(issuer); /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020080
Mateusz Starzyk846f0212021-05-19 19:44:07 +020081 mbedtls_x509_time MBEDTLS_PRIVATE(this_update);
82 mbedtls_x509_time MBEDTLS_PRIVATE(next_update);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020083
Mateusz Starzyk846f0212021-05-19 19:44:07 +020084 mbedtls_x509_crl_entry MBEDTLS_PRIVATE(entry); /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020085
Mateusz Starzyk846f0212021-05-19 19:44:07 +020086 mbedtls_x509_buf MBEDTLS_PRIVATE(crl_ext);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020087
Mateusz Starzyk846f0212021-05-19 19:44:07 +020088 mbedtls_x509_buf MBEDTLS_PRIVATE(sig_oid2);
89 mbedtls_x509_buf MBEDTLS_PRIVATE(sig);
90 mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
91 mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
92 void *MBEDTLS_PRIVATE(sig_opts); /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020093
Mateusz Starzyk846f0212021-05-19 19:44:07 +020094 struct mbedtls_x509_crl *MBEDTLS_PRIVATE(next);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020095}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020097
98/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +010099 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100 *
101 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100102 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +0000103 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +0100104 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100105 *
106 * \return 0 if successful, or a specific X509 or PEM error code
107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100109 const unsigned char *buf, size_t buflen );
110/**
111 * \brief Parse one or more CRLs and append them to the chained list
112 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100113 * \note Multiple CRLs are accepted only if using PEM format
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100114 *
115 * \param chain points to the start of the chain
116 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200117 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200118 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200119 *
120 * \return 0 if successful, or a specific X509 or PEM error code
121 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200125/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100126 * \brief Load one or more CRLs and append them to the chained list
127 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100128 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200129 *
130 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100131 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200132 *
133 * \return 0 if successful, or a specific X509 or PEM error code
134 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
136#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200137
Hanno Becker612a2f12020-10-09 09:19:39 +0100138#if !defined(MBEDTLS_X509_REMOVE_INFO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200139/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200140 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200141 *
142 * \param buf Buffer to write to
143 * \param size Maximum size of buffer
144 * \param prefix A line prefix
145 * \param crl The X509 CRL to represent
146 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200147 * \return The length of the string written (not including the
148 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200149 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
151 const mbedtls_x509_crl *crl );
Hanno Becker88c2bf32019-06-14 17:21:24 +0100152#endif /* !MBEDTLS_X509_REMOVE_INFO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200153
154/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200155 * \brief Initialize a CRL (chain)
156 *
157 * \param crl CRL chain to initialize
158 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200160
161/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200162 * \brief Unallocate all CRL data
163 *
164 * \param crl CRL chain to free
165 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200167
168/* \} name */
169/* \} addtogroup x509_module */
170
171#ifdef __cplusplus
172}
173#endif
174
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175#endif /* mbedtls_x509_crl.h */