blob: 28507a5f95ec5b1c21911899cb27bd8cf3d9a2b7 [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/**
2 * \file x509_crl.h
3 *
4 * \brief X.509 certificate revocation list parsing
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakker7c6b2c32013-09-16 13:49:26 +02007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker7c6b2c32013-09-16 13:49:26 +02009 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +020010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24#ifndef POLARSSL_X509_CRL_H
25#define POLARSSL_X509_CRL_H
26
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020032
33#include "x509.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/**
40 * \addtogroup x509_module
41 * \{ */
42
43/**
44 * \name Structures and functions for parsing CRLs
45 * \{
46 */
47
48/**
49 * Certificate revocation list entry.
50 * Contains the CA-specific serial numbers and revocation dates.
51 */
52typedef struct _x509_crl_entry
53{
54 x509_buf raw;
55
56 x509_buf serial;
57
58 x509_time revocation_date;
59
60 x509_buf entry_ext;
61
62 struct _x509_crl_entry *next;
63}
64x509_crl_entry;
65
66/**
67 * Certificate revocation list structure.
68 * Every CRL may have multiple entries.
69 */
70typedef struct _x509_crl
71{
72 x509_buf raw; /**< The raw certificate data (DER). */
73 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
74
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +020075 int version; /**< CRL version (1=v1, 2=v2) */
Manuel Pégourié-Gonnard1022fed2015-03-27 16:30:47 +010076 x509_buf sig_oid; /**< CRL signature type identifier */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020077
78 x509_buf issuer_raw; /**< The raw issuer data (DER). */
79
80 x509_name issuer; /**< The parsed issuer data (named information object). */
81
82 x509_time this_update;
83 x509_time next_update;
84
85 x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
86
87 x509_buf crl_ext;
88
89 x509_buf sig_oid2;
90 x509_buf sig;
91 md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. POLARSSL_MD_SHA256 */
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +020092 pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. POLARSSL_PK_RSA */
Paul Bakker6dade7c2014-06-12 22:02:14 +020093 void *sig_opts; /**< Signature options to be passed to pk_verify_ext(), e.g. for RSASSA-PSS */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020094
95 struct _x509_crl *next;
96}
97x509_crl;
98
99/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100100 * \brief Parse a DER-encoded CRL and append it to the chained list
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200101 *
102 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100103 * \param buf buffer holding the CRL data in DER format
104 * \param buflen size of the buffer
105 *
106 * \return 0 if successful, or a specific X509 or PEM error code
107 */
108int x509_crl_parse_der( x509_crl *chain,
109 const unsigned char *buf, size_t buflen );
110/**
111 * \brief Parse one or more CRLs and append them to the chained list
112 *
113 * \note Mutliple CRLs are accepted only if using PEM format
114 *
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
118 *
119 * \return 0 if successful, or a specific X509 or PEM error code
120 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200121int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122
123#if defined(POLARSSL_FS_IO)
124/**
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100125 * \brief Load one or more CRLs and append them to the chained list
126 *
127 * \note Mutliple CRLs are accepted only if using PEM format
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200128 *
129 * \param chain points to the start of the chain
Manuel Pégourié-Gonnard426d4ae2014-11-19 16:58:28 +0100130 * \param path filename to read the CRLs from (in PEM or DER encoding)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200131 *
132 * \return 0 if successful, or a specific X509 or PEM error code
133 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200134int x509_crl_parse_file( x509_crl *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200135#endif /* POLARSSL_FS_IO */
136
137/**
Paul Bakkerddf26b42013-09-18 13:46:23 +0200138 * \brief Returns an informational string about the CRL.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200139 *
140 * \param buf Buffer to write to
141 * \param size Maximum size of buffer
142 * \param prefix A line prefix
143 * \param crl The X509 CRL to represent
144 *
145 * \return The amount of data written to the buffer, or -1 in
146 * case of an error.
147 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200148int x509_crl_info( char *buf, size_t size, const char *prefix,
149 const x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200150
151/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200152 * \brief Initialize a CRL (chain)
153 *
154 * \param crl CRL chain to initialize
155 */
156void x509_crl_init( x509_crl *crl );
157
158/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200159 * \brief Unallocate all CRL data
160 *
161 * \param crl CRL chain to free
162 */
163void x509_crl_free( x509_crl *crl );
164
165/* \} name */
166/* \} addtogroup x509_module */
167
168#ifdef __cplusplus
169}
170#endif
171
172#endif /* x509_crl.h */