blob: d24204db3ff3fe572261bd2492e85118fc96ca4e [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file x509_crt.h
Paul Bakker7c6b2c32013-09-16 13:49:26 +02003 *
4 * \brief X.509 certificate parsing and writing
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_X509_CRT_H
25#define MBEDTLS_X509_CRT_H
Paul Bakker7c6b2c32013-09-16 13:49:26 +020026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero6609aef2019-07-04 20:01:14 +010028#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020032
Jaeden Amero6609aef2019-07-04 20:01:14 +010033#include "mbedtls/x509.h"
34#include "mbedtls/x509_crl.h"
35#include "mbedtls/bignum.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020036
37/**
38 * \addtogroup x509_module
39 * \{
40 */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 * \name Structures and functions for parsing and writing X.509 certificates
48 * \{
49 */
50
51/**
52 * Container for an X.509 certificate. The certificate may be chained.
53 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054typedef struct mbedtls_x509_crt
Paul Bakker7c6b2c32013-09-16 13:49:26 +020055{
Hanno Becker1a65dcd2019-01-31 08:57:44 +000056 int own_buffer; /**< Indicates if \c raw is owned
57 * by the structure or not. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
59 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020060
Manuel Pégourié-Gonnardf4e1b642014-06-19 11:39:46 +020061 int version; /**< The X.509 version. (1=v1, 2=v2, 3=v3) */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062 mbedtls_x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
63 mbedtls_x509_buf sig_oid; /**< Signature algorithm, e.g. sha1RSA */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020064
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
66 mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020067
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
69 mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020070
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071 mbedtls_x509_time valid_from; /**< Start time of certificate validity. */
72 mbedtls_x509_time valid_to; /**< End time of certificate validity. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020073
Hanno Becker494dd7a2019-02-06 16:13:41 +000074 mbedtls_x509_buf pk_raw;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 mbedtls_pk_context pk; /**< Container for the public key context. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020076
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077 mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
78 mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
79 mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
Ron Eldor78c30402019-05-13 15:49:53 +030080 mbedtls_x509_sequence subject_alt_names; /**< Optional list of raw entries of Subject Alternative Names extension (currently only dNSName and OtherName are listed). */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020081
Ron Eldorc8b5f3f2019-05-15 15:15:55 +030082 mbedtls_x509_sequence certificate_policies; /**< Optional list of certificate policies (Only anyPolicy is printed and enforced, however the rest of the policies are still listed). */
Ron Eldor74d9acc2019-03-21 14:00:03 +020083
Paul Bakker7c6b2c32013-09-16 13:49:26 +020084 int ext_types; /**< Bit string containing detected and parsed extensions */
85 int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
86 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+ */
87
Manuel Pégourié-Gonnard1d0ca1a2015-03-27 16:50:00 +010088 unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020089
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090 mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020091
Manuel Pégourié-Gonnardb28487d2014-04-01 12:19:09 +020092 unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020093
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094 mbedtls_x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
95 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
96 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
97 void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020098
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099 struct mbedtls_x509_crt *next; /**< Next certificate in the CA-chain. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101mbedtls_x509_crt;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200102
Janos Follath5091bec2019-05-08 15:23:08 +0100103/**
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200104 * From RFC 5280 section 4.2.1.6:
105 * OtherName ::= SEQUENCE {
106 * type-id OBJECT IDENTIFIER,
107 * value [0] EXPLICIT ANY DEFINED BY type-id }
108 */
109typedef struct mbedtls_x509_san_other_name
110{
Ron Eldor890819a2019-05-13 19:03:04 +0300111 /**
112 * The type_id is an OID as deifned in RFC 5280.
113 * To check the value of the type id, you should use
114 * \p MBEDTLS_OID_CMP with a known OID mbedtls_x509_buf.
115 */
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200116 mbedtls_x509_buf type_id; /**< The type id. */
117 union
118 {
Janos Follath5091bec2019-05-08 15:23:08 +0100119 /**
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200120 * From RFC 4108 section 5:
121 * HardwareModuleName ::= SEQUENCE {
122 * hwType OBJECT IDENTIFIER,
123 * hwSerialNum OCTET STRING }
124 */
Ron Eldorf05f5942019-05-13 19:11:31 +0300125 struct
126 {
127 mbedtls_x509_buf oid; /**< The object identifier. */
128 mbedtls_x509_buf val; /**< The named value. */
129 }
130 hardware_module_name;
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200131 }
132 value;
133}
134mbedtls_x509_san_other_name;
135
Janos Follath5091bec2019-05-08 15:23:08 +0100136/**
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200137 * A structure for holding the parsed Subject Alternative Name, according to type
138 */
139typedef struct mbedtls_x509_subject_alternative_name
140{
141 int type; /**< The SAN type, value of MBEDTLS_X509_SAN_XXX. */
142 union {
143 mbedtls_x509_san_other_name other_name; /**< The otherName supported type. */
144 mbedtls_x509_buf unstructured_name; /**< The buffer for the un constructed types. Only dnsName currently supported */
145 }
146 san; /**< A union of the supported SAN types */
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200147}
148mbedtls_x509_subject_alternative_name;
149
Manuel Pégourié-Gonnard88db5da2015-06-15 14:34:59 +0200150/**
Manuel Pégourié-Gonnardf8ea8562015-06-15 15:33:19 +0200151 * Build flag from an algorithm/curve identifier (pk, md, ecp)
152 * Since 0 is always XXX_NONE, ignore it.
153 */
Hanno Becker1eeca412018-10-15 12:01:35 +0100154#define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( (id) - 1 ) )
Manuel Pégourié-Gonnardf8ea8562015-06-15 15:33:19 +0200155
156/**
Manuel Pégourié-Gonnard88db5da2015-06-15 14:34:59 +0200157 * Security profile for certificate verification.
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200158 *
Manuel Pégourié-Gonnardf8ea8562015-06-15 15:33:19 +0200159 * All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG().
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200160 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200161typedef struct mbedtls_x509_crt_profile
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200162{
Manuel Pégourié-Gonnardf8ea8562015-06-15 15:33:19 +0200163 uint32_t allowed_mds; /**< MDs for signatures */
164 uint32_t allowed_pks; /**< PK algs for signatures */
165 uint32_t allowed_curves; /**< Elliptic curves for ECDSA */
166 uint32_t rsa_min_bitlen; /**< Minimum size for RSA keys */
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200167}
168mbedtls_x509_crt_profile;
169
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170#define MBEDTLS_X509_CRT_VERSION_1 0
171#define MBEDTLS_X509_CRT_VERSION_2 1
172#define MBEDTLS_X509_CRT_VERSION_3 2
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200173
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174#define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 32
175#define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200176
Andres AGf9113192016-09-02 14:06:04 +0100177#if !defined( MBEDTLS_X509_MAX_FILE_PATH_LEN )
178#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
179#endif
180
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200181/**
182 * Container for writing a certificate (CRT)
183 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184typedef struct mbedtls_x509write_cert
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200185{
186 int version;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187 mbedtls_mpi serial;
188 mbedtls_pk_context *subject_key;
189 mbedtls_pk_context *issuer_key;
190 mbedtls_asn1_named_data *subject;
191 mbedtls_asn1_named_data *issuer;
192 mbedtls_md_type_t md_alg;
193 char not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
194 char not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
195 mbedtls_asn1_named_data *extensions;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200196}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197mbedtls_x509write_cert;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200198
Manuel Pégourié-Gonnardc11e4ba2017-08-14 17:17:14 +0200199/**
200 * Item in a verification chain: cert and flags for it
201 */
202typedef struct {
203 mbedtls_x509_crt *crt;
204 uint32_t flags;
205} mbedtls_x509_crt_verify_chain_item;
206
207/**
208 * Max size of verification chain: end-entity + intermediates + trusted root
209 */
210#define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE ( MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2 )
211
212/**
213 * Verification chain as built by \c mbedtls_crt_verify_chain()
214 */
215typedef struct
216{
217 mbedtls_x509_crt_verify_chain_item items[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE];
Manuel Pégourié-Gonnardbb216bd2017-08-28 13:25:55 +0200218 unsigned len;
Hanno Beckerf53893b2019-03-28 13:45:55 +0000219
220#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
221 /* This stores the list of potential trusted signers obtained from
222 * the CA callback used for the CRT verification, if configured.
223 * We must track it somewhere because the callback passes its
224 * ownership to the caller. */
225 mbedtls_x509_crt *trust_ca_cb_result;
226#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
Manuel Pégourié-Gonnardc11e4ba2017-08-14 17:17:14 +0200227} mbedtls_x509_crt_verify_chain;
228
Manuel Pégourié-Gonnardbc3f44a2017-07-11 11:02:20 +0200229#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
230
231/**
232 * \brief Context for resuming X.509 verify operations
233 */
234typedef struct
235{
Manuel Pégourié-Gonnard8b590492017-08-14 18:04:19 +0200236 /* for check_signature() */
Manuel Pégourié-Gonnard15d7df22017-08-17 14:33:31 +0200237 mbedtls_pk_restart_ctx pk;
Manuel Pégourié-Gonnard8b590492017-08-14 18:04:19 +0200238
239 /* for find_parent_in() */
240 mbedtls_x509_crt *parent; /* non-null iff parent_in in progress */
241 mbedtls_x509_crt *fallback_parent;
Manuel Pégourié-Gonnard78d7e8c2018-07-02 12:33:14 +0200242 int fallback_signature_is_good;
Manuel Pégourié-Gonnard8b590492017-08-14 18:04:19 +0200243
244 /* for find_parent() */
245 int parent_is_trusted; /* -1 if find_parent is not in progress */
246
247 /* for verify_chain() */
Manuel Pégourié-Gonnarddaf04912017-08-23 12:32:19 +0200248 enum {
249 x509_crt_rs_none,
250 x509_crt_rs_find_parent,
251 } in_progress; /* none if no operation is in progress */
Manuel Pégourié-Gonnard8b590492017-08-14 18:04:19 +0200252 int self_cnt;
253 mbedtls_x509_crt_verify_chain ver_chain;
254
Manuel Pégourié-Gonnardbc3f44a2017-07-11 11:02:20 +0200255} mbedtls_x509_crt_restart_ctx;
256
257#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
258
259/* Now we can declare functions that take a pointer to that */
260typedef void mbedtls_x509_crt_restart_ctx;
261
262#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
263
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200264#if defined(MBEDTLS_X509_CRT_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200265/**
Manuel Pégourié-Gonnard88db5da2015-06-15 14:34:59 +0200266 * Default security profile. Should provide a good balance between security
267 * and compatibility with current deployments.
268 */
269extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
270
271/**
272 * Expected next default profile. Recommended for new deployments.
273 * Currently targets a 128-bit security level, except for RSA-2048.
274 */
275extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
276
277/**
278 * NSA Suite B profile.
279 */
280extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
281
282/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200283 * \brief Parse a single DER formatted certificate and add it
Hanno Becker1a65dcd2019-01-31 08:57:44 +0000284 * to the end of the provided chained list.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200285 *
Hanno Becker1a65dcd2019-01-31 08:57:44 +0000286 * \param chain The pointer to the start of the CRT chain to attach to.
287 * When parsing the first CRT in a chain, this should point
288 * to an instance of ::mbedtls_x509_crt initialized through
289 * mbedtls_x509_crt_init().
290 * \param buf The buffer holding the DER encoded certificate.
291 * \param buflen The size in Bytes of \p buf.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200292 *
Hanno Becker1a65dcd2019-01-31 08:57:44 +0000293 * \note This function makes an internal copy of the CRT buffer
294 * \p buf. In particular, \p buf may be destroyed or reused
295 * after this call returns. To avoid duplicating the CRT
296 * buffer (at the cost of stricter lifetime constraints),
297 * use mbedtls_x509_crt_parse_der_nocopy() instead.
298 *
299 * \return \c 0 if successful.
300 * \return A negative error code on failure.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200301 */
Hanno Becker1a65dcd2019-01-31 08:57:44 +0000302int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain,
303 const unsigned char *buf,
304 size_t buflen );
305
306/**
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200307 * \brief The type of certificate extension callbacks.
308 *
309 * Callbacks of this type are passed to and used by the
Nicola Di Lietofde98f72020-05-28 08:34:33 +0200310 * mbedtls_x509_crt_parse_der_with_ext_cb() routine when
Nicola Di Lietoc84b1e62020-06-13 11:08:16 +0200311 * it encounters either an unsupported extension or a
312 * "certificate policies" extension containing any
313 * unsupported certificate policies.
Nicola Di Lieto511bc8c2020-06-23 00:15:28 +0200314 * Future versions of the library may invoke the callback
315 * in other cases, if and when the need arises.
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200316 *
Nicola Di Lieto5659e7e2020-05-28 23:41:38 +0200317 * \param p_ctx An opaque context passed to the callback.
ndilieto6e249802020-05-28 06:17:38 +0000318 * \param crt The certificate being parsed.
319 * \param oid The OID of the extension.
320 * \param critical Whether the extension is critical.
Nicola Di Lietofae25a12020-05-28 08:55:08 +0200321 * \param p Pointer to the start of the extension value
ndilieto6e249802020-05-28 06:17:38 +0000322 * (the content of the OCTET STRING).
ndilieto6e249802020-05-28 06:17:38 +0000323 * \param end End of extension value.
Nicola Di Lieto565b52b2020-05-29 22:46:56 +0200324 *
325 * \note The callback must fail and return a negative error code
326 * if it can not parse or does not support the extension.
327 * When the callback fails to parse a critical extension
328 * mbedtls_x509_crt_parse_der_with_ext_cb() also fails.
329 * When the callback fails to parse a non critical extension
330 * mbedtls_x509_crt_parse_der_with_ext_cb() simply skips
331 * the extension and continues parsing.
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200332 *
333 * \return \c 0 on success.
334 * \return A negative error code on failure.
335 */
Nicola Di Lieto5659e7e2020-05-28 23:41:38 +0200336typedef int (*mbedtls_x509_crt_ext_cb_t)( void *p_ctx,
337 mbedtls_x509_crt const *crt,
ndilieto6e249802020-05-28 06:17:38 +0000338 mbedtls_x509_buf const *oid,
339 int critical,
Nicola Di Lietofae25a12020-05-28 08:55:08 +0200340 const unsigned char *p,
ndilieto6e249802020-05-28 06:17:38 +0000341 const unsigned char *end );
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200342
343/**
Nicola Di Lieto4dbe5672020-05-28 09:18:42 +0200344 * \brief Parse a single DER formatted certificate and add it
345 * to the end of the provided chained list.
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200346 *
Nicola Di Lieto4dbe5672020-05-28 09:18:42 +0200347 * \param chain The pointer to the start of the CRT chain to attach to.
348 * When parsing the first CRT in a chain, this should point
349 * to an instance of ::mbedtls_x509_crt initialized through
350 * mbedtls_x509_crt_init().
351 * \param buf The buffer holding the DER encoded certificate.
352 * \param buflen The size in Bytes of \p buf.
353 * \param make_copy When not zero this function makes an internal copy of the
354 * CRT buffer \p buf. In particular, \p buf may be destroyed
355 * or reused after this call returns.
356 * When zero this function avoids duplicating the CRT buffer
357 * by taking temporary ownership thereof until the CRT
358 * is destroyed (like mbedtls_x509_crt_parse_der_nocopy())
359 * \param cb A callback invoked for every unsupported certificate
360 * extension.
Nicola Di Lieto5659e7e2020-05-28 23:41:38 +0200361 * \param p_ctx An opaque context passed to the callback.
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200362 *
Nicola Di Lieto4dbe5672020-05-28 09:18:42 +0200363 * \note This call is functionally equivalent to
364 * mbedtls_x509_crt_parse_der(), and/or
365 * mbedtls_x509_crt_parse_der_nocopy()
366 * but it calls the callback with every unsupported
Nicola Di Lietoc84b1e62020-06-13 11:08:16 +0200367 * certificate extension and additionally the
368 * "certificate policies" extension if it contains any
369 * unsupported certificate policies.
Nicola Di Lieto4dbe5672020-05-28 09:18:42 +0200370 * The callback must return a negative error code if it
371 * does not know how to handle such an extension.
Nicola Di Lieto565b52b2020-05-29 22:46:56 +0200372 * When the callback fails to parse a critical extension
373 * mbedtls_x509_crt_parse_der_with_ext_cb() also fails.
374 * When the callback fails to parse a non critical extension
375 * mbedtls_x509_crt_parse_der_with_ext_cb() simply skips
376 * the extension and continues parsing.
Nicola Di Lieto511bc8c2020-06-23 00:15:28 +0200377 * Future versions of the library may invoke the callback
378 * in other cases, if and when the need arises.
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200379 *
Nicola Di Lieto4dbe5672020-05-28 09:18:42 +0200380 * \return \c 0 if successful.
381 * \return A negative error code on failure.
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200382 */
Nicola Di Lietofde98f72020-05-28 08:34:33 +0200383int mbedtls_x509_crt_parse_der_with_ext_cb( mbedtls_x509_crt *chain,
384 const unsigned char *buf,
385 size_t buflen,
Nicola Di Lieto5f6ebde2020-05-28 19:00:47 +0200386 int make_copy,
Nicola Di Lieto5659e7e2020-05-28 23:41:38 +0200387 mbedtls_x509_crt_ext_cb_t cb,
388 void *p_ctx );
Nicola Di Lieto502d4b42020-04-25 14:41:25 +0200389
390/**
Hanno Becker1a65dcd2019-01-31 08:57:44 +0000391 * \brief Parse a single DER formatted certificate and add it
392 * to the end of the provided chained list. This is a
393 * variant of mbedtls_x509_crt_parse_der() which takes
394 * temporary ownership of the CRT buffer until the CRT
395 * is destroyed.
396 *
397 * \param chain The pointer to the start of the CRT chain to attach to.
398 * When parsing the first CRT in a chain, this should point
399 * to an instance of ::mbedtls_x509_crt initialized through
400 * mbedtls_x509_crt_init().
401 * \param buf The address of the readable buffer holding the DER encoded
402 * certificate to use. On success, this buffer must be
403 * retained and not be changed for the liftetime of the
404 * CRT chain \p chain, that is, until \p chain is destroyed
405 * through a call to mbedtls_x509_crt_free().
406 * \param buflen The size in Bytes of \p buf.
407 *
408 * \note This call is functionally equivalent to
409 * mbedtls_x509_crt_parse_der(), but it avoids creating a
410 * copy of the input buffer at the cost of stronger lifetime
411 * constraints. This is useful in constrained environments
412 * where duplication of the CRT cannot be tolerated.
413 *
414 * \return \c 0 if successful.
415 * \return A negative error code on failure.
416 */
417int mbedtls_x509_crt_parse_der_nocopy( mbedtls_x509_crt *chain,
418 const unsigned char *buf,
419 size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200420
421/**
Hanno Becker89a91122018-08-23 16:14:00 +0100422 * \brief Parse one DER-encoded or one or more concatenated PEM-encoded
Hanno Becker65e619a2018-08-23 15:46:33 +0100423 * certificates and add them to the chained list.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200424 *
Hanno Beckere8658e22018-08-24 10:01:17 +0100425 * For CRTs in PEM encoding, the function parses permissively:
426 * if at least one certificate can be parsed, the function
Hanno Becker65e619a2018-08-23 15:46:33 +0100427 * returns the number of certificates for which parsing failed
428 * (hence \c 0 if all certificates were parsed successfully).
429 * If no certificate could be parsed, the function returns
430 * the first (negative) error encountered during parsing.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200431 *
Hanno Becker65e619a2018-08-23 15:46:33 +0100432 * PEM encoded certificates may be interleaved by other data
433 * such as human readable descriptions of their content, as
434 * long as the certificates are enclosed in the PEM specific
435 * '-----{BEGIN/END} CERTIFICATE-----' delimiters.
436 *
437 * \param chain The chain to which to add the parsed certificates.
438 * \param buf The buffer holding the certificate data in PEM or DER format.
439 * For certificates in PEM encoding, this may be a concatenation
440 * of multiple certificates; for DER encoding, the buffer must
441 * comprise exactly one certificate.
442 * \param buflen The size of \p buf, including the terminating \c NULL byte
443 * in case of PEM encoded data.
444 *
445 * \return \c 0 if all certificates were parsed successfully.
446 * \return The (positive) number of certificates that couldn't
447 * be parsed if parsing was partly successful (see above).
Hanno Becker89a91122018-08-23 16:14:00 +0100448 * \return A negative X509 or PEM error code otherwise.
Hanno Becker65e619a2018-08-23 15:46:33 +0100449 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200450 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200451int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200452
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200453#if defined(MBEDTLS_FS_IO)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200454/**
455 * \brief Load one or more certificates and add them
456 * to the chained list. Parses permissively. If some
457 * certificates can be parsed, the result is the number
458 * of failed certificates it encountered. If none complete
459 * correctly, the first error is returned.
460 *
461 * \param chain points to the start of the chain
462 * \param path filename to read the certificates from
463 *
464 * \return 0 if all certificates parsed successfully, a positive number
465 * if partly successful or a specific X509 or PEM error code
466 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200467int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200468
469/**
470 * \brief Load one or more certificate files from a path and add them
471 * to the chained list. Parses permissively. If some
472 * certificates can be parsed, the result is the number
473 * of failed certificates it encountered. If none complete
474 * correctly, the first error is returned.
475 *
476 * \param chain points to the start of the chain
477 * \param path directory / folder to read the certificate files from
478 *
479 * \return 0 if all certificates parsed successfully, a positive number
480 * if partly successful or a specific X509 or PEM error code
481 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200482int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
Janos Follath11b41eb2019-05-08 15:26:49 +0100483
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200484#endif /* MBEDTLS_FS_IO */
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200485/**
Ron Eldorc8b5f3f2019-05-15 15:15:55 +0300486 * \brief This function parses an item in the SubjectAlternativeNames
487 * extension.
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200488 *
Ron Eldor890819a2019-05-13 19:03:04 +0300489 * \param san_buf The buffer holding the raw data item of the subject
490 * alternative name.
491 * \param san The target structure to populate with the parsed presentation
492 * of the subject alternative name encoded in \p san_raw.
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200493 *
Ron Eldorc8b5f3f2019-05-15 15:15:55 +0300494 * \note Only "dnsName" and "otherName" of type hardware_module_name
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200495 * as defined in RFC 4180 is supported.
496 *
Ron Eldor890819a2019-05-13 19:03:04 +0300497 * \note This function should be called on a single raw data of
Ron Eldorcc45cd12019-05-15 10:20:09 +0300498 * subject alternative name. For example, after successful
Ron Eldor890819a2019-05-13 19:03:04 +0300499 * certificate parsing, one must iterate on every item in the
Ron Eldorc8b5f3f2019-05-15 15:15:55 +0300500 * \p crt->subject_alt_names sequence, and pass it to
501 * this function.
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200502 *
Ron Eldorc8b5f3f2019-05-15 15:15:55 +0300503 * \warning The target structure contains pointers to the raw data of the
Ron Eldorcc45cd12019-05-15 10:20:09 +0300504 * parsed certificate, and its lifetime is restricted by the
505 * lifetime of the certificate.
506 *
Ron Eldor890819a2019-05-13 19:03:04 +0300507 * \return \c 0 on success
508 * \return #MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE for an unsupported
Ron Eldorc8b5f3f2019-05-15 15:15:55 +0300509 * SAN type.
510 * \return Another negative value for any other failure.
Ron Eldorb2dc3fa2019-03-21 13:40:13 +0200511 */
Ron Eldor890819a2019-05-13 19:03:04 +0300512int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf,
513 mbedtls_x509_subject_alternative_name *san );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200514/**
515 * \brief Returns an informational string about the
516 * certificate.
517 *
518 * \param buf Buffer to write to
519 * \param size Maximum size of buffer
520 * \param prefix A line prefix
521 * \param crt The X509 certificate to represent
522 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200523 * \return The length of the string written (not including the
524 * terminated nul byte), or a negative error code.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200525 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
527 const mbedtls_x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200528
529/**
Manuel Pégourié-Gonnardb5f48ad2015-04-20 10:38:13 +0100530 * \brief Returns an informational string about the
531 * verification status of a certificate.
532 *
533 * \param buf Buffer to write to
534 * \param size Maximum size of buffer
535 * \param prefix A line prefix
536 * \param flags Verification flags created by mbedtls_x509_crt_verify()
537 *
Manuel Pégourié-Gonnarde244f9f2015-06-23 12:10:45 +0200538 * \return The length of the string written (not including the
539 * terminated nul byte), or a negative error code.
Manuel Pégourié-Gonnardb5f48ad2015-04-20 10:38:13 +0100540 */
541int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200542 uint32_t flags );
Manuel Pégourié-Gonnard39a183a2015-04-17 16:14:32 +0200543
544/**
Hanno Becker902451d2019-03-27 11:48:40 +0000545 * \brief Verify a chain of certificates.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200546 *
547 * The verify callback is a user-supplied callback that
548 * can clear / modify / add flags for a certificate. If set,
549 * the verification callback is called for each
550 * certificate in the chain (from the trust-ca down to the
551 * presented crt). The parameters for the callback are:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552 * (void *parameter, mbedtls_x509_crt *crt, int certificate_depth,
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200553 * int *flags). With the flags representing current flags for
554 * that specific certificate and the certificate depth from
555 * the bottom (Peer cert depth = 0).
556 *
557 * All flags left after returning from the callback
558 * are also returned to the application. The function should
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200559 * return 0 for anything (including invalid certificates)
560 * other than fatal error, as a non-zero return code
561 * immediately aborts the verification process. For fatal
562 * errors, a specific error code should be used (different
563 * from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not
564 * be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR
565 * can be used if no better code is available.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200566 *
Manuel Pégourié-Gonnardb5f48ad2015-04-20 10:38:13 +0100567 * \note In case verification failed, the results can be displayed
568 * using \c mbedtls_x509_crt_verify_info()
569 *
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200570 * \note Same as \c mbedtls_x509_crt_verify_with_profile() with the
571 * default security profile.
572 *
Manuel Pégourié-Gonnardeeef9472016-02-22 11:36:55 +0100573 * \note It is your responsibility to provide up-to-date CRLs for
574 * all trusted CAs. If no CRL is provided for the CA that was
575 * used to sign the certificate, CRL verification is skipped
576 * silently, that is *without* setting any flag.
577 *
Manuel Pégourié-Gonnard08eacec2017-10-18 14:20:24 +0200578 * \note The \c trust_ca list can contain two types of certificates:
Manuel Pégourié-Gonnarda4a206e2017-06-21 09:35:44 +0200579 * (1) those of trusted root CAs, so that certificates
580 * chaining up to those CAs will be trusted, and (2)
581 * self-signed end-entity certificates to be trusted (for
582 * specific peers you know) - in that case, the self-signed
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +0200583 * certificate doesn't need to have the CA bit set.
Manuel Pégourié-Gonnarda4a206e2017-06-21 09:35:44 +0200584 *
Hanno Becker902451d2019-03-27 11:48:40 +0000585 * \param crt The certificate chain to be verified.
586 * \param trust_ca The list of trusted CAs.
587 * \param ca_crl The list of CRLs for trusted CAs.
Manuel Pégourié-Gonnardf58e5cc2020-07-24 10:31:37 +0200588 * \param cn The expected Common Name. This will be checked to be
589 * present in the certificate's subjectAltNames extension or,
590 * if this extension is absent, as a CN component in its
591 * Subject name. Currently only DNS names are supported. This
592 * may be \c NULL if the CN need not be verified.
Hanno Becker902451d2019-03-27 11:48:40 +0000593 * \param flags The address at which to store the result of the verification.
Janos Follath846ae7a2019-04-05 16:45:01 +0100594 * If the verification couldn't be completed, the flag value is
595 * set to (uint32_t) -1.
Hanno Becker902451d2019-03-27 11:48:40 +0000596 * \param f_vrfy The verification callback to use. See the documentation
597 * of mbedtls_x509_crt_verify() for more information.
598 * \param p_vrfy The context to be passed to \p f_vrfy.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200599 *
Hanno Becker902451d2019-03-27 11:48:40 +0000600 * \return \c 0 if the chain is valid with respect to the
601 * passed CN, CAs, CRLs and security profile.
602 * \return #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the
603 * certificate chain verification failed. In this case,
604 * \c *flags will have one or more
605 * \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX
606 * flags set.
607 * \return Another negative error code in case of a fatal error
608 * encountered during the verification process.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200609 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt,
611 mbedtls_x509_crt *trust_ca,
612 mbedtls_x509_crl *ca_crl,
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200613 const char *cn, uint32_t *flags,
614 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
Paul Bakkerddf26b42013-09-18 13:46:23 +0200615 void *p_vrfy );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200616
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200617/**
Hanno Becker902451d2019-03-27 11:48:40 +0000618 * \brief Verify a chain of certificates with respect to
619 * a configurable security profile.
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200620 *
621 * \note Same as \c mbedtls_x509_crt_verify(), but with explicit
622 * security profile.
623 *
Manuel Pégourié-Gonnard27716cc2015-06-17 11:49:39 +0200624 * \note The restrictions on keys (RSA minimum size, allowed curves
Manuel Pégourié-Gonnard65eefc82015-10-23 14:08:48 +0200625 * for ECDSA) apply to all certificates: trusted root,
626 * intermediate CAs if any, and end entity certificate.
Manuel Pégourié-Gonnard27716cc2015-06-17 11:49:39 +0200627 *
Hanno Becker902451d2019-03-27 11:48:40 +0000628 * \param crt The certificate chain to be verified.
629 * \param trust_ca The list of trusted CAs.
630 * \param ca_crl The list of CRLs for trusted CAs.
631 * \param profile The security profile to use for the verification.
632 * \param cn The expected Common Name. This may be \c NULL if the
633 * CN need not be verified.
634 * \param flags The address at which to store the result of the verification.
Janos Follath846ae7a2019-04-05 16:45:01 +0100635 * If the verification couldn't be completed, the flag value is
636 * set to (uint32_t) -1.
Hanno Becker902451d2019-03-27 11:48:40 +0000637 * \param f_vrfy The verification callback to use. See the documentation
638 * of mbedtls_x509_crt_verify() for more information.
639 * \param p_vrfy The context to be passed to \p f_vrfy.
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200640 *
Hanno Becker902451d2019-03-27 11:48:40 +0000641 * \return \c 0 if the chain is valid with respect to the
642 * passed CN, CAs, CRLs and security profile.
643 * \return #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the
644 * certificate chain verification failed. In this case,
645 * \c *flags will have one or more
646 * \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX
647 * flags set.
648 * \return Another negative error code in case of a fatal error
649 * encountered during the verification process.
Manuel Pégourié-Gonnard95051642015-06-15 10:39:46 +0200650 */
651int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt,
652 mbedtls_x509_crt *trust_ca,
653 mbedtls_x509_crl *ca_crl,
654 const mbedtls_x509_crt_profile *profile,
655 const char *cn, uint32_t *flags,
656 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
657 void *p_vrfy );
658
Manuel Pégourié-Gonnardbc3f44a2017-07-11 11:02:20 +0200659/**
660 * \brief Restartable version of \c mbedtls_crt_verify_with_profile()
661 *
662 * \note Performs the same job as \c mbedtls_crt_verify_with_profile()
663 * but can return early and restart according to the limit
664 * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
665 *
Hanno Becker902451d2019-03-27 11:48:40 +0000666 * \param crt The certificate chain to be verified.
667 * \param trust_ca The list of trusted CAs.
668 * \param ca_crl The list of CRLs for trusted CAs.
669 * \param profile The security profile to use for the verification.
670 * \param cn The expected Common Name. This may be \c NULL if the
671 * CN need not be verified.
672 * \param flags The address at which to store the result of the verification.
Janos Follath846ae7a2019-04-05 16:45:01 +0100673 * If the verification couldn't be completed, the flag value is
674 * set to (uint32_t) -1.
Hanno Becker902451d2019-03-27 11:48:40 +0000675 * \param f_vrfy The verification callback to use. See the documentation
676 * of mbedtls_x509_crt_verify() for more information.
677 * \param p_vrfy The context to be passed to \p f_vrfy.
678 * \param rs_ctx The restart context to use. This may be set to \c NULL
679 * to disable restartable ECC.
Manuel Pégourié-Gonnardbc3f44a2017-07-11 11:02:20 +0200680 *
681 * \return See \c mbedtls_crt_verify_with_profile(), or
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200682 * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
Manuel Pégourié-Gonnardbc3f44a2017-07-11 11:02:20 +0200683 * operations was reached: see \c mbedtls_ecp_set_max_ops().
684 */
685int mbedtls_x509_crt_verify_restartable( mbedtls_x509_crt *crt,
686 mbedtls_x509_crt *trust_ca,
687 mbedtls_x509_crl *ca_crl,
688 const mbedtls_x509_crt_profile *profile,
689 const char *cn, uint32_t *flags,
690 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
691 void *p_vrfy,
692 mbedtls_x509_crt_restart_ctx *rs_ctx );
693
Hanno Becker5c8df782019-03-27 11:01:17 +0000694/**
695 * \brief The type of trusted certificate callbacks.
696 *
697 * Callbacks of this type are passed to and used by the CRT
Jarno Lamsa31d9db62019-04-01 14:33:49 +0300698 * verification routine mbedtls_x509_crt_verify_with_ca_cb()
Hanno Becker5c8df782019-03-27 11:01:17 +0000699 * when looking for trusted signers of a given certificate.
700 *
701 * On success, the callback returns a list of trusted
702 * certificates to be considered as potential signers
703 * for the input certificate.
704 *
705 * \param p_ctx An opaque context passed to the callback.
706 * \param child The certificate for which to search a potential signer.
Jarno Lamsaf49fedc2019-04-01 14:58:30 +0300707 * This will point to a readable certificate.
Hanno Becker5c8df782019-03-27 11:01:17 +0000708 * \param candidate_cas The address at which to store the address of the first
709 * entry in the generated linked list of candidate signers.
Jarno Lamsaf49fedc2019-04-01 14:58:30 +0300710 * This will not be \c NULL.
Hanno Becker5c8df782019-03-27 11:01:17 +0000711 *
712 * \note The callback must only return a non-zero value on a
713 * fatal error. If, in contrast, the search for a potential
714 * signer completes without a single candidate, the
Jarno Lamsaf49fedc2019-04-01 14:58:30 +0300715 * callback must return \c 0 and set \c *candidate_cas
Hanno Becker5c8df782019-03-27 11:01:17 +0000716 * to \c NULL.
717 *
718 * \return \c 0 on success. In this case, \c *candidate_cas points
719 * to a heap-allocated linked list of instances of
720 * ::mbedtls_x509_crt, and ownership of this list is passed
721 * to the caller.
722 * \return A negative error code on failure.
723 */
724typedef int (*mbedtls_x509_crt_ca_cb_t)( void *p_ctx,
725 mbedtls_x509_crt const *child,
726 mbedtls_x509_crt **candidate_cas );
Hanno Beckere15dae72019-03-28 13:55:38 +0000727
728#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
Hanno Becker5c8df782019-03-27 11:01:17 +0000729/**
730 * \brief Version of \c mbedtls_x509_crt_verify_with_profile() which
731 * uses a callback to acquire the list of trusted CA
732 * certificates.
733 *
734 * \param crt The certificate chain to be verified.
735 * \param f_ca_cb The callback to be used to query for potential signers
736 * of a given child certificate. See the documentation of
737 * ::mbedtls_x509_crt_ca_cb_t for more information.
738 * \param p_ca_cb The opaque context to be passed to \p f_ca_cb.
739 * \param profile The security profile for the verification.
740 * \param cn The expected Common Name. This may be \c NULL if the
741 * CN need not be verified.
742 * \param flags The address at which to store the result of the verification.
Janos Follath846ae7a2019-04-05 16:45:01 +0100743 * If the verification couldn't be completed, the flag value is
744 * set to (uint32_t) -1.
Hanno Becker5c8df782019-03-27 11:01:17 +0000745 * \param f_vrfy The verification callback to use. See the documentation
746 * of mbedtls_x509_crt_verify() for more information.
747 * \param p_vrfy The context to be passed to \p f_vrfy.
748 *
749 * \return See \c mbedtls_crt_verify_with_profile().
750 */
Jarno Lamsa31d9db62019-04-01 14:33:49 +0300751int mbedtls_x509_crt_verify_with_ca_cb( mbedtls_x509_crt *crt,
Hanno Becker5c8df782019-03-27 11:01:17 +0000752 mbedtls_x509_crt_ca_cb_t f_ca_cb,
753 void *p_ca_cb,
754 const mbedtls_x509_crt_profile *profile,
755 const char *cn, uint32_t *flags,
756 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
757 void *p_vrfy );
758
759#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
760
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200761#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200762/**
763 * \brief Check usage of certificate against keyUsage extension.
764 *
765 * \param crt Leaf certificate used.
Manuel Pégourié-Gonnard655a9642015-06-23 10:48:44 +0200766 * \param usage Intended usage(s) (eg MBEDTLS_X509_KU_KEY_ENCIPHERMENT
767 * before using the certificate to perform an RSA key
768 * exchange).
769 *
770 * \note Except for decipherOnly and encipherOnly, a bit set in the
771 * usage argument means this bit MUST be set in the
772 * certificate. For decipherOnly and encipherOnly, it means
773 * that bit MAY be set.
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200774 *
775 * \return 0 is these uses of the certificate are allowed,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200776 * MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
Manuel Pégourié-Gonnard655a9642015-06-23 10:48:44 +0200777 * is present but does not match the usage argument.
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200778 *
779 * \note You should only call this function on leaf certificates, on
780 * (intermediate) CAs the keyUsage extension is automatically
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200781 * checked by \c mbedtls_x509_crt_verify().
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200782 */
Manuel Pégourié-Gonnard655a9642015-06-23 10:48:44 +0200783int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
784 unsigned int usage );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200785#endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200786
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200787#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200788/**
Andres Amaya Garcia5a6da632017-11-14 21:40:51 +0000789 * \brief Check usage of certificate against extendedKeyUsage.
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200790 *
Andres Amaya Garcia5a6da632017-11-14 21:40:51 +0000791 * \param crt Leaf certificate used.
792 * \param usage_oid Intended usage (eg MBEDTLS_OID_SERVER_AUTH or
793 * MBEDTLS_OID_CLIENT_AUTH).
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200794 * \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()).
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200795 *
Andres Amaya Garcia5a6da632017-11-14 21:40:51 +0000796 * \return 0 if this use of the certificate is allowed,
797 * MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200798 *
Andres Amaya Garcia5a6da632017-11-14 21:40:51 +0000799 * \note Usually only makes sense on leaf certificates.
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200800 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200801int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
Andres Amaya Garcia5a6da632017-11-14 21:40:51 +0000802 const char *usage_oid,
803 size_t usage_len );
Andres Amaya Garciac81fcb92017-11-14 21:40:02 +0000804#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200805
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200806#if defined(MBEDTLS_X509_CRL_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200807/**
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200808 * \brief Verify the certificate revocation status
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200809 *
810 * \param crt a certificate to be verified
811 * \param crl the CRL to verify against
812 *
813 * \return 1 if the certificate is revoked, 0 otherwise
814 *
815 */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100816int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200817#endif /* MBEDTLS_X509_CRL_PARSE_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200818
819/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200820 * \brief Initialize a certificate (chain)
821 *
822 * \param crt Certificate chain to initialize
823 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200824void mbedtls_x509_crt_init( mbedtls_x509_crt *crt );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200825
826/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200827 * \brief Unallocate all certificate data
828 *
829 * \param crt Certificate chain to free
830 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200831void mbedtls_x509_crt_free( mbedtls_x509_crt *crt );
Manuel Pégourié-Gonnardbc3f44a2017-07-11 11:02:20 +0200832
833#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
834/**
835 * \brief Initialize a restart context
836 */
837void mbedtls_x509_crt_restart_init( mbedtls_x509_crt_restart_ctx *ctx );
838
839/**
840 * \brief Free the components of a restart context
841 */
842void mbedtls_x509_crt_restart_free( mbedtls_x509_crt_restart_ctx *ctx );
843#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200844#endif /* MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200845
846/* \} name */
847/* \} addtogroup x509_module */
848
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200849#if defined(MBEDTLS_X509_CRT_WRITE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200850/**
851 * \brief Initialize a CRT writing context
852 *
853 * \param ctx CRT context to initialize
854 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855void mbedtls_x509write_crt_init( mbedtls_x509write_cert *ctx );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200856
857/**
858 * \brief Set the verion for a Certificate
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200859 * Default: MBEDTLS_X509_CRT_VERSION_3
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200860 *
861 * \param ctx CRT context to use
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200862 * \param version version to set (MBEDTLS_X509_CRT_VERSION_1, MBEDTLS_X509_CRT_VERSION_2 or
863 * MBEDTLS_X509_CRT_VERSION_3)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200864 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200865void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200866
867/**
868 * \brief Set the serial number for a Certificate.
869 *
870 * \param ctx CRT context to use
871 * \param serial serial number to set
872 *
873 * \return 0 if successful
874 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200875int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200876
877/**
878 * \brief Set the validity period for a Certificate
879 * Timestamps should be in string format for UTC timezone
880 * i.e. "YYYYMMDDhhmmss"
881 * e.g. "20131231235959" for December 31st 2013
882 * at 23:59:59
883 *
884 * \param ctx CRT context to use
885 * \param not_before not_before timestamp
886 * \param not_after not_after timestamp
887 *
888 * \return 0 if timestamp was parsed successfully, or
889 * a specific error code
890 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200891int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
Paul Bakker50dc8502013-10-28 21:19:10 +0100892 const char *not_after );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200893
894/**
895 * \brief Set the issuer name for a Certificate
896 * Issuer names should contain a comma-separated list
897 * of OID types and values:
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +0000898 * e.g. "C=UK,O=ARM,CN=mbed TLS CA"
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200899 *
900 * \param ctx CRT context to use
901 * \param issuer_name issuer name to set
902 *
903 * \return 0 if issuer name was parsed successfully, or
904 * a specific error code
905 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200906int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
Paul Bakker50dc8502013-10-28 21:19:10 +0100907 const char *issuer_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200908
909/**
910 * \brief Set the subject name for a Certificate
911 * Subject names should contain a comma-separated list
912 * of OID types and values:
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +0000913 * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200914 *
915 * \param ctx CRT context to use
916 * \param subject_name subject name to set
917 *
918 * \return 0 if subject name was parsed successfully, or
919 * a specific error code
920 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200921int mbedtls_x509write_crt_set_subject_name( mbedtls_x509write_cert *ctx,
Paul Bakker50dc8502013-10-28 21:19:10 +0100922 const char *subject_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200923
924/**
925 * \brief Set the subject public key for the certificate
926 *
927 * \param ctx CRT context to use
928 * \param key public key to include
929 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200930void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200931
932/**
933 * \brief Set the issuer key used for signing the certificate
934 *
935 * \param ctx CRT context to use
936 * \param key private key to sign with
937 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200938void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200939
940/**
941 * \brief Set the MD algorithm to use for the signature
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200942 * (e.g. MBEDTLS_MD_SHA1)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200943 *
944 * \param ctx CRT context to use
Paul Bakkera36d23e2013-12-30 17:57:27 +0100945 * \param md_alg MD algorithm to use
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200946 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200948
949/**
950 * \brief Generic function to add to or replace an extension in the
951 * CRT
952 *
953 * \param ctx CRT context to use
954 * \param oid OID of the extension
955 * \param oid_len length of the OID
956 * \param critical if the extension is critical (per the RFC's definition)
957 * \param val value of the extension OCTET STRING
958 * \param val_len length of the value data
959 *
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200960 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200961 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200962int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200963 const char *oid, size_t oid_len,
964 int critical,
965 const unsigned char *val, size_t val_len );
966
967/**
968 * \brief Set the basicConstraints extension for a CRT
969 *
970 * \param ctx CRT context to use
971 * \param is_ca is this a CA certificate
972 * \param max_pathlen maximum length of certificate chains below this
973 * certificate (only for CA certificates, -1 is
974 * inlimited)
975 *
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200976 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200977 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200978int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200979 int is_ca, int max_pathlen );
980
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200981#if defined(MBEDTLS_SHA1_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200982/**
983 * \brief Set the subjectKeyIdentifier extension for a CRT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200984 * Requires that mbedtls_x509write_crt_set_subject_key() has been
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200985 * called before
986 *
987 * \param ctx CRT context to use
988 *
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200989 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200990 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200991int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200992
993/**
994 * \brief Set the authorityKeyIdentifier extension for a CRT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200995 * Requires that mbedtls_x509write_crt_set_issuer_key() has been
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200996 * called before
997 *
998 * \param ctx CRT context to use
999 *
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +02001000 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001001 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001002int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *ctx );
1003#endif /* MBEDTLS_SHA1_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001004
1005/**
1006 * \brief Set the Key Usage Extension flags
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001007 * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001008 *
1009 * \param ctx CRT context to use
1010 * \param key_usage key usage flags to set
1011 *
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +02001012 * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001013 */
Manuel Pégourié-Gonnard1cd10ad2015-06-23 11:07:37 +02001014int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
1015 unsigned int key_usage );
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001016
1017/**
1018 * \brief Set the Netscape Cert Type flags
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001019 * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001020 *
1021 * \param ctx CRT context to use
1022 * \param ns_cert_type Netscape Cert Type flags to set
1023 *
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +02001024 * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001025 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001026int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001027 unsigned char ns_cert_type );
1028
1029/**
1030 * \brief Free the contents of a CRT write context
1031 *
1032 * \param ctx CRT context to free
1033 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001034void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx );
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001035
1036/**
1037 * \brief Write a built up certificate to a X509 DER structure
1038 * Note: data is written at the end of the buffer! Use the
1039 * return value to determine where you should start
1040 * using the buffer
1041 *
Paul Bakkera36d23e2013-12-30 17:57:27 +01001042 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001043 * \param buf buffer to write to
1044 * \param size size of the buffer
1045 * \param f_rng RNG function (for signature, see note)
1046 * \param p_rng RNG parameter
1047 *
1048 * \return length of data written if successful, or a specific
1049 * error code
1050 *
1051 * \note f_rng may be NULL if RSA is used for signature and the
1052 * signature is made offline (otherwise f_rng is desirable
1053 * for countermeasures against timing attacks).
1054 * ECDSA signatures always require a non-NULL f_rng.
1055 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001056int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001057 int (*f_rng)(void *, unsigned char *, size_t),
1058 void *p_rng );
1059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001060#if defined(MBEDTLS_PEM_WRITE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001061/**
1062 * \brief Write a built up certificate to a X509 PEM string
1063 *
Paul Bakkera36d23e2013-12-30 17:57:27 +01001064 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001065 * \param buf buffer to write to
1066 * \param size size of the buffer
1067 * \param f_rng RNG function (for signature, see note)
1068 * \param p_rng RNG parameter
1069 *
Manuel Pégourié-Gonnard81abefd2015-05-29 12:53:47 +02001070 * \return 0 if successful, or a specific error code
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001071 *
1072 * \note f_rng may be NULL if RSA is used for signature and the
1073 * signature is made offline (otherwise f_rng is desirable
1074 * for countermeasures against timing attacks).
1075 * ECDSA signatures always require a non-NULL f_rng.
1076 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001077int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001078 int (*f_rng)(void *, unsigned char *, size_t),
1079 void *p_rng );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001080#endif /* MBEDTLS_PEM_WRITE_C */
1081#endif /* MBEDTLS_X509_CRT_WRITE_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001082
1083#ifdef __cplusplus
1084}
1085#endif
1086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001087#endif /* mbedtls_x509_crt.h */