blob: f65e9847ba7007acca5431841872cd33a80342d8 [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
Bence Szépkútic662b362021-05-27 11:25:03 +020026#include "mbedtls/build_info.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020027
Jaeden Amero6609aef2019-07-04 20:01:14 +010028#include "mbedtls/x509.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020029
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 * \addtogroup x509_module
36 * \{ */
37
38/**
39 * \name Structures and functions for parsing CRLs
40 * \{
41 */
42
43/**
44 * Certificate revocation list entry.
45 * Contains the CA-specific serial numbers and revocation dates.
Gilles Peskine842edf42021-08-04 21:56:10 +020046 *
47 * Some fields of this structure are publicly readable. Do not modify
48 * them except via Mbed TLS library functions: the effect of modifying
49 * those fields or the data that those fields points to is unspecified.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020050 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051typedef struct mbedtls_x509_crl_entry
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052{
Gilles Peskine842edf42021-08-04 21:56:10 +020053 /** Direct access to the whole entry inside the containing buffer. */
54 mbedtls_x509_buf raw;
55 /** The serial number of the revoked certificate. */
56 mbedtls_x509_buf serial;
57 /** The revocation date of this entry. */
58 mbedtls_x509_time revocation_date;
59 /** Direct access to the list of CRL entry extensions
60 * (an ASN.1 constructed sequence).
61 *
62 * If there are no extensions, `entry_ext.len == 0` and
63 * `entry_ext.p == NULL`. */
64 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020065
Mateusz Starzyk846f0212021-05-19 19:44:07 +020066 struct mbedtls_x509_crl_entry *MBEDTLS_PRIVATE(next);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020067}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020069
70/**
71 * Certificate revocation list structure.
72 * Every CRL may have multiple entries.
73 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074typedef struct mbedtls_x509_crl
Paul Bakker7c6b2c32013-09-16 13:49:26 +020075{
Gilles Peskine842edf42021-08-04 21:56:10 +020076 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
77 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020078
Gilles Peskine842edf42021-08-04 21:56:10 +020079 int version; /**< CRL version (1=v1, 2=v2) */
80 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020081
Gilles Peskine842edf42021-08-04 21:56:10 +020082 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020083
Gilles Peskine842edf42021-08-04 21:56:10 +020084 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020085
Gilles Peskine842edf42021-08-04 21:56:10 +020086 mbedtls_x509_time this_update;
87 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020088
Gilles Peskine842edf42021-08-04 21:56:10 +020089 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020090
Gilles Peskine842edf42021-08-04 21:56:10 +020091 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020092
Mateusz Starzyk846f0212021-05-19 19:44:07 +020093 mbedtls_x509_buf MBEDTLS_PRIVATE(sig_oid2);
94 mbedtls_x509_buf MBEDTLS_PRIVATE(sig);
95 mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
96 mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
97 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 +020098
Mateusz Starzyk846f0212021-05-19 19:44:07 +020099 struct mbedtls_x509_crl *MBEDTLS_PRIVATE(next);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200102
103/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100104 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200105 *
106 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100107 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +0000108 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +0100109 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100110 *
111 * \return 0 if successful, or a specific X509 or PEM error code
112 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100114 const unsigned char *buf, size_t buflen );
115/**
116 * \brief Parse one or more CRLs and append them to the chained list
117 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100118 * \note Multiple CRLs are accepted only if using PEM format
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100119 *
120 * \param chain points to the start of the chain
121 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200123 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200124 *
125 * \return 0 if successful, or a specific X509 or PEM error code
126 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200130/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100131 * \brief Load one or more CRLs and append them to the chained list
132 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100133 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200134 *
135 * \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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
141#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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155int 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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164void 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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200172
173/* \} name */
174/* \} addtogroup x509_module */
175
176#ifdef __cplusplus
177}
178#endif
179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#endif /* mbedtls_x509_crl.h */