blob: 0f3bd07109e8d8cffb4cdc90fbe846c40803ba7e [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 Bakkerefc30292011-11-10 14:43:23 +00006 * Copyright (C) 2006-2011, 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 Bakkerefc30292011-11-10 14:43:23 +000030#include "asn1.h"
Paul Bakker314052f2011-08-15 09:07:52 +000031#include "rsa.h"
32#include "dhm.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000033
Paul Bakker37ca75d2011-01-06 12:28:03 +000034/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000035 * \addtogroup x509_module
36 * \{
Paul Bakker13e2dfe2009-07-28 07:18:38 +000037 */
Paul Bakker37ca75d2011-01-06 12:28:03 +000038
Manuel Pégourié-Gonnard4cdb3ba2014-11-20 17:12:15 +010039#if !defined(POLARSSL_CONFIG_OPTIONS)
40/**
41 * Maximum number of intermediate CAs in a verification chain.
42 * That is, maximum length of the chain, excluding the end-entity certificate
43 * and the trusted root certificate.
44 *
45 * Set this to a low value to prevent an adversary from making you waste
46 * resources verifying an overlong certificate chain.
47 */
48#define POLARSSL_X509_MAX_INTERMEDIATE_CA 8
49#endif
50
Paul Bakker37ca75d2011-01-06 12:28:03 +000051/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000052 * \name X509 Error codes
53 * \{
Paul Bakker13e2dfe2009-07-28 07:18:38 +000054 */
Paul Bakker9d781402011-05-09 16:17:09 +000055#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
56#define POLARSSL_ERR_X509_CERT_INVALID_PEM -0x2100 /**< The PEM-encoded certificate contains invalid elements, e.g. invalid character. */
57#define POLARSSL_ERR_X509_CERT_INVALID_FORMAT -0x2180 /**< The certificate format is invalid, e.g. different type expected. */
58#define POLARSSL_ERR_X509_CERT_INVALID_VERSION -0x2200 /**< The certificate version element is invalid. */
59#define POLARSSL_ERR_X509_CERT_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
60#define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
61#define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
62#define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
63#define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x2480 /**< The pubkey tag or value is invalid (only RSA is supported). */
64#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x2500 /**< The signature tag or value invalid. */
65#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x2580 /**< The extension tag or value is invalid. */
66#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x2600 /**< Certificate or CRL has an unsupported version number. */
67#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x2680 /**< Signature algorithm (oid) is unsupported. */
Paul Bakkered56b222011-07-13 11:26:43 +000068#define POLARSSL_ERR_X509_UNKNOWN_PK_ALG -0x2700 /**< Key algorithm is unsupported (only RSA is supported). */
Paul Bakker9d781402011-05-09 16:17:09 +000069#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x2780 /**< Certificate signature algorithms do not match. (see \c ::x509_cert sig_oid) */
70#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2800 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
71#define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x2880 /**< Unsupported RSA key version */
72#define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x2900 /**< Invalid RSA key tag or value. */
Paul Bakker6c0ceb32011-12-04 12:24:18 +000073#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2980 /**< Format not recognized as DER or PEM. */
Paul Bakker69e095c2011-12-10 21:55:01 +000074#define POLARSSL_ERR_X509_INVALID_INPUT -0x2A00 /**< Input invalid. */
75#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2A80 /**< Allocation of memory failed. */
76#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2B00 /**< Read/write of file failed. */
Paul Bakker1fd43212013-06-17 15:14:42 +020077#define POLARSSL_ERR_X509_PASSWORD_REQUIRED -0x2B80 /**< Private key password can't be empty. */
78#define POLARSSL_ERR_X509_PASSWORD_MISMATCH -0x2C00 /**< Given private key password does not allow for correct decryption. */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000079/* \} name */
Paul Bakker5121ce52009-01-03 21:22:43 +000080
Paul Bakker37ca75d2011-01-06 12:28:03 +000081
82/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +000083 * \name X509 Verify codes
84 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +000085 */
Paul Bakkercdf07e92011-01-30 17:05:13 +000086#define BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
87#define BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
88#define BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
89#define BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
90#define BADCRL_NOT_TRUSTED 0x10 /**< CRL is not correctly signed by the trusted CA. */
91#define BADCRL_EXPIRED 0x20 /**< CRL is expired. */
92#define BADCERT_MISSING 0x40 /**< Certificate was missing. */
93#define BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
Paul Bakker915275b2012-09-28 07:10:55 +000094#define BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
Paul Bakker50a5c532014-07-08 10:59:10 +020095#define BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
96#define BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
97
Paul Bakker0f5f72e2011-01-18 14:58:55 +000098/* \} name */
Paul Bakker0f5f72e2011-01-18 14:58:55 +000099/* \} addtogroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000100
101/*
102 * various object identifiers
103 */
104#define X520_COMMON_NAME 3
105#define X520_COUNTRY 6
106#define X520_LOCALITY 7
107#define X520_STATE 8
108#define X520_ORGANIZATION 10
109#define X520_ORG_UNIT 11
110#define PKCS9_EMAIL 1
111
112#define X509_OUTPUT_DER 0x01
113#define X509_OUTPUT_PEM 0x02
114#define PEM_LINE_LENGTH 72
115#define X509_ISSUER 0x01
116#define X509_SUBJECT 0x02
117
118#define OID_X520 "\x55\x04"
Paul Bakker74111d32011-01-15 16:57:55 +0000119#define OID_CN OID_X520 "\x03"
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000120#define OID_COUNTRY OID_X520 "\x06"
121#define OID_LOCALITY OID_X520 "\x07"
122#define OID_STATE OID_X520 "\x08"
123#define OID_ORGANIZATION OID_X520 "\x0A"
124#define OID_ORG_UNIT OID_X520 "\x0B"
Paul Bakker74111d32011-01-15 16:57:55 +0000125
Paul Bakker5121ce52009-01-03 21:22:43 +0000126#define OID_PKCS1 "\x2A\x86\x48\x86\xF7\x0D\x01\x01"
Paul Bakker74111d32011-01-15 16:57:55 +0000127#define OID_PKCS1_RSA OID_PKCS1 "\x01"
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000128#define OID_PKCS1_SHA1 OID_PKCS1 "\x05"
Paul Bakker400ff6f2011-02-20 10:40:16 +0000129
130#define OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
Paul Bakker74111d32011-01-15 16:57:55 +0000131
Paul Bakker5121ce52009-01-03 21:22:43 +0000132#define OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09"
Paul Bakker74111d32011-01-15 16:57:55 +0000133#define OID_PKCS9_EMAIL OID_PKCS9 "\x01"
134
135/** ISO arc for standard certificate and CRL extensions */
136#define OID_ID_CE "\x55\x1D" /**< id-ce OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 29} */
137
138/**
139 * Private Internet Extensions
140 * { iso(1) identified-organization(3) dod(6) internet(1)
141 * security(5) mechanisms(5) pkix(7) }
142 */
143#define OID_PKIX "\x2B\x06\x01\x05\x05\x07"
144
145/*
146 * OIDs for standard certificate extensions
147 */
148#define OID_AUTHORITY_KEY_IDENTIFIER OID_ID_CE "\x23" /**< id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } */
149#define OID_SUBJECT_KEY_IDENTIFIER OID_ID_CE "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */
150#define OID_KEY_USAGE OID_ID_CE "\x0F" /**< id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } */
151#define OID_CERTIFICATE_POLICIES OID_ID_CE "\x20" /**< id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } */
152#define OID_POLICY_MAPPINGS OID_ID_CE "\x21" /**< id-ce-policyMappings OBJECT IDENTIFIER ::= { id-ce 33 } */
153#define OID_SUBJECT_ALT_NAME OID_ID_CE "\x11" /**< id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } */
154#define OID_ISSUER_ALT_NAME OID_ID_CE "\x12" /**< id-ce-issuerAltName OBJECT IDENTIFIER ::= { id-ce 18 } */
155#define OID_SUBJECT_DIRECTORY_ATTRS OID_ID_CE "\x09" /**< id-ce-subjectDirectoryAttributes OBJECT IDENTIFIER ::= { id-ce 9 } */
156#define OID_BASIC_CONSTRAINTS OID_ID_CE "\x13" /**< id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } */
157#define OID_NAME_CONSTRAINTS OID_ID_CE "\x1E" /**< id-ce-nameConstraints OBJECT IDENTIFIER ::= { id-ce 30 } */
158#define OID_POLICY_CONSTRAINTS OID_ID_CE "\x24" /**< id-ce-policyConstraints OBJECT IDENTIFIER ::= { id-ce 36 } */
159#define OID_EXTENDED_KEY_USAGE OID_ID_CE "\x25" /**< id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } */
160#define OID_CRL_DISTRIBUTION_POINTS OID_ID_CE "\x1F" /**< id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } */
161#define OID_INIHIBIT_ANYPOLICY OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */
162#define OID_FRESHEST_CRL OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */
163
164/*
165 * X.509 v3 Key Usage Extension flags
166 */
167#define KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
168#define KU_NON_REPUDIATION (0x40) /* bit 1 */
169#define KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
170#define KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
171#define KU_KEY_AGREEMENT (0x08) /* bit 4 */
172#define KU_KEY_CERT_SIGN (0x04) /* bit 5 */
173#define KU_CRL_SIGN (0x02) /* bit 6 */
174
175/*
176 * X.509 v3 Extended key usage OIDs
177 */
178#define OID_ANY_EXTENDED_KEY_USAGE OID_EXTENDED_KEY_USAGE "\x00" /**< anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 } */
179
180#define OID_KP OID_PKIX "\x03" /**< id-kp OBJECT IDENTIFIER ::= { id-pkix 3 } */
181#define OID_SERVER_AUTH OID_KP "\x01" /**< id-kp-serverAuth OBJECT IDENTIFIER ::= { id-kp 1 } */
182#define OID_CLIENT_AUTH OID_KP "\x02" /**< id-kp-clientAuth OBJECT IDENTIFIER ::= { id-kp 2 } */
183#define OID_CODE_SIGNING OID_KP "\x03" /**< id-kp-codeSigning OBJECT IDENTIFIER ::= { id-kp 3 } */
184#define OID_EMAIL_PROTECTION OID_KP "\x04" /**< id-kp-emailProtection OBJECT IDENTIFIER ::= { id-kp 4 } */
185#define OID_TIME_STAMPING OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */
186#define OID_OCSP_SIGNING OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */
187
188#define STRING_SERVER_AUTH "TLS Web Server Authentication"
189#define STRING_CLIENT_AUTH "TLS Web Client Authentication"
190#define STRING_CODE_SIGNING "Code Signing"
191#define STRING_EMAIL_PROTECTION "E-mail Protection"
192#define STRING_TIME_STAMPING "Time Stamping"
193#define STRING_OCSP_SIGNING "OCSP Signing"
194
195/*
196 * OIDs for CRL extensions
197 */
198#define OID_PRIVATE_KEY_USAGE_PERIOD OID_ID_CE "\x10"
199#define OID_CRL_NUMBER OID_ID_CE "\x14" /**< id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } */
200
201/*
202 * Netscape certificate extensions
203 */
204#define OID_NETSCAPE "\x60\x86\x48\x01\x86\xF8\x42" /**< Netscape OID */
205#define OID_NS_CERT OID_NETSCAPE "\x01"
206#define OID_NS_CERT_TYPE OID_NS_CERT "\x01"
207#define OID_NS_BASE_URL OID_NS_CERT "\x02"
208#define OID_NS_REVOCATION_URL OID_NS_CERT "\x03"
209#define OID_NS_CA_REVOCATION_URL OID_NS_CERT "\x04"
210#define OID_NS_RENEWAL_URL OID_NS_CERT "\x07"
211#define OID_NS_CA_POLICY_URL OID_NS_CERT "\x08"
212#define OID_NS_SSL_SERVER_NAME OID_NS_CERT "\x0C"
213#define OID_NS_COMMENT OID_NS_CERT "\x0D"
214#define OID_NS_DATA_TYPE OID_NETSCAPE "\x02"
215#define OID_NS_CERT_SEQUENCE OID_NS_DATA_TYPE "\x05"
216
217/*
218 * Netscape certificate types
219 * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
220 */
221
222#define NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
223#define NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
224#define NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
225#define NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
226#define NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
227#define NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
228#define NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
229#define NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
230
231#define EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
232#define EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
233#define EXT_KEY_USAGE (1 << 2)
234#define EXT_CERTIFICATE_POLICIES (1 << 3)
235#define EXT_POLICY_MAPPINGS (1 << 4)
236#define EXT_SUBJECT_ALT_NAME (1 << 5)
237#define EXT_ISSUER_ALT_NAME (1 << 6)
238#define EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
239#define EXT_BASIC_CONSTRAINTS (1 << 8)
240#define EXT_NAME_CONSTRAINTS (1 << 9)
241#define EXT_POLICY_CONSTRAINTS (1 << 10)
242#define EXT_EXTENDED_KEY_USAGE (1 << 11)
243#define EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
244#define EXT_INIHIBIT_ANYPOLICY (1 << 13)
245#define EXT_FRESHEST_CRL (1 << 14)
246
247#define EXT_NS_CERT_TYPE (1 << 16)
Paul Bakker5121ce52009-01-03 21:22:43 +0000248
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000249/*
250 * Storage format identifiers
251 * Recognized formats: PEM and DER
252 */
253#define X509_FORMAT_DER 1
254#define X509_FORMAT_PEM 2
255
Paul Bakker37ca75d2011-01-06 12:28:03 +0000256/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000257 * \addtogroup x509_module
258 * \{ */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000259
260/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000261 * \name Structures for parsing X.509 certificates and CRLs
262 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000263 */
264
265/**
266 * Type-length-value structure that allows for ASN1 using DER.
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000268typedef asn1_buf x509_buf;
Paul Bakker5121ce52009-01-03 21:22:43 +0000269
Paul Bakker37ca75d2011-01-06 12:28:03 +0000270/**
Paul Bakker74111d32011-01-15 16:57:55 +0000271 * Container for ASN1 bit strings.
272 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000273typedef asn1_bitstring x509_bitstring;
Paul Bakker74111d32011-01-15 16:57:55 +0000274
275/**
Paul Bakker37ca75d2011-01-06 12:28:03 +0000276 * Container for ASN1 named information objects.
277 * It allows for Relative Distinguished Names (e.g. cn=polarssl,ou=code,etc.).
278 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000279typedef struct _x509_name
280{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000281 x509_buf oid; /**< The object identifier. */
282 x509_buf val; /**< The named value. */
283 struct _x509_name *next; /**< The next named information object. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000284}
285x509_name;
286
Paul Bakker74111d32011-01-15 16:57:55 +0000287/**
288 * Container for a sequence of ASN.1 items
289 */
Paul Bakkerefc30292011-11-10 14:43:23 +0000290typedef asn1_sequence x509_sequence;
Paul Bakker74111d32011-01-15 16:57:55 +0000291
Paul Bakker37ca75d2011-01-06 12:28:03 +0000292/** Container for date and time (precision in seconds). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000293typedef struct _x509_time
294{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000295 int year, mon, day; /**< Date. */
296 int hour, min, sec; /**< Time. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000297}
298x509_time;
299
Paul Bakker37ca75d2011-01-06 12:28:03 +0000300/**
301 * Container for an X.509 certificate. The certificate may be chained.
302 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000303typedef struct _x509_cert
304{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000305 x509_buf raw; /**< The raw certificate data (DER). */
306 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000307
Paul Bakker37ca75d2011-01-06 12:28:03 +0000308 int version; /**< The X.509 version. (0=v1, 1=v2, 2=v3) */
309 x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
310 x509_buf sig_oid1; /**< Signature algorithm, e.g. sha1RSA */
Paul Bakker5121ce52009-01-03 21:22:43 +0000311
Paul Bakker37ca75d2011-01-06 12:28:03 +0000312 x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
313 x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000314
Paul Bakker37ca75d2011-01-06 12:28:03 +0000315 x509_name issuer; /**< The parsed issuer data (named information object). */
316 x509_name subject; /**< The parsed subject data (named information object). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000317
Paul Bakker37ca75d2011-01-06 12:28:03 +0000318 x509_time valid_from; /**< Start time of certificate validity. */
319 x509_time valid_to; /**< End time of certificate validity. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000320
Paul Bakker37ca75d2011-01-06 12:28:03 +0000321 x509_buf pk_oid; /**< Subject public key info. Includes the public key algorithm and the key itself. */
322 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 +0000323
Paul Bakker37ca75d2011-01-06 12:28:03 +0000324 x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
325 x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
326 x509_buf v3_ext; /**< Optional X.509 v3 extensions. Only Basic Contraints are supported at this time. */
Paul Bakkera8cd2392012-02-11 16:09:32 +0000327 x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
Paul Bakker5121ce52009-01-03 21:22:43 +0000328
Paul Bakker74111d32011-01-15 16:57:55 +0000329 int ext_types; /**< Bit string containing detected and parsed extensions */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000330 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 +0000331 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 +0000332
Paul Bakker74111d32011-01-15 16:57:55 +0000333 unsigned char key_usage; /**< Optional key usage extension value: See the values below */
334
335 x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
336
337 unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values below */
338
Paul Bakker37ca75d2011-01-06 12:28:03 +0000339 x509_buf sig_oid2; /**< Signature algorithm. Must match sig_oid1. */
340 x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
341 int sig_alg; /**< Internal representation of the signature algorithm, e.g. SIG_RSA_MD2 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000342
Paul Bakker37ca75d2011-01-06 12:28:03 +0000343 struct _x509_cert *next; /**< Next certificate in the CA-chain. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000344}
345x509_cert;
346
Paul Bakker37ca75d2011-01-06 12:28:03 +0000347/**
348 * Certificate revocation list entry.
349 * Contains the CA-specific serial numbers and revocation dates.
350 */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000351typedef struct _x509_crl_entry
352{
353 x509_buf raw;
354
355 x509_buf serial;
356
357 x509_time revocation_date;
358
359 x509_buf entry_ext;
360
361 struct _x509_crl_entry *next;
362}
363x509_crl_entry;
364
Paul Bakker37ca75d2011-01-06 12:28:03 +0000365/**
366 * Certificate revocation list structure.
367 * Every CRL may have multiple entries.
368 */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000369typedef struct _x509_crl
370{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000371 x509_buf raw; /**< The raw certificate data (DER). */
372 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000373
374 int version;
375 x509_buf sig_oid1;
376
Paul Bakker37ca75d2011-01-06 12:28:03 +0000377 x509_buf issuer_raw; /**< The raw issuer data (DER). */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000378
Paul Bakker37ca75d2011-01-06 12:28:03 +0000379 x509_name issuer; /**< The parsed issuer data (named information object). */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000380
Paul Bakker37ca75d2011-01-06 12:28:03 +0000381 x509_time this_update;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000382 x509_time next_update;
383
Paul Bakker37ca75d2011-01-06 12:28:03 +0000384 x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000385
386 x509_buf crl_ext;
387
388 x509_buf sig_oid2;
389 x509_buf sig;
Paul Bakker27d66162010-03-17 06:56:01 +0000390 int sig_alg;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000391
392 struct _x509_crl *next;
393}
394x509_crl;
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000395/** \} name Structures for parsing X.509 certificates and CRLs */
396/** \} addtogroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000397
Paul Bakker37ca75d2011-01-06 12:28:03 +0000398/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000399 * \name Structures for writing X.509 certificates.
Paul Bakker37ca75d2011-01-06 12:28:03 +0000400 * XvP: commented out as they are not used.
401 * - <tt>typedef struct _x509_node x509_node;</tt>
402 * - <tt>typedef struct _x509_raw x509_raw;</tt>
Paul Bakker5121ce52009-01-03 21:22:43 +0000403 */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000404/*
Paul Bakker5121ce52009-01-03 21:22:43 +0000405typedef struct _x509_node
406{
407 unsigned char *data;
408 unsigned char *p;
409 unsigned char *end;
410
411 size_t len;
412}
413x509_node;
414
415typedef struct _x509_raw
416{
417 x509_node raw;
418 x509_node tbs;
419
420 x509_node version;
421 x509_node serial;
422 x509_node tbs_signalg;
423 x509_node issuer;
424 x509_node validity;
425 x509_node subject;
426 x509_node subpubkey;
427
428 x509_node signalg;
429 x509_node sign;
430}
431x509_raw;
Paul Bakker37ca75d2011-01-06 12:28:03 +0000432*/
Paul Bakker5121ce52009-01-03 21:22:43 +0000433
434#ifdef __cplusplus
435extern "C" {
436#endif
437
438/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000439 * \name Functions to read in DHM parameters, a certificate, CRL or private RSA key
440 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000441 */
442
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000443/** \ingroup x509_module */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000444/**
Paul Bakker1922a4e2013-06-06 15:11:16 +0200445 * \brief Parse a single DER formatted certificate and add it
446 * to the chained list.
447 *
448 * \param chain points to the start of the chain
449 * \param buf buffer holding the certificate DER data
450 * \param buflen size of the buffer
451 *
452 * \return 0 if successful, or a specific X509 or PEM error code
453 */
454int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, size_t buflen );
455
456/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000457 * \brief Parse one or more certificates and add them
Paul Bakker69e095c2011-12-10 21:55:01 +0000458 * to the chained list. Parses permissively. If some
459 * certificates can be parsed, the result is the number
460 * of failed certificates it encountered. If none complete
461 * correctly, the first error is returned.
Paul Bakker5121ce52009-01-03 21:22:43 +0000462 *
463 * \param chain points to the start of the chain
464 * \param buf buffer holding the certificate data
465 * \param buflen size of the buffer
466 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000467 * \return 0 if all certificates parsed successfully, a positive number
468 * if partly successful or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000469 */
Paul Bakker69e095c2011-12-10 21:55:01 +0000470int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000471
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000472/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000473/**
474 * \brief Load one or more certificates and add them
Paul Bakker69e095c2011-12-10 21:55:01 +0000475 * to the chained list. Parses permissively. If some
476 * certificates can be parsed, the result is the number
477 * of failed certificates it encountered. If none complete
478 * correctly, the first error is returned.
Paul Bakker5121ce52009-01-03 21:22:43 +0000479 *
480 * \param chain points to the start of the chain
481 * \param path filename to read the certificates from
482 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000483 * \return 0 if all certificates parsed successfully, a positive number
484 * if partly successful or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000485 */
Paul Bakker69e095c2011-12-10 21:55:01 +0000486int x509parse_crtfile( x509_cert *chain, const char *path );
Paul Bakker5121ce52009-01-03 21:22:43 +0000487
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000488/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000489/**
Paul Bakker8d914582012-06-04 12:46:42 +0000490 * \brief Load one or more certificate files from a path and add them
491 * to the chained list. Parses permissively. If some
492 * certificates can be parsed, the result is the number
493 * of failed certificates it encountered. If none complete
494 * correctly, the first error is returned.
495 *
496 * \param chain points to the start of the chain
497 * \param path directory / folder to read the certificate files from
498 *
499 * \return 0 if all certificates parsed successfully, a positive number
500 * if partly successful or a specific X509 or PEM error code
501 */
502int x509parse_crtpath( x509_cert *chain, const char *path );
503
504/** \ingroup x509_module */
505/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000506 * \brief Parse one or more CRLs and add them
507 * to the chained list
508 *
509 * \param chain points to the start of the chain
510 * \param buf buffer holding the CRL data
511 * \param buflen size of the buffer
512 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000513 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakkerd98030e2009-05-02 15:13:40 +0000514 */
Paul Bakker23986e52011-04-24 08:57:21 +0000515int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000516
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000517/** \ingroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000518/**
519 * \brief Load one or more CRLs and add them
520 * to the chained list
521 *
522 * \param chain points to the start of the chain
523 * \param path filename to read the CRLs from
524 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000525 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakkerd98030e2009-05-02 15:13:40 +0000526 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000527int x509parse_crlfile( x509_crl *chain, const char *path );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000528
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000529/** \ingroup x509_module */
Paul Bakkerd98030e2009-05-02 15:13:40 +0000530/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000531 * \brief Parse a private RSA key
532 *
533 * \param rsa RSA context to be initialized
Paul Bakkerff60ee62010-03-16 21:09:09 +0000534 * \param key input buffer
535 * \param keylen size of the buffer
Paul Bakker5121ce52009-01-03 21:22:43 +0000536 * \param pwd password for decryption (optional)
537 * \param pwdlen size of the password
538 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000539 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000540 */
541int x509parse_key( rsa_context *rsa,
Paul Bakker23986e52011-04-24 08:57:21 +0000542 const unsigned char *key, size_t keylen,
543 const unsigned char *pwd, size_t pwdlen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000544
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000545/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000546/**
547 * \brief Load and parse a private RSA key
548 *
549 * \param rsa RSA context to be initialized
550 * \param path filename to read the private key from
Paul Bakker37ca75d2011-01-06 12:28:03 +0000551 * \param password password to decrypt the file (can be NULL)
Paul Bakker5121ce52009-01-03 21:22:43 +0000552 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000553 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker5121ce52009-01-03 21:22:43 +0000554 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000555int x509parse_keyfile( rsa_context *rsa, const char *path,
556 const char *password );
Paul Bakker1b57b062011-01-06 15:48:19 +0000557
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000558/** \ingroup x509_module */
Paul Bakker1b57b062011-01-06 15:48:19 +0000559/**
Paul Bakker917e7542011-03-25 14:23:36 +0000560 * \brief Parse a public RSA key
561 *
562 * \param rsa RSA context to be initialized
563 * \param key input buffer
564 * \param keylen size of the buffer
565 *
566 * \return 0 if successful, or a specific X509 or PEM error code
567 */
568int x509parse_public_key( rsa_context *rsa,
Paul Bakker23986e52011-04-24 08:57:21 +0000569 const unsigned char *key, size_t keylen );
Paul Bakker917e7542011-03-25 14:23:36 +0000570
571/** \ingroup x509_module */
572/**
573 * \brief Load and parse a public RSA key
574 *
575 * \param rsa RSA context to be initialized
576 * \param path filename to read the private key from
577 *
578 * \return 0 if successful, or a specific X509 or PEM error code
579 */
580int x509parse_public_keyfile( rsa_context *rsa, const char *path );
581
582/** \ingroup x509_module */
583/**
Paul Bakker1b57b062011-01-06 15:48:19 +0000584 * \brief Parse DHM parameters
585 *
586 * \param dhm DHM context to be initialized
587 * \param dhmin input buffer
588 * \param dhminlen size of the buffer
589 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000590 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker1b57b062011-01-06 15:48:19 +0000591 */
Paul Bakker23986e52011-04-24 08:57:21 +0000592int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen );
Paul Bakker1b57b062011-01-06 15:48:19 +0000593
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000594/** \ingroup x509_module */
Paul Bakker1b57b062011-01-06 15:48:19 +0000595/**
596 * \brief Load and parse DHM parameters
597 *
598 * \param dhm DHM context to be initialized
599 * \param path filename to read the DHM Parameters from
600 *
Paul Bakker96743fc2011-02-12 14:30:57 +0000601 * \return 0 if successful, or a specific X509 or PEM error code
Paul Bakker1b57b062011-01-06 15:48:19 +0000602 */
Paul Bakkerf3b86c12011-01-27 15:24:17 +0000603int x509parse_dhmfile( dhm_context *dhm, const char *path );
Paul Bakker1b57b062011-01-06 15:48:19 +0000604
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000605/** \} name Functions to read in DHM parameters, a certificate, CRL or private RSA key */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000606
Paul Bakker5121ce52009-01-03 21:22:43 +0000607/**
608 * \brief Store the certificate DN in printable form into buf;
Paul Bakkerd98030e2009-05-02 15:13:40 +0000609 * no more than size characters will be written.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000610 *
611 * \param buf Buffer to write to
612 * \param size Maximum size of buffer
613 * \param dn The X509 name to represent
614 *
615 * \return The amount of data written to the buffer, or -1 in
616 * case of an error.
Paul Bakker5121ce52009-01-03 21:22:43 +0000617 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000618int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn );
Paul Bakker5121ce52009-01-03 21:22:43 +0000619
620/**
Paul Bakkerdd476992011-01-16 21:34:59 +0000621 * \brief Store the certificate serial in printable form into buf;
622 * no more than size characters will be written.
623 *
624 * \param buf Buffer to write to
625 * \param size Maximum size of buffer
626 * \param serial The X509 serial to represent
627 *
628 * \return The amount of data written to the buffer, or -1 in
629 * case of an error.
630 */
631int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial );
632
633/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000634 * \brief Returns an informational string about the
635 * certificate.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000636 *
637 * \param buf Buffer to write to
638 * \param size Maximum size of buffer
639 * \param prefix A line prefix
640 * \param crt The X509 certificate to represent
641 *
642 * \return The amount of data written to the buffer, or -1 in
643 * case of an error.
Paul Bakker5121ce52009-01-03 21:22:43 +0000644 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000645int x509parse_cert_info( char *buf, size_t size, const char *prefix,
646 const x509_cert *crt );
Paul Bakkerd98030e2009-05-02 15:13:40 +0000647
648/**
649 * \brief Returns an informational string about the
650 * CRL.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000651 *
652 * \param buf Buffer to write to
653 * \param size Maximum size of buffer
654 * \param prefix A line prefix
Paul Bakker37ca75d2011-01-06 12:28:03 +0000655 * \param crl The X509 CRL to represent
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000656 *
657 * \return The amount of data written to the buffer, or -1 in
658 * case of an error.
Paul Bakkerd98030e2009-05-02 15:13:40 +0000659 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000660int x509parse_crl_info( char *buf, size_t size, const char *prefix,
661 const x509_crl *crl );
Paul Bakker5121ce52009-01-03 21:22:43 +0000662
663/**
Paul Bakker74111d32011-01-15 16:57:55 +0000664 * \brief Give an known OID, return its descriptive string.
665 *
666 * \param oid buffer containing the oid
667 *
668 * \return Return a string if the OID is known,
669 * or NULL otherwise.
670 */
671const char *x509_oid_get_description( x509_buf *oid );
672
Paul Bakker9a736322012-11-14 12:39:52 +0000673/**
Paul Bakker74111d32011-01-15 16:57:55 +0000674 * \brief Give an OID, return a string version of its OID number.
675 *
676 * \param buf Buffer to write to
677 * \param size Maximum size of buffer
678 * \param oid Buffer containing the OID
679 *
680 * \return The amount of data written to the buffer, or -1 in
681 * case of an error.
682 */
683int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid );
684
685/**
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000686 * \brief Check a given x509_time against the system time and check
Paul Bakker0d844dd2014-07-07 17:44:14 +0200687 * if it is not expired.
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000688 *
689 * \param time x509_time to check
690 *
Paul Bakker0d844dd2014-07-07 17:44:14 +0200691 * \return 0 if the x509_time is still valid,
Paul Bakker40ea7de2009-05-03 10:18:48 +0000692 * or 1 otherwise.
Paul Bakker5121ce52009-01-03 21:22:43 +0000693 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000694int x509parse_time_expired( const x509_time *time );
Paul Bakker5121ce52009-01-03 21:22:43 +0000695
696/**
Paul Bakker0d844dd2014-07-07 17:44:14 +0200697 * \brief Check a given x509_time against the system time and check
698 * if it is not from the future.
699 *
700 * \param time x509_time to check
701 *
702 * \return 0 if the x509_time is already valid,
703 * or 1 otherwise.
704 */
705int x509parse_time_future( const x509_time *time );
706
707/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000708 * \name Functions to verify a certificate
709 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000710 */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000711/** \ingroup x509_module */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000712/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000713 * \brief Verify the certificate signature
714 *
Paul Bakker915275b2012-09-28 07:10:55 +0000715 * The verify callback is a user-supplied callback that
716 * can clear / modify / add flags for a certificate. If set,
717 * the verification callback is called for each
718 * certificate in the chain (from the trust-ca down to the
719 * presented crt). The parameters for the callback are:
720 * (void *parameter, x509_cert *crt, int certificate_depth,
721 * int *flags). With the flags representing current flags for
722 * that specific certificate and the certificate depth from
Paul Bakker9a736322012-11-14 12:39:52 +0000723 * the bottom (Peer cert depth = 0).
Paul Bakker915275b2012-09-28 07:10:55 +0000724 *
725 * All flags left after returning from the callback
726 * are also returned to the application. The function should
727 * return 0 for anything but a fatal error.
728 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000729 * \param crt a certificate to be verified
730 * \param trust_ca the trusted CA chain
Paul Bakker40ea7de2009-05-03 10:18:48 +0000731 * \param ca_crl the CRL chain for trusted CA's
Paul Bakker5121ce52009-01-03 21:22:43 +0000732 * \param cn expected Common Name (can be set to
733 * NULL if the CN must not be verified)
734 * \param flags result of the verification
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000735 * \param f_vrfy verification function
736 * \param p_vrfy verification parameter
Paul Bakker5121ce52009-01-03 21:22:43 +0000737 *
Paul Bakker40e46942009-01-03 21:51:57 +0000738 * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
Paul Bakker5121ce52009-01-03 21:22:43 +0000739 * in which case *flags will have one or more of
740 * the following values set:
741 * BADCERT_EXPIRED --
742 * BADCERT_REVOKED --
743 * BADCERT_CN_MISMATCH --
744 * BADCERT_NOT_TRUSTED
Paul Bakker915275b2012-09-28 07:10:55 +0000745 * or another error in case of a fatal error encountered
746 * during the verification process.
Paul Bakker5121ce52009-01-03 21:22:43 +0000747 */
748int x509parse_verify( x509_cert *crt,
749 x509_cert *trust_ca,
Paul Bakker40ea7de2009-05-03 10:18:48 +0000750 x509_crl *ca_crl,
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000751 const char *cn, int *flags,
Paul Bakker915275b2012-09-28 07:10:55 +0000752 int (*f_vrfy)(void *, x509_cert *, int, int *),
Paul Bakkerb63b0af2011-01-13 17:54:59 +0000753 void *p_vrfy );
Paul Bakker5121ce52009-01-03 21:22:43 +0000754
Paul Bakker74111d32011-01-15 16:57:55 +0000755/**
756 * \brief Verify the certificate signature
757 *
758 * \param crt a certificate to be verified
759 * \param crl the CRL to verify against
760 *
761 * \return 1 if the certificate is revoked, 0 otherwise
762 *
763 */
764int x509parse_revoked( const x509_cert *crt, const x509_crl *crl );
765
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000766/** \} name Functions to verify a certificate */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000767
768
769
770/**
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000771 * \name Functions to clear a certificate, CRL or private RSA key
772 * \{
Paul Bakker37ca75d2011-01-06 12:28:03 +0000773 */
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000774/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000775/**
776 * \brief Unallocate all certificate data
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000777 *
778 * \param crt Certificate chain to free
Paul Bakker5121ce52009-01-03 21:22:43 +0000779 */
780void x509_free( x509_cert *crt );
781
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000782/** \ingroup x509_module */
Paul Bakker5121ce52009-01-03 21:22:43 +0000783/**
Paul Bakkerd98030e2009-05-02 15:13:40 +0000784 * \brief Unallocate all CRL data
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000785 *
Paul Bakker37ca75d2011-01-06 12:28:03 +0000786 * \param crl CRL chain to free
Paul Bakkerd98030e2009-05-02 15:13:40 +0000787 */
788void x509_crl_free( x509_crl *crl );
789
Paul Bakker0f5f72e2011-01-18 14:58:55 +0000790/** \} name Functions to clear a certificate, CRL or private RSA key */
Paul Bakker37ca75d2011-01-06 12:28:03 +0000791
792
Paul Bakkerd98030e2009-05-02 15:13:40 +0000793/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000794 * \brief Checkup routine
795 *
796 * \return 0 if successful, or 1 if the test failed
797 */
798int x509_self_test( int verbose );
799
800#ifdef __cplusplus
801}
802#endif
803
804#endif /* x509.h */