blob: 00e9b0bcecac34c0e27c3c2c261da4d9e8be4766 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file x509.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief X.509 certificate and private key decoding
5 *
Paul Bakker407a0da2013-06-27 14:29:21 +02006 * Copyright (C) 2006-2013, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * 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.
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakker40e46942009-01-03 21:51:57 +000027#ifndef POLARSSL_X509_H
28#define POLARSSL_X509_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakkered27a042013-04-18 22:46:23 +020030#include "config.h"
31
32#if defined(POLARSSL_X509_PARSE_C) || defined(POLARSSL_X509_WRITE_C)
Paul Bakkerefc30292011-11-10 14:43:23 +000033#include "asn1.h"
Paul Bakker314052f2011-08-15 09:07:52 +000034#include "dhm.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +020035#include "md.h"
Paul Bakkered27a042013-04-18 22:46:23 +020036#include "pk.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000037
Paul Bakker37ca75d2011-01-06 12:28:03 +000038/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000039 * \addtogroup x509_module
40 * \{
Paul Bakker13e2dfe2009-07-28 07:18:38 +000041 */
Paul Bakker37ca75d2011-01-06 12:28:03 +000042
Paul Bakker37ca75d2011-01-06 12:28:03 +000043/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000044 * \name X509 Error codes
45 * \{
Paul Bakker13e2dfe2009-07-28 07:18:38 +000046 */
Paul Bakker9d781402011-05-09 16:17:09 +000047#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
48#define POLARSSL_ERR_X509_CERT_INVALID_PEM -0x2100 /**< The PEM-encoded certificate contains invalid elements, e.g. invalid character. */
49#define POLARSSL_ERR_X509_CERT_INVALID_FORMAT -0x2180 /**< The certificate format is invalid, e.g. different type expected. */
50#define POLARSSL_ERR_X509_CERT_INVALID_VERSION -0x2200 /**< The certificate version element is invalid. */
51#define POLARSSL_ERR_X509_CERT_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
52#define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
53#define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
54#define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
Manuel Pégourié-Gonnard5151b452013-08-23 12:03:28 +020055#define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x2480 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
Paul Bakker9d781402011-05-09 16:17:09 +000056#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x2500 /**< The signature tag or value invalid. */
57#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x2580 /**< The extension tag or value is invalid. */
58#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x2600 /**< Certificate or CRL has an unsupported version number. */
59#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x2680 /**< Signature algorithm (oid) is unsupported. */
Manuel Pégourié-Gonnard5a9b82e2013-07-01 16:57:44 +020060#define POLARSSL_ERR_X509_UNKNOWN_PK_ALG -0x2700 /**< Key algorithm is unsupported (only RSA and EC are supported). */
Paul Bakker9d781402011-05-09 16:17:09 +000061#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x2780 /**< Certificate signature algorithms do not match. (see \c ::x509_cert sig_oid) */
62#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2800 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
63#define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x2880 /**< Unsupported RSA key version */
64#define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x2900 /**< Invalid RSA key tag or value. */
Paul Bakker6c0ceb32011-12-04 12:24:18 +000065#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2980 /**< Format not recognized as DER or PEM. */
Paul Bakker69e095c2011-12-10 21:55:01 +000066#define POLARSSL_ERR_X509_INVALID_INPUT -0x2A00 /**< Input invalid. */
67#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2A80 /**< Allocation of memory failed. */
68#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2B00 /**< Read/write of file failed. */
Paul Bakker28144de2013-06-24 19:28:55 +020069#define POLARSSL_ERR_X509_PASSWORD_REQUIRED -0x2B80 /**< Private key password can't be empty. */
70#define POLARSSL_ERR_X509_PASSWORD_MISMATCH -0x2C00 /**< Given private key password does not allow for correct decryption. */
Manuel Pégourié-Gonnardf838eed2013-07-02 14:56:43 +020071#define POLARSSL_ERR_X509_UNKNOWN_NAMED_CURVE -0x2C80 /**< Elliptic curve is unsupported (only NIST curves are supported). */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000072/* \} name */
Paul Bakker5121ce52009-01-03 21:22:43 +000073
Paul Bakker37ca75d2011-01-06 12:28:03 +000074/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000075 * \name X509 Verify codes
76 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +000077 */
Paul Bakkercdf07e92011-01-30 17:05:13 +000078#define BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
79#define BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
80#define BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
81#define BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
82#define BADCRL_NOT_TRUSTED 0x10 /**< CRL is not correctly signed by the trusted CA. */
83#define BADCRL_EXPIRED 0x20 /**< CRL is expired. */
84#define BADCERT_MISSING 0x40 /**< Certificate was missing. */
85#define BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
Paul Bakker915275b2012-09-28 07:10:55 +000086#define BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000087/* \} name */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000088/* \} addtogroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +000089
90/*
Paul Bakker74111d32011-01-15 16:57:55 +000091 * X.509 v3 Key Usage Extension flags
92 */
93#define KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
94#define KU_NON_REPUDIATION (0x40) /* bit 1 */
95#define KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
96#define KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
97#define KU_KEY_AGREEMENT (0x08) /* bit 4 */
98#define KU_KEY_CERT_SIGN (0x04) /* bit 5 */
99#define KU_CRL_SIGN (0x02) /* bit 6 */
100
101/*
Paul Bakker74111d32011-01-15 16:57:55 +0000102 * Netscape certificate types
103 * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
104 */
105
106#define NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
107#define NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
108#define NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
109#define NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
110#define NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
111#define NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
112#define NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
113#define NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
114
Paul Bakkerc70b9822013-04-07 22:00:46 +0200115/*
116 * X.509 extension types
117 */
Paul Bakker74111d32011-01-15 16:57:55 +0000118#define EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
119#define EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
120#define EXT_KEY_USAGE (1 << 2)
121#define EXT_CERTIFICATE_POLICIES (1 << 3)
122#define EXT_POLICY_MAPPINGS (1 << 4)
123#define EXT_SUBJECT_ALT_NAME (1 << 5)
124#define EXT_ISSUER_ALT_NAME (1 << 6)
125#define EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
126#define EXT_BASIC_CONSTRAINTS (1 << 8)
127#define EXT_NAME_CONSTRAINTS (1 << 9)
128#define EXT_POLICY_CONSTRAINTS (1 << 10)
129#define EXT_EXTENDED_KEY_USAGE (1 << 11)
130#define EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
131#define EXT_INIHIBIT_ANYPOLICY (1 << 13)
132#define EXT_FRESHEST_CRL (1 << 14)
133
134#define EXT_NS_CERT_TYPE (1 << 16)
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000136/*
137 * Storage format identifiers
138 * Recognized formats: PEM and DER
139 */
140#define X509_FORMAT_DER 1
141#define X509_FORMAT_PEM 2
142
Paul Bakker407a0da2013-06-27 14:29:21 +0200143#ifdef __cplusplus
144extern "C" {
145#endif
146
Paul Bakkere5eae762013-08-26 12:05:14 +0200147/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000148 * \addtogroup x509_module
149 * \{ */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000150
151/**
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200152 * \name Structures for parsing X.509 certificates, CRLs and CSRs
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000153 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000154 */
Paul Bakkere5eae762013-08-26 12:05:14 +0200155
156/**
Paul Bakker37ca75d2011-01-06 12:28:03 +0000157 * Type-length-value structure that allows for ASN1 using DER.
Paul Bakker5121ce52009-01-03 21:22:43 +0000158 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000159typedef asn1_buf x509_buf;
Paul Bakker5121ce52009-01-03 21:22:43 +0000160
Paul Bakker37ca75d2011-01-06 12:28:03 +0000161/**
Paul Bakker74111d32011-01-15 16:57:55 +0000162 * Container for ASN1 bit strings.
163 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000164typedef asn1_bitstring x509_bitstring;
Paul Bakker74111d32011-01-15 16:57:55 +0000165
166/**
Paul Bakkere5eae762013-08-26 12:05:14 +0200167 * Container for ASN1 named information objects.
Paul Bakker37ca75d2011-01-06 12:28:03 +0000168 * It allows for Relative Distinguished Names (e.g. cn=polarssl,ou=code,etc.).
169 */
Paul Bakkere5eae762013-08-26 12:05:14 +0200170typedef asn1_named_data x509_name;
Paul Bakker5121ce52009-01-03 21:22:43 +0000171
Paul Bakker74111d32011-01-15 16:57:55 +0000172/**
173 * Container for a sequence of ASN.1 items
174 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000175typedef asn1_sequence x509_sequence;
Paul Bakker74111d32011-01-15 16:57:55 +0000176
Paul Bakker37ca75d2011-01-06 12:28:03 +0000177/** Container for date and time (precision in seconds). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000178typedef struct _x509_time
179{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000180 int year, mon, day; /**< Date. */
181 int hour, min, sec; /**< Time. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000182}
183x509_time;
184
Paul Bakkere5eae762013-08-26 12:05:14 +0200185/**
Paul Bakker37ca75d2011-01-06 12:28:03 +0000186 * Container for an X.509 certificate. The certificate may be chained.
187 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000188typedef struct _x509_cert
189{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000190 x509_buf raw; /**< The raw certificate data (DER). */
191 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000192
Paul Bakker37ca75d2011-01-06 12:28:03 +0000193 int version; /**< The X.509 version. (0=v1, 1=v2, 2=v3) */
194 x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
195 x509_buf sig_oid1; /**< Signature algorithm, e.g. sha1RSA */
Paul Bakker5121ce52009-01-03 21:22:43 +0000196
Paul Bakker37ca75d2011-01-06 12:28:03 +0000197 x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
198 x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000199
Paul Bakker37ca75d2011-01-06 12:28:03 +0000200 x509_name issuer; /**< The parsed issuer data (named information object). */
201 x509_name subject; /**< The parsed subject data (named information object). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000202
Paul Bakker37ca75d2011-01-06 12:28:03 +0000203 x509_time valid_from; /**< Start time of certificate validity. */
204 x509_time valid_to; /**< End time of certificate validity. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000205
Manuel Pégourié-Gonnard674b2242013-07-10 14:32:58 +0200206 pk_context pk; /**< Container for the public key context. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000207
Paul Bakker37ca75d2011-01-06 12:28:03 +0000208 x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
209 x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
210 x509_buf v3_ext; /**< Optional X.509 v3 extensions. Only Basic Contraints are supported at this time. */
Paul Bakkera8cd2392012-02-11 16:09:32 +0000211 x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000212
Paul Bakker74111d32011-01-15 16:57:55 +0000213 int ext_types; /**< Bit string containing detected and parsed extensions */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000214 int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
Paul Bakker915275b2012-09-28 07:10:55 +0000215 int max_pathlen; /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. Path length is 1 higher than RFC 5280 'meaning', so 1+ */
Paul Bakker5121ce52009-01-03 21:22:43 +0000216
Paul Bakker74111d32011-01-15 16:57:55 +0000217 unsigned char key_usage; /**< Optional key usage extension value: See the values below */
218
219 x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
220
221 unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values below */
222
Paul Bakker37ca75d2011-01-06 12:28:03 +0000223 x509_buf sig_oid2; /**< Signature algorithm. Must match sig_oid1. */
224 x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200225 md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. POLARSSL_MD_SHA256 */
226 pk_type_t sig_pk /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. POLARSSL_PK_RSA */;
Paul Bakker5121ce52009-01-03 21:22:43 +0000227
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200228 struct _x509_cert *next; /**< Next certificate in the CA-chain. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000229}
230x509_cert;
231
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200232/**
233 * Certificate revocation list entry.
Paul Bakker37ca75d2011-01-06 12:28:03 +0000234 * Contains the CA-specific serial numbers and revocation dates.
235 */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000236typedef struct _x509_crl_entry
237{
238 x509_buf raw;
239
240 x509_buf serial;
241
242 x509_time revocation_date;
243
244 x509_buf entry_ext;
245
246 struct _x509_crl_entry *next;
247}
248x509_crl_entry;
249
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200250/**
251 * Certificate revocation list structure.
Paul Bakker37ca75d2011-01-06 12:28:03 +0000252 * Every CRL may have multiple entries.
253 */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000254typedef struct _x509_crl
255{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000256 x509_buf raw; /**< The raw certificate data (DER). */
257 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000258
259 int version;
260 x509_buf sig_oid1;
261
Paul Bakker37ca75d2011-01-06 12:28:03 +0000262 x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000263
Paul Bakker37ca75d2011-01-06 12:28:03 +0000264 x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000265
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200266 x509_time this_update;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000267 x509_time next_update;
268
Paul Bakker37ca75d2011-01-06 12:28:03 +0000269 x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000270
271 x509_buf crl_ext;
272
273 x509_buf sig_oid2;
274 x509_buf sig;
Paul Bakkerc70b9822013-04-07 22:00:46 +0200275 md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. POLARSSL_MD_SHA256 */
276 pk_type_t sig_pk /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. POLARSSL_PK_RSA */;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000277
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200278 struct _x509_crl *next;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000279}
280x509_crl;
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200281
282/**
283 * Certificate Signing Request (CSR) structure.
284 */
285typedef struct _x509_csr
286{
287 x509_buf raw; /**< The raw CSR data (DER). */
288 x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */
289
290 int version;
291
292 x509_buf subject_raw; /**< The raw subject data (DER). */
293 x509_name subject; /**< The parsed subject data (named information object). */
294
295 pk_context pk; /**< Container for the public key context. */
296
297 x509_buf sig_oid;
298 x509_buf sig;
299 md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. POLARSSL_MD_SHA256 */
300 pk_type_t sig_pk /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. POLARSSL_PK_RSA */;
301}
302x509_csr;
303/** \} name Structures for parsing X.509 certificates, CRLs and CSRs */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000304/** \} addtogroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000305
Paul Bakker37ca75d2011-01-06 12:28:03 +0000306/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000307 * \name Functions to read in DHM parameters, a certificate, CRL or private RSA key
308 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000309 */
310
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000311/** \ingroup x509_module */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000312/**
Paul Bakker89ecb2d2013-06-24 19:06:15 +0200313 * \brief Parse a single DER formatted certificate and add it
314 * to the chained list.
315 *
316 * \param chain points to the start of the chain
317 * \param buf buffer holding the certificate DER data
318 * \param buflen size of the buffer
319 *
320 * \return 0 if successful, or a specific X509 or PEM error code
321 */
322int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, size_t buflen );
323
324/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000325 * \brief Parse one or more certificates and add them
Paul Bakker69e095c2011-12-10 21:55:01 +0000326 * to the chained list. Parses permissively. If some
327 * certificates can be parsed, the result is the number
328 * of failed certificates it encountered. If none complete
329 * correctly, the first error is returned.
Paul Bakker5121ce52009-01-03 21:22:43 +0000330 *
331 * \param chain points to the start of the chain
332 * \param buf buffer holding the certificate data
333 * \param buflen size of the buffer
334 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000335 * \return 0 if all certificates parsed successfully, a positive number
336 * if partly successful or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000337 */
Paul Bakker69e095c2011-12-10 21:55:01 +0000338int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000339
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200340#if defined(POLARSSL_FS_IO)
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000341/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000342/**
343 * \brief Load one or more certificates and add them
Paul Bakker69e095c2011-12-10 21:55:01 +0000344 * to the chained list. Parses permissively. If some
345 * certificates can be parsed, the result is the number
346 * of failed certificates it encountered. If none complete
347 * correctly, the first error is returned.
Paul Bakker5121ce52009-01-03 21:22:43 +0000348 *
349 * \param chain points to the start of the chain
350 * \param path filename to read the certificates from
351 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000352 * \return 0 if all certificates parsed successfully, a positive number
353 * if partly successful or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000354 */
Paul Bakker69e095c2011-12-10 21:55:01 +0000355int x509parse_crtfile( x509_cert *chain, const char *path );
Paul Bakker5121ce52009-01-03 21:22:43 +0000356
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000357/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000358/**
Paul Bakker8d914582012-06-04 12:46:42 +0000359 * \brief Load one or more certificate files from a path and add them
360 * to the chained list. Parses permissively. If some
361 * certificates can be parsed, the result is the number
362 * of failed certificates it encountered. If none complete
363 * correctly, the first error is returned.
364 *
365 * \param chain points to the start of the chain
366 * \param path directory / folder to read the certificate files from
367 *
368 * \return 0 if all certificates parsed successfully, a positive number
369 * if partly successful or a specific X509 or PEM error code
370 */
371int x509parse_crtpath( x509_cert *chain, const char *path );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200372#endif /* POLARSSL_FS_IO */
Paul Bakker8d914582012-06-04 12:46:42 +0000373
374/** \ingroup x509_module */
375/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000376 * \brief Parse one or more CRLs and add them
377 * to the chained list
378 *
379 * \param chain points to the start of the chain
380 * \param buf buffer holding the CRL data
381 * \param buflen size of the buffer
382 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000383 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakkerd98030e2009-05-02 15:13:40 +0000384 */
Paul Bakker23986e52011-04-24 08:57:21 +0000385int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000386
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000387/** \ingroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000388/**
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200389 * \brief Load a Certificate Signing Request (CSR)
390 *
391 * \param csr CSR context to fill
392 * \param buf buffer holding the CRL data
393 * \param buflen size of the buffer
394 *
395 * \return 0 if successful, or a specific X509 or PEM error code
396 */
397int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen );
398
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200399#if defined(POLARSSL_FS_IO)
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200400/** \ingroup x509_module */
401/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000402 * \brief Load one or more CRLs and add them
403 * to the chained list
404 *
405 * \param chain points to the start of the chain
406 * \param path filename to read the CRLs from
407 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000408 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakkerd98030e2009-05-02 15:13:40 +0000409 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000410int x509parse_crlfile( x509_crl *chain, const char *path );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000411
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200412/** \ingroup x509_module */
413/**
414 * \brief Load a Certificate Signing Request (CSR)
415 *
416 * \param csr CSR context to fill
417 * \param path filename to read the CSR from
418 *
419 * \return 0 if successful, or a specific X509 or PEM error code
420 */
421int x509parse_csrfile( x509_csr *csr, const char *path );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200422#endif /* POLARSSL_FS_IO */
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200423
Manuel Pégourié-Gonnardab2d9832013-07-11 16:17:23 +0200424#if defined(POLARSSL_RSA_C)
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000425/** \ingroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000426/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000427 * \brief Parse a private RSA key
428 *
429 * \param rsa RSA context to be initialized
Paul Bakkerff60ee62010-03-16 21:09:09 +0000430 * \param key input buffer
431 * \param keylen size of the buffer
Paul Bakker5121ce52009-01-03 21:22:43 +0000432 * \param pwd password for decryption (optional)
433 * \param pwdlen size of the password
434 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000435 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000436 */
Manuel Pégourié-Gonnardba4878a2013-06-27 10:51:01 +0200437int x509parse_key_rsa( rsa_context *rsa,
438 const unsigned char *key, size_t keylen,
439 const unsigned char *pwd, size_t pwdlen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000440
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200441#if defined(POLARSSL_FS_IO)
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000442/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000443/**
444 * \brief Load and parse a private RSA key
445 *
446 * \param rsa RSA context to be initialized
447 * \param path filename to read the private key from
Paul Bakker37ca75d2011-01-06 12:28:03 +0000448 * \param password password to decrypt the file (can be NULL)
Paul Bakker5121ce52009-01-03 21:22:43 +0000449 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000450 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000451 */
Manuel Pégourié-Gonnardba4878a2013-06-27 10:51:01 +0200452int x509parse_keyfile_rsa( rsa_context *rsa, const char *path,
453 const char *password );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200454#endif /* POLARSSL_FS_IO */
Paul Bakker1b57b062011-01-06 15:48:19 +0000455
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000456/** \ingroup x509_module */
Paul Bakker1b57b062011-01-06 15:48:19 +0000457/**
Paul Bakker917e7542011-03-25 14:23:36 +0000458 * \brief Parse a public RSA key
459 *
460 * \param rsa RSA context to be initialized
461 * \param key input buffer
462 * \param keylen size of the buffer
463 *
464 * \return 0 if successful, or a specific X509 or PEM error code
465 */
Manuel Pégourié-Gonnardba4878a2013-06-27 10:51:01 +0200466int x509parse_public_key_rsa( rsa_context *rsa,
467 const unsigned char *key, size_t keylen );
Paul Bakker917e7542011-03-25 14:23:36 +0000468
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200469#if defined(POLARSSL_FS_IO)
Paul Bakker917e7542011-03-25 14:23:36 +0000470/** \ingroup x509_module */
471/**
472 * \brief Load and parse a public RSA key
473 *
474 * \param rsa RSA context to be initialized
475 * \param path filename to read the private key from
476 *
477 * \return 0 if successful, or a specific X509 or PEM error code
478 */
Manuel Pégourié-Gonnardba4878a2013-06-27 10:51:01 +0200479int x509parse_public_keyfile_rsa( rsa_context *rsa, const char *path );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200480#endif /* POLARSSL_FS_IO */
Manuel Pégourié-Gonnardab2d9832013-07-11 16:17:23 +0200481#endif /* POLARSSL_RSA_C */
Paul Bakker917e7542011-03-25 14:23:36 +0000482
483/** \ingroup x509_module */
484/**
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200485 * \brief Parse a private key
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200486 *
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200487 * \param ctx key to be initialized
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200488 * \param key input buffer
489 * \param keylen size of the buffer
490 * \param pwd password for decryption (optional)
491 * \param pwdlen size of the password
492 *
493 * \return 0 if successful, or a specific X509 or PEM error code
494 */
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200495int x509parse_key( pk_context *ctx,
496 const unsigned char *key, size_t keylen,
497 const unsigned char *pwd, size_t pwdlen );
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200498
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200499#if defined(POLARSSL_FS_IO)
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200500/** \ingroup x509_module */
501/**
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200502 * \brief Load and parse a private key
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200503 *
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200504 * \param ctx key to be initialized
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200505 * \param path filename to read the private key from
506 * \param password password to decrypt the file (can be NULL)
507 *
508 * \return 0 if successful, or a specific X509 or PEM error code
509 */
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200510int x509parse_keyfile( pk_context *ctx,
511 const char *path, const char *password );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200512#endif /* POLARSSL_FS_IO */
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200513
514/** \ingroup x509_module */
515/**
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200516 * \brief Parse a public key
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200517 *
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200518 * \param ctx key to be initialized
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200519 * \param key input buffer
520 * \param keylen size of the buffer
521 *
522 * \return 0 if successful, or a specific X509 or PEM error code
523 */
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200524int x509parse_public_key( pk_context *ctx,
525 const unsigned char *key, size_t keylen );
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200526
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200527#if defined(POLARSSL_FS_IO)
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200528/** \ingroup x509_module */
529/**
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200530 * \brief Load and parse a public key
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200531 *
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200532 * \param ctx key to be initialized
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200533 * \param path filename to read the private key from
534 *
535 * \return 0 if successful, or a specific X509 or PEM error code
536 */
Manuel Pégourié-Gonnard88380992013-07-04 14:09:57 +0200537int x509parse_public_keyfile( pk_context *ctx, const char *path );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200538#endif /* POLARSSL_FS_IO */
Manuel Pégourié-Gonnard26833c22013-06-27 11:27:58 +0200539
540/** \ingroup x509_module */
541/**
Paul Bakker1b57b062011-01-06 15:48:19 +0000542 * \brief Parse DHM parameters
543 *
544 * \param dhm DHM context to be initialized
545 * \param dhmin input buffer
546 * \param dhminlen size of the buffer
547 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000548 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker1b57b062011-01-06 15:48:19 +0000549 */
Paul Bakker23986e52011-04-24 08:57:21 +0000550int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen );
Paul Bakker1b57b062011-01-06 15:48:19 +0000551
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200552#if defined(POLARSSL_FS_IO)
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000553/** \ingroup x509_module */
Paul Bakker1b57b062011-01-06 15:48:19 +0000554/**
555 * \brief Load and parse DHM parameters
556 *
557 * \param dhm DHM context to be initialized
558 * \param path filename to read the DHM Parameters from
559 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000560 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker1b57b062011-01-06 15:48:19 +0000561 */
Paul Bakkerf3b86c12011-01-27 15:24:17 +0000562int x509parse_dhmfile( dhm_context *dhm, const char *path );
Manuel Pégourié-Gonnard02376202013-09-12 07:01:31 +0200563#endif /* POLARSSL_FS_IO */
Paul Bakker1b57b062011-01-06 15:48:19 +0000564
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000565/** \} name Functions to read in DHM parameters, a certificate, CRL or private RSA key */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000566
Paul Bakker5121ce52009-01-03 21:22:43 +0000567/**
568 * \brief Store the certificate DN in printable form into buf;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000569 * no more than size characters will be written.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000570 *
571 * \param buf Buffer to write to
572 * \param size Maximum size of buffer
573 * \param dn The X509 name to represent
574 *
575 * \return The amount of data written to the buffer, or -1 in
576 * case of an error.
Paul Bakker5121ce52009-01-03 21:22:43 +0000577 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000578int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn );
Paul Bakker5121ce52009-01-03 21:22:43 +0000579
580/**
Paul Bakkerdd476992011-01-16 21:34:59 +0000581 * \brief Store the certificate serial in printable form into buf;
582 * no more than size characters will be written.
583 *
584 * \param buf Buffer to write to
585 * \param size Maximum size of buffer
586 * \param serial The X509 serial to represent
587 *
588 * \return The amount of data written to the buffer, or -1 in
589 * case of an error.
590 */
591int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial );
592
593/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000594 * \brief Returns an informational string about the
595 * certificate.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000596 *
597 * \param buf Buffer to write to
598 * \param size Maximum size of buffer
599 * \param prefix A line prefix
600 * \param crt The X509 certificate to represent
601 *
602 * \return The amount of data written to the buffer, or -1 in
603 * case of an error.
Paul Bakker5121ce52009-01-03 21:22:43 +0000604 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000605int x509parse_cert_info( char *buf, size_t size, const char *prefix,
606 const x509_cert *crt );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000607
608/**
609 * \brief Returns an informational string about the
610 * CRL.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000611 *
612 * \param buf Buffer to write to
613 * \param size Maximum size of buffer
614 * \param prefix A line prefix
Paul Bakker37ca75d2011-01-06 12:28:03 +0000615 * \param crl The X509 CRL to represent
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000616 *
617 * \return The amount of data written to the buffer, or -1 in
618 * case of an error.
Paul Bakkerd98030e2009-05-02 15:13:40 +0000619 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000620int x509parse_crl_info( char *buf, size_t size, const char *prefix,
621 const x509_crl *crl );
Paul Bakker5121ce52009-01-03 21:22:43 +0000622
623/**
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200624 * \brief Returns an informational string about the
625 * CSR.
626 *
627 * \param buf Buffer to write to
628 * \param size Maximum size of buffer
629 * \param prefix A line prefix
630 * \param csr The X509 CSR to represent
631 *
632 * \return The amount of data written to the buffer, or -1 in
633 * case of an error.
634 */
635int x509parse_csr_info( char *buf, size_t size, const char *prefix,
636 const x509_csr *csr );
637
638/**
Paul Bakker74111d32011-01-15 16:57:55 +0000639 * \brief Give an known OID, return its descriptive string.
640 *
641 * \param oid buffer containing the oid
642 *
643 * \return Return a string if the OID is known,
644 * or NULL otherwise.
645 */
646const char *x509_oid_get_description( x509_buf *oid );
647
Paul Bakker9a736322012-11-14 12:39:52 +0000648/**
Paul Bakker74111d32011-01-15 16:57:55 +0000649 * \brief Give an OID, return a string version of its OID number.
Paul Bakkerd5c2b542013-04-07 22:34:26 +0200650 * (Deprecated. Use oid_get_numeric_string() instead)
Paul Bakker74111d32011-01-15 16:57:55 +0000651 *
652 * \param buf Buffer to write to
653 * \param size Maximum size of buffer
654 * \param oid Buffer containing the OID
655 *
656 * \return The amount of data written to the buffer, or -1 in
657 * case of an error.
658 */
659int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid );
660
661/**
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000662 * \brief Check a given x509_time against the system time and check
663 * if it is valid.
664 *
665 * \param time x509_time to check
666 *
667 * \return Return 0 if the x509_time is still valid,
Paul Bakker40ea7de2009-05-03 10:18:48 +0000668 * or 1 otherwise.
Paul Bakker5121ce52009-01-03 21:22:43 +0000669 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000670int x509parse_time_expired( const x509_time *time );
Paul Bakker5121ce52009-01-03 21:22:43 +0000671
672/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000673 * \name Functions to verify a certificate
674 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000675 */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000676/** \ingroup x509_module */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000677/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000678 * \brief Verify the certificate signature
679 *
Paul Bakker915275b2012-09-28 07:10:55 +0000680 * The verify callback is a user-supplied callback that
681 * can clear / modify / add flags for a certificate. If set,
682 * the verification callback is called for each
683 * certificate in the chain (from the trust-ca down to the
684 * presented crt). The parameters for the callback are:
685 * (void *parameter, x509_cert *crt, int certificate_depth,
686 * int *flags). With the flags representing current flags for
687 * that specific certificate and the certificate depth from
Paul Bakker9a736322012-11-14 12:39:52 +0000688 * the bottom (Peer cert depth = 0).
Paul Bakker915275b2012-09-28 07:10:55 +0000689 *
690 * All flags left after returning from the callback
691 * are also returned to the application. The function should
692 * return 0 for anything but a fatal error.
693 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000694 * \param crt a certificate to be verified
695 * \param trust_ca the trusted CA chain
Paul Bakker40ea7de2009-05-03 10:18:48 +0000696 * \param ca_crl the CRL chain for trusted CA's
Paul Bakker5121ce52009-01-03 21:22:43 +0000697 * \param cn expected Common Name (can be set to
698 * NULL if the CN must not be verified)
699 * \param flags result of the verification
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000700 * \param f_vrfy verification function
701 * \param p_vrfy verification parameter
Paul Bakker5121ce52009-01-03 21:22:43 +0000702 *
Paul Bakker40e46942009-01-03 21:51:57 +0000703 * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
Paul Bakker5121ce52009-01-03 21:22:43 +0000704 * in which case *flags will have one or more of
705 * the following values set:
706 * BADCERT_EXPIRED --
707 * BADCERT_REVOKED --
708 * BADCERT_CN_MISMATCH --
709 * BADCERT_NOT_TRUSTED
Paul Bakker915275b2012-09-28 07:10:55 +0000710 * or another error in case of a fatal error encountered
711 * during the verification process.
Paul Bakker5121ce52009-01-03 21:22:43 +0000712 */
713int x509parse_verify( x509_cert *crt,
714 x509_cert *trust_ca,
Paul Bakker40ea7de2009-05-03 10:18:48 +0000715 x509_crl *ca_crl,
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000716 const char *cn, int *flags,
Paul Bakker915275b2012-09-28 07:10:55 +0000717 int (*f_vrfy)(void *, x509_cert *, int, int *),
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000718 void *p_vrfy );
Paul Bakker5121ce52009-01-03 21:22:43 +0000719
Paul Bakker74111d32011-01-15 16:57:55 +0000720/**
721 * \brief Verify the certificate signature
722 *
723 * \param crt a certificate to be verified
724 * \param crl the CRL to verify against
725 *
726 * \return 1 if the certificate is revoked, 0 otherwise
727 *
728 */
729int x509parse_revoked( const x509_cert *crt, const x509_crl *crl );
730
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000731/** \} name Functions to verify a certificate */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000732
733
734
735/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000736 * \name Functions to clear a certificate, CRL or private RSA key
737 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000738 */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000739/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000740/**
741 * \brief Unallocate all certificate data
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000742 *
743 * \param crt Certificate chain to free
Paul Bakker5121ce52009-01-03 21:22:43 +0000744 */
745void x509_free( x509_cert *crt );
746
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000747/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000748/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000749 * \brief Unallocate all CRL data
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000750 *
Paul Bakker37ca75d2011-01-06 12:28:03 +0000751 * \param crl CRL chain to free
Paul Bakkerd98030e2009-05-02 15:13:40 +0000752 */
753void x509_crl_free( x509_crl *crl );
754
Paul Bakkerf9f377e2013-09-09 15:35:10 +0200755/**
756 * \brief Unallocate all CSR data
757 *
758 * \param csr CSR to free
759 */
760void x509_csr_free( x509_csr *csr );
761
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000762/** \} name Functions to clear a certificate, CRL or private RSA key */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000763
764
Paul Bakkerd98030e2009-05-02 15:13:40 +0000765/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000766 * \brief Checkup routine
767 *
768 * \return 0 if successful, or 1 if the test failed
769 */
770int x509_self_test( int verbose );
771
772#ifdef __cplusplus
773}
774#endif
775
Paul Bakkered27a042013-04-18 22:46:23 +0200776#endif /* POLARSSL_X509_PARSE_C || POLARSSL_X509_WRITE_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000777#endif /* x509.h */