1 /**
2  * \file x509_crl.h
3  *
4  * \brief X.509 certificate revocation list parsing
5  */
6 /*
7  *  Copyright The Mbed TLS Contributors
8  *  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:
15  *
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.
27  *
28  *  **********
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  *  **********
48  */
49 #ifndef MBEDTLS_X509_CRL_H
50 #define MBEDTLS_X509_CRL_H
51 
52 #if !defined(MBEDTLS_CONFIG_FILE)
53 #include "config.h"
54 #else
55 #include MBEDTLS_CONFIG_FILE
56 #endif
57 
58 #include "x509.h"
59 
60 #ifdef __cplusplus
61 extern "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  */
77 typedef struct mbedtls_x509_crl_entry
78 {
79     mbedtls_x509_buf raw;
80 
81     mbedtls_x509_buf serial;
82 
83     mbedtls_x509_time revocation_date;
84 
85     mbedtls_x509_buf entry_ext;
86 
87     struct mbedtls_x509_crl_entry *next;
88 }
89 mbedtls_x509_crl_entry;
90 
91 /**
92  * Certificate revocation list structure.
93  * Every CRL may have multiple entries.
94  */
95 typedef struct mbedtls_x509_crl
96 {
97     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. */
99 
100     int version;            /**< CRL version (1=v1, 2=v2) */
101     mbedtls_x509_buf sig_oid;       /**< CRL signature type identifier */
102 
103     mbedtls_x509_buf issuer_raw;    /**< The raw issuer data (DER). */
104 
105     mbedtls_x509_name issuer;       /**< The parsed issuer data (named information object). */
106 
107     mbedtls_x509_time this_update;
108     mbedtls_x509_time next_update;
109 
110     mbedtls_x509_crl_entry entry;   /**< The CRL entries containing the certificate revocation times for this CA. */
111 
112     mbedtls_x509_buf crl_ext;
113 
114     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 */
119 
120     struct mbedtls_x509_crl *next;
121 }
122 mbedtls_x509_crl;
123 
124 /**
125  * \brief          Parse a DER-encoded CRL and append it to the chained list
126  *
127  * \param chain    points to the start of the chain
128  * \param buf      buffer holding the CRL data in DER format
129  * \param buflen   size of the buffer
130  *                 (including the terminating null byte for PEM data)
131  *
132  * \return         0 if successful, or a specific X509 or PEM error code
133  */
134 int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
135                         const unsigned char *buf, size_t buflen );
136 /**
137  * \brief          Parse one or more CRLs and append them to the chained list
138  *
139  * \note           Multiple CRLs are accepted only if using PEM format
140  *
141  * \param chain    points to the start of the chain
142  * \param buf      buffer holding the CRL data in PEM or DER format
143  * \param buflen   size of the buffer
144  *                 (including the terminating null byte for PEM data)
145  *
146  * \return         0 if successful, or a specific X509 or PEM error code
147  */
148 int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
149 
150 #if defined(MBEDTLS_FS_IO)
151 /**
152  * \brief          Load one or more CRLs and append them to the chained list
153  *
154  * \note           Multiple CRLs are accepted only if using PEM format
155  *
156  * \param chain    points to the start of the chain
157  * \param path     filename to read the CRLs from (in PEM or DER encoding)
158  *
159  * \return         0 if successful, or a specific X509 or PEM error code
160  */
161 int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
162 #endif /* MBEDTLS_FS_IO */
163 
164 /**
165  * \brief          Returns an informational string about the CRL.
166  *
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  *
172  * \return         The length of the string written (not including the
173  *                 terminated nul byte), or a negative error code.
174  */
175 int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
176                    const mbedtls_x509_crl *crl );
177 
178 /**
179  * \brief          Initialize a CRL (chain)
180  *
181  * \param crl      CRL chain to initialize
182  */
183 void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
184 
185 /**
186  * \brief          Unallocate all CRL data
187  *
188  * \param crl      CRL chain to free
189  */
190 void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
191 
192 /* \} name */
193 /* \} addtogroup x509_module */
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif /* mbedtls_x509_crl.h */
200