Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file x509_crl.h |
| 3 | * |
| 4 | * \brief X.509 certificate revocation list parsing |
| 5 | * |
| 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
| 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 26 | */ |
| 27 | #ifndef POLARSSL_X509_CRL_H |
| 28 | #define POLARSSL_X509_CRL_H |
| 29 | |
| 30 | #include "config.h" |
| 31 | |
| 32 | #include "x509.h" |
| 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
| 38 | /** |
| 39 | * \addtogroup x509_module |
| 40 | * \{ */ |
| 41 | |
| 42 | /** |
| 43 | * \name Structures and functions for parsing CRLs |
| 44 | * \{ |
| 45 | */ |
| 46 | |
| 47 | /** |
| 48 | * Certificate revocation list entry. |
| 49 | * Contains the CA-specific serial numbers and revocation dates. |
| 50 | */ |
| 51 | typedef struct _x509_crl_entry |
| 52 | { |
| 53 | x509_buf raw; |
| 54 | |
| 55 | x509_buf serial; |
| 56 | |
| 57 | x509_time revocation_date; |
| 58 | |
| 59 | x509_buf entry_ext; |
| 60 | |
| 61 | struct _x509_crl_entry *next; |
| 62 | } |
| 63 | x509_crl_entry; |
| 64 | |
| 65 | /** |
| 66 | * Certificate revocation list structure. |
| 67 | * Every CRL may have multiple entries. |
| 68 | */ |
| 69 | typedef struct _x509_crl |
| 70 | { |
| 71 | x509_buf raw; /**< The raw certificate data (DER). */ |
| 72 | x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */ |
| 73 | |
| 74 | int version; |
| 75 | x509_buf sig_oid1; |
| 76 | |
| 77 | x509_buf issuer_raw; /**< The raw issuer data (DER). */ |
| 78 | |
| 79 | x509_name issuer; /**< The parsed issuer data (named information object). */ |
| 80 | |
| 81 | x509_time this_update; |
| 82 | x509_time next_update; |
| 83 | |
| 84 | x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */ |
| 85 | |
| 86 | x509_buf crl_ext; |
| 87 | |
| 88 | x509_buf sig_oid2; |
| 89 | x509_buf sig; |
| 90 | md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. POLARSSL_MD_SHA256 */ |
| 91 | pk_type_t sig_pk /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. POLARSSL_PK_RSA */; |
| 92 | |
| 93 | struct _x509_crl *next; |
| 94 | } |
| 95 | x509_crl; |
| 96 | |
| 97 | /** |
| 98 | * \brief Parse one or more CRLs and add them |
| 99 | * to the chained list |
| 100 | * |
| 101 | * \param chain points to the start of the chain |
| 102 | * \param buf buffer holding the CRL data |
| 103 | * \param buflen size of the buffer |
| 104 | * |
| 105 | * \return 0 if successful, or a specific X509 or PEM error code |
| 106 | */ |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 107 | int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 108 | |
| 109 | #if defined(POLARSSL_FS_IO) |
| 110 | /** |
| 111 | * \brief Load one or more CRLs and add them |
| 112 | * to the chained list |
| 113 | * |
| 114 | * \param chain points to the start of the chain |
| 115 | * \param path filename to read the CRLs from |
| 116 | * |
| 117 | * \return 0 if successful, or a specific X509 or PEM error code |
| 118 | */ |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 119 | int x509_crl_parse_file( x509_crl *chain, const char *path ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 120 | #endif /* POLARSSL_FS_IO */ |
| 121 | |
| 122 | /** |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 123 | * \brief Returns an informational string about the CRL. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 124 | * |
| 125 | * \param buf Buffer to write to |
| 126 | * \param size Maximum size of buffer |
| 127 | * \param prefix A line prefix |
| 128 | * \param crl The X509 CRL to represent |
| 129 | * |
| 130 | * \return The amount of data written to the buffer, or -1 in |
| 131 | * case of an error. |
| 132 | */ |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 133 | int x509_crl_info( char *buf, size_t size, const char *prefix, |
| 134 | const x509_crl *crl ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 135 | |
| 136 | /** |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 137 | * \brief Initialize a CRL (chain) |
| 138 | * |
| 139 | * \param crl CRL chain to initialize |
| 140 | */ |
| 141 | void x509_crl_init( x509_crl *crl ); |
| 142 | |
| 143 | /** |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 144 | * \brief Unallocate all CRL data |
| 145 | * |
| 146 | * \param crl CRL chain to free |
| 147 | */ |
| 148 | void x509_crl_free( x509_crl *crl ); |
| 149 | |
| 150 | /* \} name */ |
| 151 | /* \} addtogroup x509_module */ |
| 152 | |
| 153 | #ifdef __cplusplus |
| 154 | } |
| 155 | #endif |
| 156 | |
| 157 | #endif /* x509_crl.h */ |