4 * \brief X.509 certificate revocation list parsing
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef MBEDTLS_X509_CRL_H
23 #define MBEDTLS_X509_CRL_H
25 #if !defined(MBEDTLS_CONFIG_FILE)
26 #include "mbedtls/config.h"
28 #include MBEDTLS_CONFIG_FILE
31 #include "mbedtls/x509.h"
38 * \addtogroup x509_module
42 * \name Structures and functions for parsing CRLs
47 * Certificate revocation list entry.
48 * Contains the CA-specific serial numbers and revocation dates.
50 typedef struct mbedtls_x509_crl_entry
{
53 mbedtls_x509_buf serial
;
55 mbedtls_x509_time revocation_date
;
57 mbedtls_x509_buf entry_ext
;
59 struct mbedtls_x509_crl_entry
*next
;
61 mbedtls_x509_crl_entry
;
64 * Certificate revocation list structure.
65 * Every CRL may have multiple entries.
67 typedef struct mbedtls_x509_crl
{
68 mbedtls_x509_buf raw
; /**< The raw certificate data (DER). */
69 mbedtls_x509_buf tbs
; /**< The raw certificate body (DER). The part that is To Be Signed. */
71 int version
; /**< CRL version (1=v1, 2=v2) */
72 mbedtls_x509_buf sig_oid
; /**< CRL signature type identifier */
74 mbedtls_x509_buf issuer_raw
; /**< The raw issuer data (DER). */
76 mbedtls_x509_name issuer
; /**< The parsed issuer data (named information object). */
78 mbedtls_x509_time this_update
;
79 mbedtls_x509_time next_update
;
81 mbedtls_x509_crl_entry entry
; /**< The CRL entries containing the certificate revocation times for this CA. */
83 mbedtls_x509_buf crl_ext
;
85 mbedtls_x509_buf sig_oid2
;
87 mbedtls_md_type_t sig_md
; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
88 mbedtls_pk_type_t sig_pk
; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
89 void *sig_opts
; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
91 struct mbedtls_x509_crl
*next
;
96 * \brief Parse a DER-encoded CRL and append it to the chained list
98 * \param chain points to the start of the chain
99 * \param buf buffer holding the CRL data in DER format
100 * \param buflen size of the buffer
101 * (including the terminating null byte for PEM data)
103 * \return 0 if successful, or a specific X509 or PEM error code
105 int mbedtls_x509_crl_parse_der(mbedtls_x509_crl
*chain
,
106 const unsigned char *buf
, size_t buflen
);
108 * \brief Parse one or more CRLs and append them to the chained list
110 * \note Multiple CRLs are accepted only if using PEM format
112 * \param chain points to the start of the chain
113 * \param buf buffer holding the CRL data in PEM or DER format
114 * \param buflen size of the buffer
115 * (including the terminating null byte for PEM data)
117 * \return 0 if successful, or a specific X509 or PEM error code
119 int mbedtls_x509_crl_parse(mbedtls_x509_crl
*chain
, const unsigned char *buf
, size_t buflen
);
121 #if defined(MBEDTLS_FS_IO)
123 * \brief Load one or more CRLs and append them to the chained list
125 * \note Multiple CRLs are accepted only if using PEM format
127 * \param chain points to the start of the chain
128 * \param path filename to read the CRLs from (in PEM or DER encoding)
130 * \return 0 if successful, or a specific X509 or PEM error code
132 int mbedtls_x509_crl_parse_file(mbedtls_x509_crl
*chain
, const char *path
);
133 #endif /* MBEDTLS_FS_IO */
136 * \brief Returns an informational string about the CRL.
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
143 * \return The length of the string written (not including the
144 * terminated nul byte), or a negative error code.
146 int mbedtls_x509_crl_info(char *buf
, size_t size
, const char *prefix
,
147 const mbedtls_x509_crl
*crl
);
150 * \brief Initialize a CRL (chain)
152 * \param crl CRL chain to initialize
154 void mbedtls_x509_crl_init(mbedtls_x509_crl
*crl
);
157 * \brief Unallocate all CRL data
159 * \param crl CRL chain to free
161 void mbedtls_x509_crl_free(mbedtls_x509_crl
*crl
);
164 /* \} addtogroup x509_module */
170 #endif /* mbedtls_x509_crl.h */