blob: ed78645ed03c5faeb749aef635872ce9d90eb01e [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 *
Manuel Pégourié-Gonnard0edee5e2015-01-26 15:29:40 +00006 * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnard0edee5e2015-01-26 15:29:40 +00008 * This file is part of mbed TLS (https://www.polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * 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.
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Paul Bakker40e46942009-01-03 21:51:57 +000024#ifndef POLARSSL_X509_H
25#define POLARSSL_X509_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Paul Bakkerefc30292011-11-10 14:43:23 +000027#include "asn1.h"
Paul Bakker314052f2011-08-15 09:07:52 +000028#include "rsa.h"
29#include "dhm.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Paul Bakker37ca75d2011-01-06 12:28:03 +000031/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000032 * \addtogroup x509_module
33 * \{
Paul Bakker13e2dfe2009-07-28 07:18:38 +000034 */
Paul Bakker37ca75d2011-01-06 12:28:03 +000035
Manuel Pégourié-Gonnard4cdb3ba2014-11-20 17:12:15 +010036#if !defined(POLARSSL_CONFIG_OPTIONS)
37/**
38 * Maximum number of intermediate CAs in a verification chain.
39 * That is, maximum length of the chain, excluding the end-entity certificate
40 * and the trusted root certificate.
41 *
42 * Set this to a low value to prevent an adversary from making you waste
43 * resources verifying an overlong certificate chain.
44 */
45#define POLARSSL_X509_MAX_INTERMEDIATE_CA 8
46#endif
47
Paul Bakker37ca75d2011-01-06 12:28:03 +000048/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000049 * \name X509 Error codes
50 * \{
Paul Bakker13e2dfe2009-07-28 07:18:38 +000051 */
Paul Bakker9d781402011-05-09 16:17:09 +000052#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
53#define POLARSSL_ERR_X509_CERT_INVALID_PEM -0x2100 /**< The PEM-encoded certificate contains invalid elements, e.g. invalid character. */
54#define POLARSSL_ERR_X509_CERT_INVALID_FORMAT -0x2180 /**< The certificate format is invalid, e.g. different type expected. */
55#define POLARSSL_ERR_X509_CERT_INVALID_VERSION -0x2200 /**< The certificate version element is invalid. */
56#define POLARSSL_ERR_X509_CERT_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
57#define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
58#define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
59#define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
60#define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x2480 /**< The pubkey tag or value is invalid (only RSA is supported). */
61#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x2500 /**< The signature tag or value invalid. */
62#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x2580 /**< The extension tag or value is invalid. */
63#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x2600 /**< Certificate or CRL has an unsupported version number. */
64#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x2680 /**< Signature algorithm (oid) is unsupported. */
Paul Bakkered56b222011-07-13 11:26:43 +000065#define POLARSSL_ERR_X509_UNKNOWN_PK_ALG -0x2700 /**< Key algorithm is unsupported (only RSA is supported). */
Paul Bakker9d781402011-05-09 16:17:09 +000066#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x2780 /**< Certificate signature algorithms do not match. (see \c ::x509_cert sig_oid) */
67#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2800 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
68#define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x2880 /**< Unsupported RSA key version */
69#define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x2900 /**< Invalid RSA key tag or value. */
Paul Bakker6c0ceb32011-12-04 12:24:18 +000070#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2980 /**< Format not recognized as DER or PEM. */
Paul Bakker69e095c2011-12-10 21:55:01 +000071#define POLARSSL_ERR_X509_INVALID_INPUT -0x2A00 /**< Input invalid. */
72#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2A80 /**< Allocation of memory failed. */
73#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2B00 /**< Read/write of file failed. */
Paul Bakker1fd43212013-06-17 15:14:42 +020074#define POLARSSL_ERR_X509_PASSWORD_REQUIRED -0x2B80 /**< Private key password can't be empty. */
75#define POLARSSL_ERR_X509_PASSWORD_MISMATCH -0x2C00 /**< Given private key password does not allow for correct decryption. */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000076/* \} name */
Paul Bakker5121ce52009-01-03 21:22:43 +000077
Paul Bakker37ca75d2011-01-06 12:28:03 +000078
79/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000080 * \name X509 Verify codes
81 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +000082 */
Paul Bakkercdf07e92011-01-30 17:05:13 +000083#define BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
84#define BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
85#define BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
86#define BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
87#define BADCRL_NOT_TRUSTED 0x10 /**< CRL is not correctly signed by the trusted CA. */
88#define BADCRL_EXPIRED 0x20 /**< CRL is expired. */
89#define BADCERT_MISSING 0x40 /**< Certificate was missing. */
90#define BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
Paul Bakker915275b2012-09-28 07:10:55 +000091#define BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
Paul Bakker50a5c532014-07-08 10:59:10 +020092#define BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
93#define BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
94
Paul Bakker0f5f72e2011-01-18 14:58:55 +000095/* \} name */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000096/* \} addtogroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +000097
98/*
99 * various object identifiers
100 */
101#define X520_COMMON_NAME 3
102#define X520_COUNTRY 6
103#define X520_LOCALITY 7
104#define X520_STATE 8
105#define X520_ORGANIZATION 10
106#define X520_ORG_UNIT 11
107#define PKCS9_EMAIL 1
108
109#define X509_OUTPUT_DER 0x01
110#define X509_OUTPUT_PEM 0x02
111#define PEM_LINE_LENGTH 72
112#define X509_ISSUER 0x01
113#define X509_SUBJECT 0x02
114
115#define OID_X520 "\x55\x04"
Paul Bakker74111d32011-01-15 16:57:55 +0000116#define OID_CN OID_X520 "\x03"
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000117#define OID_COUNTRY OID_X520 "\x06"
118#define OID_LOCALITY OID_X520 "\x07"
119#define OID_STATE OID_X520 "\x08"
120#define OID_ORGANIZATION OID_X520 "\x0A"
121#define OID_ORG_UNIT OID_X520 "\x0B"
Paul Bakker74111d32011-01-15 16:57:55 +0000122
Paul Bakker5121ce52009-01-03 21:22:43 +0000123#define OID_PKCS1 "\x2A\x86\x48\x86\xF7\x0D\x01\x01"
Paul Bakker74111d32011-01-15 16:57:55 +0000124#define OID_PKCS1_RSA OID_PKCS1 "\x01"
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000125#define OID_PKCS1_SHA1 OID_PKCS1 "\x05"
Paul Bakker400ff6f2011-02-20 10:40:16 +0000126
127#define OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
Paul Bakker74111d32011-01-15 16:57:55 +0000128
Paul Bakker5121ce52009-01-03 21:22:43 +0000129#define OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09"
Paul Bakker74111d32011-01-15 16:57:55 +0000130#define OID_PKCS9_EMAIL OID_PKCS9 "\x01"
131
132/** ISO arc for standard certificate and CRL extensions */
133#define OID_ID_CE "\x55\x1D" /**< id-ce OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 29} */
134
135/**
136 * Private Internet Extensions
137 * { iso(1) identified-organization(3) dod(6) internet(1)
138 * security(5) mechanisms(5) pkix(7) }
139 */
140#define OID_PKIX "\x2B\x06\x01\x05\x05\x07"
141
142/*
143 * OIDs for standard certificate extensions
144 */
145#define OID_AUTHORITY_KEY_IDENTIFIER OID_ID_CE "\x23" /**< id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } */
146#define OID_SUBJECT_KEY_IDENTIFIER OID_ID_CE "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */
147#define OID_KEY_USAGE OID_ID_CE "\x0F" /**< id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } */
148#define OID_CERTIFICATE_POLICIES OID_ID_CE "\x20" /**< id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } */
149#define OID_POLICY_MAPPINGS OID_ID_CE "\x21" /**< id-ce-policyMappings OBJECT IDENTIFIER ::= { id-ce 33 } */
150#define OID_SUBJECT_ALT_NAME OID_ID_CE "\x11" /**< id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } */
151#define OID_ISSUER_ALT_NAME OID_ID_CE "\x12" /**< id-ce-issuerAltName OBJECT IDENTIFIER ::= { id-ce 18 } */
152#define OID_SUBJECT_DIRECTORY_ATTRS OID_ID_CE "\x09" /**< id-ce-subjectDirectoryAttributes OBJECT IDENTIFIER ::= { id-ce 9 } */
153#define OID_BASIC_CONSTRAINTS OID_ID_CE "\x13" /**< id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } */
154#define OID_NAME_CONSTRAINTS OID_ID_CE "\x1E" /**< id-ce-nameConstraints OBJECT IDENTIFIER ::= { id-ce 30 } */
155#define OID_POLICY_CONSTRAINTS OID_ID_CE "\x24" /**< id-ce-policyConstraints OBJECT IDENTIFIER ::= { id-ce 36 } */
156#define OID_EXTENDED_KEY_USAGE OID_ID_CE "\x25" /**< id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } */
157#define OID_CRL_DISTRIBUTION_POINTS OID_ID_CE "\x1F" /**< id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } */
158#define OID_INIHIBIT_ANYPOLICY OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */
159#define OID_FRESHEST_CRL OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */
160
161/*
162 * X.509 v3 Key Usage Extension flags
163 */
164#define KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
165#define KU_NON_REPUDIATION (0x40) /* bit 1 */
166#define KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
167#define KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
168#define KU_KEY_AGREEMENT (0x08) /* bit 4 */
169#define KU_KEY_CERT_SIGN (0x04) /* bit 5 */
170#define KU_CRL_SIGN (0x02) /* bit 6 */
171
172/*
173 * X.509 v3 Extended key usage OIDs
174 */
175#define OID_ANY_EXTENDED_KEY_USAGE OID_EXTENDED_KEY_USAGE "\x00" /**< anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 } */
176
177#define OID_KP OID_PKIX "\x03" /**< id-kp OBJECT IDENTIFIER ::= { id-pkix 3 } */
178#define OID_SERVER_AUTH OID_KP "\x01" /**< id-kp-serverAuth OBJECT IDENTIFIER ::= { id-kp 1 } */
179#define OID_CLIENT_AUTH OID_KP "\x02" /**< id-kp-clientAuth OBJECT IDENTIFIER ::= { id-kp 2 } */
180#define OID_CODE_SIGNING OID_KP "\x03" /**< id-kp-codeSigning OBJECT IDENTIFIER ::= { id-kp 3 } */
181#define OID_EMAIL_PROTECTION OID_KP "\x04" /**< id-kp-emailProtection OBJECT IDENTIFIER ::= { id-kp 4 } */
182#define OID_TIME_STAMPING OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */
183#define OID_OCSP_SIGNING OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */
184
185#define STRING_SERVER_AUTH "TLS Web Server Authentication"
186#define STRING_CLIENT_AUTH "TLS Web Client Authentication"
187#define STRING_CODE_SIGNING "Code Signing"
188#define STRING_EMAIL_PROTECTION "E-mail Protection"
189#define STRING_TIME_STAMPING "Time Stamping"
190#define STRING_OCSP_SIGNING "OCSP Signing"
191
192/*
193 * OIDs for CRL extensions
194 */
195#define OID_PRIVATE_KEY_USAGE_PERIOD OID_ID_CE "\x10"
196#define OID_CRL_NUMBER OID_ID_CE "\x14" /**< id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } */
197
198/*
199 * Netscape certificate extensions
200 */
201#define OID_NETSCAPE "\x60\x86\x48\x01\x86\xF8\x42" /**< Netscape OID */
202#define OID_NS_CERT OID_NETSCAPE "\x01"
203#define OID_NS_CERT_TYPE OID_NS_CERT "\x01"
204#define OID_NS_BASE_URL OID_NS_CERT "\x02"
205#define OID_NS_REVOCATION_URL OID_NS_CERT "\x03"
206#define OID_NS_CA_REVOCATION_URL OID_NS_CERT "\x04"
207#define OID_NS_RENEWAL_URL OID_NS_CERT "\x07"
208#define OID_NS_CA_POLICY_URL OID_NS_CERT "\x08"
209#define OID_NS_SSL_SERVER_NAME OID_NS_CERT "\x0C"
210#define OID_NS_COMMENT OID_NS_CERT "\x0D"
211#define OID_NS_DATA_TYPE OID_NETSCAPE "\x02"
212#define OID_NS_CERT_SEQUENCE OID_NS_DATA_TYPE "\x05"
213
214/*
215 * Netscape certificate types
216 * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
217 */
218
219#define NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
220#define NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
221#define NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
222#define NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
223#define NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
224#define NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
225#define NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
226#define NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
227
228#define EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
229#define EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
230#define EXT_KEY_USAGE (1 << 2)
231#define EXT_CERTIFICATE_POLICIES (1 << 3)
232#define EXT_POLICY_MAPPINGS (1 << 4)
233#define EXT_SUBJECT_ALT_NAME (1 << 5)
234#define EXT_ISSUER_ALT_NAME (1 << 6)
235#define EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
236#define EXT_BASIC_CONSTRAINTS (1 << 8)
237#define EXT_NAME_CONSTRAINTS (1 << 9)
238#define EXT_POLICY_CONSTRAINTS (1 << 10)
239#define EXT_EXTENDED_KEY_USAGE (1 << 11)
240#define EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
241#define EXT_INIHIBIT_ANYPOLICY (1 << 13)
242#define EXT_FRESHEST_CRL (1 << 14)
243
244#define EXT_NS_CERT_TYPE (1 << 16)
Paul Bakker5121ce52009-01-03 21:22:43 +0000245
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000246/*
247 * Storage format identifiers
248 * Recognized formats: PEM and DER
249 */
250#define X509_FORMAT_DER 1
251#define X509_FORMAT_PEM 2
252
Paul Bakker37ca75d2011-01-06 12:28:03 +0000253/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000254 * \addtogroup x509_module
255 * \{ */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000256
257/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000258 * \name Structures for parsing X.509 certificates and CRLs
259 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000260 */
261
262/**
263 * Type-length-value structure that allows for ASN1 using DER.
Paul Bakker5121ce52009-01-03 21:22:43 +0000264 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000265typedef asn1_buf x509_buf;
Paul Bakker5121ce52009-01-03 21:22:43 +0000266
Paul Bakker37ca75d2011-01-06 12:28:03 +0000267/**
Paul Bakker74111d32011-01-15 16:57:55 +0000268 * Container for ASN1 bit strings.
269 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000270typedef asn1_bitstring x509_bitstring;
Paul Bakker74111d32011-01-15 16:57:55 +0000271
272/**
Paul Bakker37ca75d2011-01-06 12:28:03 +0000273 * Container for ASN1 named information objects.
274 * It allows for Relative Distinguished Names (e.g. cn=polarssl,ou=code,etc.).
275 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000276typedef struct _x509_name
277{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000278 x509_buf oid; /**< The object identifier. */
279 x509_buf val; /**< The named value. */
280 struct _x509_name *next; /**< The next named information object. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000281}
282x509_name;
283
Paul Bakker74111d32011-01-15 16:57:55 +0000284/**
285 * Container for a sequence of ASN.1 items
286 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000287typedef asn1_sequence x509_sequence;
Paul Bakker74111d32011-01-15 16:57:55 +0000288
Paul Bakker37ca75d2011-01-06 12:28:03 +0000289/** Container for date and time (precision in seconds). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000290typedef struct _x509_time
291{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000292 int year, mon, day; /**< Date. */
293 int hour, min, sec; /**< Time. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000294}
295x509_time;
296
Paul Bakker37ca75d2011-01-06 12:28:03 +0000297/**
298 * Container for an X.509 certificate. The certificate may be chained.
299 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000300typedef struct _x509_cert
301{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000302 x509_buf raw; /**< The raw certificate data (DER). */
303 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000304
Paul Bakker37ca75d2011-01-06 12:28:03 +0000305 int version; /**< The X.509 version. (0=v1, 1=v2, 2=v3) */
306 x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
307 x509_buf sig_oid1; /**< Signature algorithm, e.g. sha1RSA */
Paul Bakker5121ce52009-01-03 21:22:43 +0000308
Paul Bakker37ca75d2011-01-06 12:28:03 +0000309 x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
310 x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000311
Paul Bakker37ca75d2011-01-06 12:28:03 +0000312 x509_name issuer; /**< The parsed issuer data (named information object). */
313 x509_name subject; /**< The parsed subject data (named information object). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000314
Paul Bakker37ca75d2011-01-06 12:28:03 +0000315 x509_time valid_from; /**< Start time of certificate validity. */
316 x509_time valid_to; /**< End time of certificate validity. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000317
Paul Bakker37ca75d2011-01-06 12:28:03 +0000318 x509_buf pk_oid; /**< Subject public key info. Includes the public key algorithm and the key itself. */
319 rsa_context rsa; /**< Container for the RSA context. Only RSA is supported for public keys at this time. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000320
Paul Bakker37ca75d2011-01-06 12:28:03 +0000321 x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
322 x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
323 x509_buf v3_ext; /**< Optional X.509 v3 extensions. Only Basic Contraints are supported at this time. */
Paul Bakkera8cd2392012-02-11 16:09:32 +0000324 x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000325
Paul Bakker74111d32011-01-15 16:57:55 +0000326 int ext_types; /**< Bit string containing detected and parsed extensions */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000327 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 +0000328 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 +0000329
Paul Bakker74111d32011-01-15 16:57:55 +0000330 unsigned char key_usage; /**< Optional key usage extension value: See the values below */
331
332 x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
333
334 unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values below */
335
Paul Bakker37ca75d2011-01-06 12:28:03 +0000336 x509_buf sig_oid2; /**< Signature algorithm. Must match sig_oid1. */
337 x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
338 int sig_alg; /**< Internal representation of the signature algorithm, e.g. SIG_RSA_MD2 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000339
Paul Bakker37ca75d2011-01-06 12:28:03 +0000340 struct _x509_cert *next; /**< Next certificate in the CA-chain. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000341}
342x509_cert;
343
Paul Bakker37ca75d2011-01-06 12:28:03 +0000344/**
345 * Certificate revocation list entry.
346 * Contains the CA-specific serial numbers and revocation dates.
347 */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000348typedef struct _x509_crl_entry
349{
350 x509_buf raw;
351
352 x509_buf serial;
353
354 x509_time revocation_date;
355
356 x509_buf entry_ext;
357
358 struct _x509_crl_entry *next;
359}
360x509_crl_entry;
361
Paul Bakker37ca75d2011-01-06 12:28:03 +0000362/**
363 * Certificate revocation list structure.
364 * Every CRL may have multiple entries.
365 */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000366typedef struct _x509_crl
367{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000368 x509_buf raw; /**< The raw certificate data (DER). */
369 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000370
371 int version;
372 x509_buf sig_oid1;
373
Paul Bakker37ca75d2011-01-06 12:28:03 +0000374 x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000375
Paul Bakker37ca75d2011-01-06 12:28:03 +0000376 x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000377
Paul Bakker37ca75d2011-01-06 12:28:03 +0000378 x509_time this_update;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000379 x509_time next_update;
380
Paul Bakker37ca75d2011-01-06 12:28:03 +0000381 x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000382
383 x509_buf crl_ext;
384
385 x509_buf sig_oid2;
386 x509_buf sig;
Paul Bakker27d66162010-03-17 06:56:01 +0000387 int sig_alg;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000388
389 struct _x509_crl *next;
390}
391x509_crl;
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000392/** \} name Structures for parsing X.509 certificates and CRLs */
393/** \} addtogroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000394
Paul Bakker37ca75d2011-01-06 12:28:03 +0000395/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000396 * \name Structures for writing X.509 certificates.
Paul Bakker37ca75d2011-01-06 12:28:03 +0000397 * XvP: commented out as they are not used.
398 * - <tt>typedef struct _x509_node x509_node;</tt>
399 * - <tt>typedef struct _x509_raw x509_raw;</tt>
Paul Bakker5121ce52009-01-03 21:22:43 +0000400 */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000401/*
Paul Bakker5121ce52009-01-03 21:22:43 +0000402typedef struct _x509_node
403{
404 unsigned char *data;
405 unsigned char *p;
406 unsigned char *end;
407
408 size_t len;
409}
410x509_node;
411
412typedef struct _x509_raw
413{
414 x509_node raw;
415 x509_node tbs;
416
417 x509_node version;
418 x509_node serial;
419 x509_node tbs_signalg;
420 x509_node issuer;
421 x509_node validity;
422 x509_node subject;
423 x509_node subpubkey;
424
425 x509_node signalg;
426 x509_node sign;
427}
428x509_raw;
Paul Bakker37ca75d2011-01-06 12:28:03 +0000429*/
Paul Bakker5121ce52009-01-03 21:22:43 +0000430
431#ifdef __cplusplus
432extern "C" {
433#endif
434
435/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000436 * \name Functions to read in DHM parameters, a certificate, CRL or private RSA key
437 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000438 */
439
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000440/** \ingroup x509_module */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000441/**
Paul Bakker1922a4e2013-06-06 15:11:16 +0200442 * \brief Parse a single DER formatted certificate and add it
443 * to the chained list.
444 *
445 * \param chain points to the start of the chain
446 * \param buf buffer holding the certificate DER data
447 * \param buflen size of the buffer
448 *
449 * \return 0 if successful, or a specific X509 or PEM error code
450 */
451int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, size_t buflen );
452
453/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000454 * \brief Parse one or more certificates and add them
Paul Bakker69e095c2011-12-10 21:55:01 +0000455 * to the chained list. Parses permissively. If some
456 * certificates can be parsed, the result is the number
457 * of failed certificates it encountered. If none complete
458 * correctly, the first error is returned.
Paul Bakker5121ce52009-01-03 21:22:43 +0000459 *
460 * \param chain points to the start of the chain
461 * \param buf buffer holding the certificate data
462 * \param buflen size of the buffer
463 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000464 * \return 0 if all certificates parsed successfully, a positive number
465 * if partly successful or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000466 */
Paul Bakker69e095c2011-12-10 21:55:01 +0000467int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000468
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000469/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000470/**
471 * \brief Load one or more certificates and add them
Paul Bakker69e095c2011-12-10 21:55:01 +0000472 * to the chained list. Parses permissively. If some
473 * certificates can be parsed, the result is the number
474 * of failed certificates it encountered. If none complete
475 * correctly, the first error is returned.
Paul Bakker5121ce52009-01-03 21:22:43 +0000476 *
477 * \param chain points to the start of the chain
478 * \param path filename to read the certificates from
479 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000480 * \return 0 if all certificates parsed successfully, a positive number
481 * if partly successful or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000482 */
Paul Bakker69e095c2011-12-10 21:55:01 +0000483int x509parse_crtfile( x509_cert *chain, const char *path );
Paul Bakker5121ce52009-01-03 21:22:43 +0000484
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000485/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000486/**
Paul Bakker8d914582012-06-04 12:46:42 +0000487 * \brief Load one or more certificate files from a path and add them
488 * to the chained list. Parses permissively. If some
489 * certificates can be parsed, the result is the number
490 * of failed certificates it encountered. If none complete
491 * correctly, the first error is returned.
492 *
493 * \param chain points to the start of the chain
494 * \param path directory / folder to read the certificate files from
495 *
496 * \return 0 if all certificates parsed successfully, a positive number
497 * if partly successful or a specific X509 or PEM error code
498 */
499int x509parse_crtpath( x509_cert *chain, const char *path );
500
501/** \ingroup x509_module */
502/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000503 * \brief Parse one or more CRLs and add them
504 * to the chained list
505 *
506 * \param chain points to the start of the chain
507 * \param buf buffer holding the CRL data
508 * \param buflen size of the buffer
509 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000510 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakkerd98030e2009-05-02 15:13:40 +0000511 */
Paul Bakker23986e52011-04-24 08:57:21 +0000512int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000513
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000514/** \ingroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000515/**
516 * \brief Load one or more CRLs and add them
517 * to the chained list
518 *
519 * \param chain points to the start of the chain
520 * \param path filename to read the CRLs from
521 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000522 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakkerd98030e2009-05-02 15:13:40 +0000523 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000524int x509parse_crlfile( x509_crl *chain, const char *path );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000525
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000526/** \ingroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000527/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000528 * \brief Parse a private RSA key
529 *
530 * \param rsa RSA context to be initialized
Paul Bakkerff60ee62010-03-16 21:09:09 +0000531 * \param key input buffer
532 * \param keylen size of the buffer
Paul Bakker5121ce52009-01-03 21:22:43 +0000533 * \param pwd password for decryption (optional)
534 * \param pwdlen size of the password
535 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000536 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000537 */
538int x509parse_key( rsa_context *rsa,
Paul Bakker23986e52011-04-24 08:57:21 +0000539 const unsigned char *key, size_t keylen,
540 const unsigned char *pwd, size_t pwdlen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000541
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000542/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000543/**
544 * \brief Load and parse a private RSA key
545 *
546 * \param rsa RSA context to be initialized
547 * \param path filename to read the private key from
Paul Bakker37ca75d2011-01-06 12:28:03 +0000548 * \param password password to decrypt the file (can be NULL)
Paul Bakker5121ce52009-01-03 21:22:43 +0000549 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000550 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000551 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000552int x509parse_keyfile( rsa_context *rsa, const char *path,
553 const char *password );
Paul Bakker1b57b062011-01-06 15:48:19 +0000554
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000555/** \ingroup x509_module */
Paul Bakker1b57b062011-01-06 15:48:19 +0000556/**
Paul Bakker917e7542011-03-25 14:23:36 +0000557 * \brief Parse a public RSA key
558 *
559 * \param rsa RSA context to be initialized
560 * \param key input buffer
561 * \param keylen size of the buffer
562 *
563 * \return 0 if successful, or a specific X509 or PEM error code
564 */
565int x509parse_public_key( rsa_context *rsa,
Paul Bakker23986e52011-04-24 08:57:21 +0000566 const unsigned char *key, size_t keylen );
Paul Bakker917e7542011-03-25 14:23:36 +0000567
568/** \ingroup x509_module */
569/**
570 * \brief Load and parse a public RSA key
571 *
572 * \param rsa RSA context to be initialized
573 * \param path filename to read the private key from
574 *
575 * \return 0 if successful, or a specific X509 or PEM error code
576 */
577int x509parse_public_keyfile( rsa_context *rsa, const char *path );
578
579/** \ingroup x509_module */
580/**
Paul Bakker1b57b062011-01-06 15:48:19 +0000581 * \brief Parse DHM parameters
582 *
583 * \param dhm DHM context to be initialized
584 * \param dhmin input buffer
585 * \param dhminlen size of the buffer
586 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000587 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker1b57b062011-01-06 15:48:19 +0000588 */
Paul Bakker23986e52011-04-24 08:57:21 +0000589int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen );
Paul Bakker1b57b062011-01-06 15:48:19 +0000590
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000591/** \ingroup x509_module */
Paul Bakker1b57b062011-01-06 15:48:19 +0000592/**
593 * \brief Load and parse DHM parameters
594 *
595 * \param dhm DHM context to be initialized
596 * \param path filename to read the DHM Parameters from
597 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000598 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker1b57b062011-01-06 15:48:19 +0000599 */
Paul Bakkerf3b86c12011-01-27 15:24:17 +0000600int x509parse_dhmfile( dhm_context *dhm, const char *path );
Paul Bakker1b57b062011-01-06 15:48:19 +0000601
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000602/** \} name Functions to read in DHM parameters, a certificate, CRL or private RSA key */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000603
Paul Bakker5121ce52009-01-03 21:22:43 +0000604/**
605 * \brief Store the certificate DN in printable form into buf;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000606 * no more than size characters will be written.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000607 *
608 * \param buf Buffer to write to
609 * \param size Maximum size of buffer
610 * \param dn The X509 name to represent
611 *
612 * \return The amount of data written to the buffer, or -1 in
613 * case of an error.
Paul Bakker5121ce52009-01-03 21:22:43 +0000614 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000615int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn );
Paul Bakker5121ce52009-01-03 21:22:43 +0000616
617/**
Paul Bakkerdd476992011-01-16 21:34:59 +0000618 * \brief Store the certificate serial in printable form into buf;
619 * no more than size characters will be written.
620 *
621 * \param buf Buffer to write to
622 * \param size Maximum size of buffer
623 * \param serial The X509 serial to represent
624 *
625 * \return The amount of data written to the buffer, or -1 in
626 * case of an error.
627 */
628int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial );
629
630/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000631 * \brief Returns an informational string about the
632 * certificate.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000633 *
634 * \param buf Buffer to write to
635 * \param size Maximum size of buffer
636 * \param prefix A line prefix
637 * \param crt The X509 certificate to represent
638 *
639 * \return The amount of data written to the buffer, or -1 in
640 * case of an error.
Paul Bakker5121ce52009-01-03 21:22:43 +0000641 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000642int x509parse_cert_info( char *buf, size_t size, const char *prefix,
643 const x509_cert *crt );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000644
645/**
646 * \brief Returns an informational string about the
647 * CRL.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000648 *
649 * \param buf Buffer to write to
650 * \param size Maximum size of buffer
651 * \param prefix A line prefix
Paul Bakker37ca75d2011-01-06 12:28:03 +0000652 * \param crl The X509 CRL to represent
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000653 *
654 * \return The amount of data written to the buffer, or -1 in
655 * case of an error.
Paul Bakkerd98030e2009-05-02 15:13:40 +0000656 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000657int x509parse_crl_info( char *buf, size_t size, const char *prefix,
658 const x509_crl *crl );
Paul Bakker5121ce52009-01-03 21:22:43 +0000659
660/**
Paul Bakker74111d32011-01-15 16:57:55 +0000661 * \brief Give an known OID, return its descriptive string.
662 *
663 * \param oid buffer containing the oid
664 *
665 * \return Return a string if the OID is known,
666 * or NULL otherwise.
667 */
668const char *x509_oid_get_description( x509_buf *oid );
669
Paul Bakker9a736322012-11-14 12:39:52 +0000670/**
Paul Bakker74111d32011-01-15 16:57:55 +0000671 * \brief Give an OID, return a string version of its OID number.
672 *
673 * \param buf Buffer to write to
674 * \param size Maximum size of buffer
675 * \param oid Buffer containing the OID
676 *
677 * \return The amount of data written to the buffer, or -1 in
678 * case of an error.
679 */
680int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid );
681
682/**
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000683 * \brief Check a given x509_time against the system time and check
Paul Bakker0d844dd2014-07-07 17:44:14 +0200684 * if it is not expired.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000685 *
686 * \param time x509_time to check
687 *
Paul Bakker0d844dd2014-07-07 17:44:14 +0200688 * \return 0 if the x509_time is still valid,
Paul Bakker40ea7de2009-05-03 10:18:48 +0000689 * or 1 otherwise.
Paul Bakker5121ce52009-01-03 21:22:43 +0000690 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000691int x509parse_time_expired( const x509_time *time );
Paul Bakker5121ce52009-01-03 21:22:43 +0000692
693/**
Paul Bakker0d844dd2014-07-07 17:44:14 +0200694 * \brief Check a given x509_time against the system time and check
695 * if it is not from the future.
696 *
697 * \param time x509_time to check
698 *
699 * \return 0 if the x509_time is already valid,
700 * or 1 otherwise.
701 */
702int x509parse_time_future( const x509_time *time );
703
704/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000705 * \name Functions to verify a certificate
706 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000707 */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000708/** \ingroup x509_module */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000709/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000710 * \brief Verify the certificate signature
711 *
Paul Bakker915275b2012-09-28 07:10:55 +0000712 * The verify callback is a user-supplied callback that
713 * can clear / modify / add flags for a certificate. If set,
714 * the verification callback is called for each
715 * certificate in the chain (from the trust-ca down to the
716 * presented crt). The parameters for the callback are:
717 * (void *parameter, x509_cert *crt, int certificate_depth,
718 * int *flags). With the flags representing current flags for
719 * that specific certificate and the certificate depth from
Paul Bakker9a736322012-11-14 12:39:52 +0000720 * the bottom (Peer cert depth = 0).
Paul Bakker915275b2012-09-28 07:10:55 +0000721 *
722 * All flags left after returning from the callback
723 * are also returned to the application. The function should
724 * return 0 for anything but a fatal error.
725 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000726 * \param crt a certificate to be verified
727 * \param trust_ca the trusted CA chain
Paul Bakker40ea7de2009-05-03 10:18:48 +0000728 * \param ca_crl the CRL chain for trusted CA's
Paul Bakker5121ce52009-01-03 21:22:43 +0000729 * \param cn expected Common Name (can be set to
730 * NULL if the CN must not be verified)
731 * \param flags result of the verification
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000732 * \param f_vrfy verification function
733 * \param p_vrfy verification parameter
Paul Bakker5121ce52009-01-03 21:22:43 +0000734 *
Paul Bakker40e46942009-01-03 21:51:57 +0000735 * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
Paul Bakker5121ce52009-01-03 21:22:43 +0000736 * in which case *flags will have one or more of
737 * the following values set:
738 * BADCERT_EXPIRED --
739 * BADCERT_REVOKED --
740 * BADCERT_CN_MISMATCH --
741 * BADCERT_NOT_TRUSTED
Paul Bakker915275b2012-09-28 07:10:55 +0000742 * or another error in case of a fatal error encountered
743 * during the verification process.
Paul Bakker5121ce52009-01-03 21:22:43 +0000744 */
745int x509parse_verify( x509_cert *crt,
746 x509_cert *trust_ca,
Paul Bakker40ea7de2009-05-03 10:18:48 +0000747 x509_crl *ca_crl,
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000748 const char *cn, int *flags,
Paul Bakker915275b2012-09-28 07:10:55 +0000749 int (*f_vrfy)(void *, x509_cert *, int, int *),
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000750 void *p_vrfy );
Paul Bakker5121ce52009-01-03 21:22:43 +0000751
Paul Bakker74111d32011-01-15 16:57:55 +0000752/**
753 * \brief Verify the certificate signature
754 *
755 * \param crt a certificate to be verified
756 * \param crl the CRL to verify against
757 *
758 * \return 1 if the certificate is revoked, 0 otherwise
759 *
760 */
761int x509parse_revoked( const x509_cert *crt, const x509_crl *crl );
762
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000763/** \} name Functions to verify a certificate */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000764
765
766
767/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000768 * \name Functions to clear a certificate, CRL or private RSA key
769 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000770 */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000771/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000772/**
773 * \brief Unallocate all certificate data
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000774 *
775 * \param crt Certificate chain to free
Paul Bakker5121ce52009-01-03 21:22:43 +0000776 */
777void x509_free( x509_cert *crt );
778
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000779/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000780/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000781 * \brief Unallocate all CRL data
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000782 *
Paul Bakker37ca75d2011-01-06 12:28:03 +0000783 * \param crl CRL chain to free
Paul Bakkerd98030e2009-05-02 15:13:40 +0000784 */
785void x509_crl_free( x509_crl *crl );
786
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000787/** \} name Functions to clear a certificate, CRL or private RSA key */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000788
789
Paul Bakkerd98030e2009-05-02 15:13:40 +0000790/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000791 * \brief Checkup routine
792 *
793 * \return 0 if successful, or 1 if the test failed
794 */
795int x509_self_test( int verbose );
796
797#ifdef __cplusplus
798}
799#endif
800
801#endif /* x509.h */