blob: 09cc9829b27ec2fa451ef13bd7b21c15ac0fcba4 [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/**
2 * \file x509_crt.h
3 *
4 * \brief X.509 certificate parsing and writing
5 *
6 * Copyright (C) 2006-2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_X509_CRT_H
28#define POLARSSL_X509_CRT_H
29
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020031#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020035
36#include "x509.h"
37
Paul Bakker7c6b2c32013-09-16 13:49:26 +020038#include "x509_crl.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020039
40/**
41 * \addtogroup x509_module
42 * \{
43 */
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \name Structures and functions for parsing and writing X.509 certificates
51 * \{
52 */
53
54/**
55 * Container for an X.509 certificate. The certificate may be chained.
56 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +020057typedef struct _x509_crt
Paul Bakker7c6b2c32013-09-16 13:49:26 +020058{
59 x509_buf raw; /**< The raw certificate data (DER). */
60 x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
61
62 int version; /**< The X.509 version. (0=v1, 1=v2, 2=v3) */
63 x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
64 x509_buf sig_oid1; /**< Signature algorithm, e.g. sha1RSA */
65
66 x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
67 x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
68
69 x509_name issuer; /**< The parsed issuer data (named information object). */
70 x509_name subject; /**< The parsed subject data (named information object). */
71
72 x509_time valid_from; /**< Start time of certificate validity. */
73 x509_time valid_to; /**< End time of certificate validity. */
74
75 pk_context pk; /**< Container for the public key context. */
76
77 x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
78 x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
Manuel Pégourié-Gonnardb28487d2014-04-01 12:19:09 +020079 x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020080 x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
81
82 int ext_types; /**< Bit string containing detected and parsed extensions */
83 int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
84 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+ */
85
Manuel Pégourié-Gonnardb28487d2014-04-01 12:19:09 +020086 unsigned char key_usage; /**< Optional key usage extension value: See the values in x509.h */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020087
88 x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
89
Manuel Pégourié-Gonnardb28487d2014-04-01 12:19:09 +020090 unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020091
92 x509_buf sig_oid2; /**< Signature algorithm. Must match sig_oid1. */
93 x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
94 md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. POLARSSL_MD_SHA256 */
95 pk_type_t sig_pk /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. POLARSSL_PK_RSA */;
Manuel Pégourié-Gonnard59a75d52014-01-22 10:12:57 +010096#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
97 x509_buf sig_params; /**< Parameters for the signature algorithm */
98#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +020099
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200100 struct _x509_crt *next; /**< Next certificate in the CA-chain. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200101}
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200102x509_crt;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200103
104#define X509_CRT_VERSION_1 0
105#define X509_CRT_VERSION_2 1
106#define X509_CRT_VERSION_3 2
107
108#define X509_RFC5280_MAX_SERIAL_LEN 32
109#define X509_RFC5280_UTC_TIME_LEN 15
110
111/**
112 * Container for writing a certificate (CRT)
113 */
114typedef struct _x509write_cert
115{
116 int version;
117 mpi serial;
118 pk_context *subject_key;
119 pk_context *issuer_key;
120 asn1_named_data *subject;
121 asn1_named_data *issuer;
122 md_type_t md_alg;
123 char not_before[X509_RFC5280_UTC_TIME_LEN + 1];
124 char not_after[X509_RFC5280_UTC_TIME_LEN + 1];
125 asn1_named_data *extensions;
126}
127x509write_cert;
128
129#if defined(POLARSSL_X509_CRT_PARSE_C)
130/**
131 * \brief Parse a single DER formatted certificate and add it
132 * to the chained list.
133 *
134 * \param chain points to the start of the chain
135 * \param buf buffer holding the certificate DER data
136 * \param buflen size of the buffer
137 *
138 * \return 0 if successful, or a specific X509 or PEM error code
139 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200140int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200141 size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200142
143/**
144 * \brief Parse one or more certificates and add them
145 * to the chained list. Parses permissively. If some
146 * certificates can be parsed, the result is the number
147 * of failed certificates it encountered. If none complete
148 * correctly, the first error is returned.
149 *
150 * \param chain points to the start of the chain
151 * \param buf buffer holding the certificate data
152 * \param buflen size of the buffer
153 *
154 * \return 0 if all certificates parsed successfully, a positive number
155 * if partly successful or a specific X509 or PEM error code
156 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200157int x509_crt_parse( x509_crt *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200158
159#if defined(POLARSSL_FS_IO)
160/**
161 * \brief Load one or more certificates and add them
162 * to the chained list. Parses permissively. If some
163 * certificates can be parsed, the result is the number
164 * of failed certificates it encountered. If none complete
165 * correctly, the first error is returned.
166 *
167 * \param chain points to the start of the chain
168 * \param path filename to read the certificates from
169 *
170 * \return 0 if all certificates parsed successfully, a positive number
171 * if partly successful or a specific X509 or PEM error code
172 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200173int x509_crt_parse_file( x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200174
175/**
176 * \brief Load one or more certificate files from a path and add them
177 * to the chained list. Parses permissively. If some
178 * certificates can be parsed, the result is the number
179 * of failed certificates it encountered. If none complete
180 * correctly, the first error is returned.
181 *
Manuel Pégourié-Gonnarde3339ce2013-11-28 17:16:41 +0100182 * \warning This function is NOT thread-safe unless
183 * POLARSSL_THREADING_PTHREADS is defined. If you're using an
184 * alternative threading implementation, you should either use
185 * this function only in the main thread, or mutex it.
186 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200187 * \param chain points to the start of the chain
188 * \param path directory / folder to read the certificate files from
189 *
190 * \return 0 if all certificates parsed successfully, a positive number
191 * if partly successful or a specific X509 or PEM error code
192 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200193int x509_crt_parse_path( x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200194#endif /* POLARSSL_FS_IO */
195
196/**
197 * \brief Returns an informational string about the
198 * certificate.
199 *
200 * \param buf Buffer to write to
201 * \param size Maximum size of buffer
202 * \param prefix A line prefix
203 * \param crt The X509 certificate to represent
204 *
205 * \return The amount of data written to the buffer, or -1 in
206 * case of an error.
207 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200208int x509_crt_info( char *buf, size_t size, const char *prefix,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200209 const x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200210
211/**
212 * \brief Verify the certificate signature
213 *
214 * The verify callback is a user-supplied callback that
215 * can clear / modify / add flags for a certificate. If set,
216 * the verification callback is called for each
217 * certificate in the chain (from the trust-ca down to the
218 * presented crt). The parameters for the callback are:
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200219 * (void *parameter, x509_crt *crt, int certificate_depth,
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200220 * int *flags). With the flags representing current flags for
221 * that specific certificate and the certificate depth from
222 * the bottom (Peer cert depth = 0).
223 *
224 * All flags left after returning from the callback
225 * are also returned to the application. The function should
226 * return 0 for anything but a fatal error.
227 *
228 * \param crt a certificate to be verified
229 * \param trust_ca the trusted CA chain
230 * \param ca_crl the CRL chain for trusted CA's
231 * \param cn expected Common Name (can be set to
232 * NULL if the CN must not be verified)
233 * \param flags result of the verification
234 * \param f_vrfy verification function
235 * \param p_vrfy verification parameter
236 *
237 * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
238 * in which case *flags will have one or more of
239 * the following values set:
240 * BADCERT_EXPIRED --
241 * BADCERT_REVOKED --
242 * BADCERT_CN_MISMATCH --
243 * BADCERT_NOT_TRUSTED
244 * or another error in case of a fatal error encountered
245 * during the verification process.
246 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200247int x509_crt_verify( x509_crt *crt,
248 x509_crt *trust_ca,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200249 x509_crl *ca_crl,
250 const char *cn, int *flags,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200251 int (*f_vrfy)(void *, x509_crt *, int, int *),
Paul Bakkerddf26b42013-09-18 13:46:23 +0200252 void *p_vrfy );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200253
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200254#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
255/**
256 * \brief Check usage of certificate against keyUsage extension.
257 *
258 * \param crt Leaf certificate used.
259 * \param usage Intended usage(s) (eg KU_KEY_ENCIPHERMENT before using the
260 * certificate to perform an RSA key exchange).
261 *
262 * \return 0 is these uses of the certificate are allowed,
Paul Bakker02ff5ce2014-04-09 15:53:09 +0200263 * POLARSSL_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200264 * is present but does not contain all the bits set in the
265 * usage argument.
266 *
267 * \note You should only call this function on leaf certificates, on
268 * (intermediate) CAs the keyUsage extension is automatically
269 * checked by \c x509_crt_verify().
270 */
271int x509_crt_check_key_usage( const x509_crt *crt, int usage );
272#endif /* POLARSSL_X509_CHECK_KEY_USAGE) */
273
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200274#if defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
275/**
276 * \brief Check usage of certificate against extentedJeyUsage.
277 *
278 * \param crt Leaf certificate used.
279 * \param usage_oid Intended usage (eg OID_SERVER_AUTH or OID_CLIENT_AUTH).
280 * \param usage_len Length of usage_oid (eg given by OID_SIZE()).
281 *
282 * \return 0 is this use of the certificate is allowed,
283 * POLARSSL_ERR_X509_BAD_INPUT_DATA if not.
284 *
285 * \note Usually only makes sense on leaf certificates.
286 */
287int x509_crt_check_extended_key_usage( const x509_crt *crt,
288 const char *usage_oid,
289 size_t usage_len );
290#endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE) */
291
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200292#if defined(POLARSSL_X509_CRL_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200293/**
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200294 * \brief Verify the certificate revocation status
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200295 *
296 * \param crt a certificate to be verified
297 * \param crl the CRL to verify against
298 *
299 * \return 1 if the certificate is revoked, 0 otherwise
300 *
301 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200302int x509_crt_revoked( const x509_crt *crt, const x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200303#endif /* POLARSSL_X509_CRL_PARSE_C */
304
305/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200306 * \brief Initialize a certificate (chain)
307 *
308 * \param crt Certificate chain to initialize
309 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200310void x509_crt_init( x509_crt *crt );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200311
312/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200313 * \brief Unallocate all certificate data
314 *
315 * \param crt Certificate chain to free
316 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200317void x509_crt_free( x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200318#endif /* POLARSSL_X509_CRT_PARSE_C */
319
320/* \} name */
321/* \} addtogroup x509_module */
322
323#if defined(POLARSSL_X509_CRT_WRITE_C)
324/**
325 * \brief Initialize a CRT writing context
326 *
327 * \param ctx CRT context to initialize
328 */
329void x509write_crt_init( x509write_cert *ctx );
330
331/**
332 * \brief Set the verion for a Certificate
333 * Default: X509_CRT_VERSION_3
334 *
335 * \param ctx CRT context to use
336 * \param version version to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or
337 * X509_CRT_VERSION_3)
338 */
339void x509write_crt_set_version( x509write_cert *ctx, int version );
340
341/**
342 * \brief Set the serial number for a Certificate.
343 *
344 * \param ctx CRT context to use
345 * \param serial serial number to set
346 *
347 * \return 0 if successful
348 */
349int x509write_crt_set_serial( x509write_cert *ctx, const mpi *serial );
350
351/**
352 * \brief Set the validity period for a Certificate
353 * Timestamps should be in string format for UTC timezone
354 * i.e. "YYYYMMDDhhmmss"
355 * e.g. "20131231235959" for December 31st 2013
356 * at 23:59:59
357 *
358 * \param ctx CRT context to use
359 * \param not_before not_before timestamp
360 * \param not_after not_after timestamp
361 *
362 * \return 0 if timestamp was parsed successfully, or
363 * a specific error code
364 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100365int x509write_crt_set_validity( x509write_cert *ctx, const char *not_before,
366 const char *not_after );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200367
368/**
369 * \brief Set the issuer name for a Certificate
370 * Issuer names should contain a comma-separated list
371 * of OID types and values:
372 * e.g. "C=NL,O=Offspark,CN=PolarSSL CA"
373 *
374 * \param ctx CRT context to use
375 * \param issuer_name issuer name to set
376 *
377 * \return 0 if issuer name was parsed successfully, or
378 * a specific error code
379 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100380int x509write_crt_set_issuer_name( x509write_cert *ctx,
381 const char *issuer_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200382
383/**
384 * \brief Set the subject name for a Certificate
385 * Subject names should contain a comma-separated list
386 * of OID types and values:
387 * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
388 *
389 * \param ctx CRT context to use
390 * \param subject_name subject name to set
391 *
392 * \return 0 if subject name was parsed successfully, or
393 * a specific error code
394 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100395int x509write_crt_set_subject_name( x509write_cert *ctx,
396 const char *subject_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200397
398/**
399 * \brief Set the subject public key for the certificate
400 *
401 * \param ctx CRT context to use
402 * \param key public key to include
403 */
404void x509write_crt_set_subject_key( x509write_cert *ctx, pk_context *key );
405
406/**
407 * \brief Set the issuer key used for signing the certificate
408 *
409 * \param ctx CRT context to use
410 * \param key private key to sign with
411 */
412void x509write_crt_set_issuer_key( x509write_cert *ctx, pk_context *key );
413
414/**
415 * \brief Set the MD algorithm to use for the signature
416 * (e.g. POLARSSL_MD_SHA1)
417 *
418 * \param ctx CRT context to use
Paul Bakkera36d23e2013-12-30 17:57:27 +0100419 * \param md_alg MD algorithm to use
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200420 */
421void x509write_crt_set_md_alg( x509write_cert *ctx, md_type_t md_alg );
422
423/**
424 * \brief Generic function to add to or replace an extension in the
425 * CRT
426 *
427 * \param ctx CRT context to use
428 * \param oid OID of the extension
429 * \param oid_len length of the OID
430 * \param critical if the extension is critical (per the RFC's definition)
431 * \param val value of the extension OCTET STRING
432 * \param val_len length of the value data
433 *
434 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
435 */
436int x509write_crt_set_extension( x509write_cert *ctx,
437 const char *oid, size_t oid_len,
438 int critical,
439 const unsigned char *val, size_t val_len );
440
441/**
442 * \brief Set the basicConstraints extension for a CRT
443 *
444 * \param ctx CRT context to use
445 * \param is_ca is this a CA certificate
446 * \param max_pathlen maximum length of certificate chains below this
447 * certificate (only for CA certificates, -1 is
448 * inlimited)
449 *
450 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
451 */
452int x509write_crt_set_basic_constraints( x509write_cert *ctx,
453 int is_ca, int max_pathlen );
454
Manuel Pégourié-Gonnard3daaf3d2013-10-27 14:22:02 +0100455#if defined(POLARSSL_SHA1_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200456/**
457 * \brief Set the subjectKeyIdentifier extension for a CRT
458 * Requires that x509write_crt_set_subject_key() has been
459 * called before
460 *
461 * \param ctx CRT context to use
462 *
463 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
464 */
465int x509write_crt_set_subject_key_identifier( x509write_cert *ctx );
466
467/**
468 * \brief Set the authorityKeyIdentifier extension for a CRT
469 * Requires that x509write_crt_set_issuer_key() has been
470 * called before
471 *
472 * \param ctx CRT context to use
473 *
474 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
475 */
476int x509write_crt_set_authority_key_identifier( x509write_cert *ctx );
Manuel Pégourié-Gonnard3daaf3d2013-10-27 14:22:02 +0100477#endif /* POLARSSL_SHA1_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200478
479/**
480 * \brief Set the Key Usage Extension flags
481 * (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN)
482 *
483 * \param ctx CRT context to use
484 * \param key_usage key usage flags to set
485 *
486 * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
487 */
488int x509write_crt_set_key_usage( x509write_cert *ctx, unsigned char key_usage );
489
490/**
491 * \brief Set the Netscape Cert Type flags
492 * (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL)
493 *
494 * \param ctx CRT context to use
495 * \param ns_cert_type Netscape Cert Type flags to set
496 *
497 * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
498 */
499int x509write_crt_set_ns_cert_type( x509write_cert *ctx,
500 unsigned char ns_cert_type );
501
502/**
503 * \brief Free the contents of a CRT write context
504 *
505 * \param ctx CRT context to free
506 */
507void x509write_crt_free( x509write_cert *ctx );
508
509/**
510 * \brief Write a built up certificate to a X509 DER structure
511 * Note: data is written at the end of the buffer! Use the
512 * return value to determine where you should start
513 * using the buffer
514 *
Paul Bakkera36d23e2013-12-30 17:57:27 +0100515 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200516 * \param buf buffer to write to
517 * \param size size of the buffer
518 * \param f_rng RNG function (for signature, see note)
519 * \param p_rng RNG parameter
520 *
521 * \return length of data written if successful, or a specific
522 * error code
523 *
524 * \note f_rng may be NULL if RSA is used for signature and the
525 * signature is made offline (otherwise f_rng is desirable
526 * for countermeasures against timing attacks).
527 * ECDSA signatures always require a non-NULL f_rng.
528 */
529int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
530 int (*f_rng)(void *, unsigned char *, size_t),
531 void *p_rng );
532
533#if defined(POLARSSL_PEM_WRITE_C)
534/**
535 * \brief Write a built up certificate to a X509 PEM string
536 *
Paul Bakkera36d23e2013-12-30 17:57:27 +0100537 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200538 * \param buf buffer to write to
539 * \param size size of the buffer
540 * \param f_rng RNG function (for signature, see note)
541 * \param p_rng RNG parameter
542 *
543 * \return 0 successful, or a specific error code
544 *
545 * \note f_rng may be NULL if RSA is used for signature and the
546 * signature is made offline (otherwise f_rng is desirable
547 * for countermeasures against timing attacks).
548 * ECDSA signatures always require a non-NULL f_rng.
549 */
550int x509write_crt_pem( x509write_cert *ctx, unsigned char *buf, size_t size,
551 int (*f_rng)(void *, unsigned char *, size_t),
552 void *p_rng );
553#endif /* POLARSSL_PEM_WRITE_C */
554#endif /* POLARSSL_X509_CRT_WRITE_C */
555
556#ifdef __cplusplus
557}
558#endif
559
560#endif /* x509_crt.h */