blob: 2ade47c89db3809cd98e8b4758757dcf1157e9c7 [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úti44bfbe32020-08-19 16:54:51 +02007 * Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020027 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
Paul Bakker7c6b2c32013-09-16 13:49:26 +020048 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#ifndef MBEDTLS_X509_CRL_H
50#define MBEDTLS_X509_CRL_H
Paul Bakker7c6b2c32013-09-16 13:49:26 +020051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020053#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020054#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020057
58#include "x509.h"
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64/**
65 * \addtogroup x509_module
66 * \{ */
67
68/**
69 * \name Structures and functions for parsing CRLs
70 * \{
71 */
72
73/**
74 * Certificate revocation list entry.
75 * Contains the CA-specific serial numbers and revocation dates.
76 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077typedef struct mbedtls_x509_crl_entry
Paul Bakker7c6b2c32013-09-16 13:49:26 +020078{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 mbedtls_x509_buf raw;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020080
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081 mbedtls_x509_buf serial;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083 mbedtls_x509_time revocation_date;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020084
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085 mbedtls_x509_buf entry_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087 struct mbedtls_x509_crl_entry *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020088}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089mbedtls_x509_crl_entry;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020090
91/**
92 * Certificate revocation list structure.
93 * Every CRL may have multiple entries.
94 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095typedef struct mbedtls_x509_crl
Paul Bakker7c6b2c32013-09-16 13:49:26 +020096{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
98 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020099
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +0200100 int version; /**< CRL version (1=v1, 2=v2) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101 mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200102
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200104
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107 mbedtls_x509_time this_update;
108 mbedtls_x509_time next_update;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200109
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110 mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112 mbedtls_x509_buf crl_ext;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200113
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114 mbedtls_x509_buf sig_oid2;
115 mbedtls_x509_buf sig;
116 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
117 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
118 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 +0200119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120 struct mbedtls_x509_crl *next;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200121}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122mbedtls_x509_crl;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200123
124/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100125 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200126 *
127 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100128 * \param buf buffer holding the CRL data in DER format
Simon Butcher5b331b92016-01-03 16:14:14 +0000129 * \param buflen size of the buffer
Manuel Pégourié-Gonnardddbb1662016-01-04 12:40:15 +0100130 * (including the terminating null byte for PEM data)
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100131 *
132 * \return 0 if successful, or a specific X509 or PEM error code
133 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100135 const unsigned char *buf, size_t buflen );
136/**
137 * \brief Parse one or more CRLs and append them to the chained list
138 *
Antonin Décimo8fd91562019-01-23 15:24:37 +0100139 * \note Multiple CRLs are accepted only if using PEM format
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100140 *
141 * \param chain points to the start of the chain
142 * \param buf buffer holding the CRL data in PEM or DER format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200143 * \param buflen size of the buffer
Manuel Pégourié-Gonnard43b37cb2015-05-12 11:20:10 +0200144 * (including the terminating null byte for PEM data)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200145 *
146 * \return 0 if successful, or a specific X509 or PEM error code
147 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200149
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200151/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100152 * \brief Load one or more CRLs and append them to the chained list
153 *
Antonin Décimo8fd91562019-01-23 15:24:37 +0100154 * \note Multiple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200155 *
156 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100157 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200158 *
159 * \return 0 if successful, or a specific X509 or PEM error code
160 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
162#endif /* MBEDTLS_FS_IO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200163
164/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200165 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200166 *
167 * \param buf Buffer to write to
168 * \param size Maximum size of buffer
169 * \param prefix A line prefix
170 * \param crl The X509 CRL to represent
171 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200172 * \return The length of the string written (not including the
173 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200174 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
176 const mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200177
178/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200179 * \brief Initialize a CRL (chain)
180 *
181 * \param crl CRL chain to initialize
182 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200184
185/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200186 * \brief Unallocate all CRL data
187 *
188 * \param crl CRL chain to free
189 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200191
192/* \} name */
193/* \} addtogroup x509_module */
194
195#ifdef __cplusplus
196}
197#endif
198
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199#endif /* mbedtls_x509_crl.h */