blob: 0081d36c435345a89e19a805ce6daa6310d54601 [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 */;
96
Paul Bakkerc559c7a2013-09-18 14:13:26 +020097 struct _x509_crt *next; /**< Next certificate in the CA-chain. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020098}
Paul Bakkerc559c7a2013-09-18 14:13:26 +020099x509_crt;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100
101#define X509_CRT_VERSION_1 0
102#define X509_CRT_VERSION_2 1
103#define X509_CRT_VERSION_3 2
104
105#define X509_RFC5280_MAX_SERIAL_LEN 32
106#define X509_RFC5280_UTC_TIME_LEN 15
107
108/**
109 * Container for writing a certificate (CRT)
110 */
111typedef struct _x509write_cert
112{
113 int version;
114 mpi serial;
115 pk_context *subject_key;
116 pk_context *issuer_key;
117 asn1_named_data *subject;
118 asn1_named_data *issuer;
119 md_type_t md_alg;
120 char not_before[X509_RFC5280_UTC_TIME_LEN + 1];
121 char not_after[X509_RFC5280_UTC_TIME_LEN + 1];
122 asn1_named_data *extensions;
123}
124x509write_cert;
125
126#if defined(POLARSSL_X509_CRT_PARSE_C)
127/**
128 * \brief Parse a single DER formatted certificate and add it
129 * to the chained list.
130 *
131 * \param chain points to the start of the chain
132 * \param buf buffer holding the certificate DER data
133 * \param buflen size of the buffer
134 *
135 * \return 0 if successful, or a specific X509 or PEM error code
136 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200137int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200138 size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200139
140/**
141 * \brief Parse one or more certificates and add them
142 * to the chained list. Parses permissively. If some
143 * certificates can be parsed, the result is the number
144 * of failed certificates it encountered. If none complete
145 * correctly, the first error is returned.
146 *
147 * \param chain points to the start of the chain
148 * \param buf buffer holding the certificate data
149 * \param buflen size of the buffer
150 *
151 * \return 0 if all certificates parsed successfully, a positive number
152 * if partly successful or a specific X509 or PEM error code
153 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200154int x509_crt_parse( x509_crt *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200155
156#if defined(POLARSSL_FS_IO)
157/**
158 * \brief Load one or more certificates and add them
159 * to the chained list. Parses permissively. If some
160 * certificates can be parsed, the result is the number
161 * of failed certificates it encountered. If none complete
162 * correctly, the first error is returned.
163 *
164 * \param chain points to the start of the chain
165 * \param path filename to read the certificates from
166 *
167 * \return 0 if all certificates parsed successfully, a positive number
168 * if partly successful or a specific X509 or PEM error code
169 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200170int x509_crt_parse_file( x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200171
172/**
173 * \brief Load one or more certificate files from a path and add them
174 * to the chained list. Parses permissively. If some
175 * certificates can be parsed, the result is the number
176 * of failed certificates it encountered. If none complete
177 * correctly, the first error is returned.
178 *
Manuel Pégourié-Gonnarde3339ce2013-11-28 17:16:41 +0100179 * \warning This function is NOT thread-safe unless
180 * POLARSSL_THREADING_PTHREADS is defined. If you're using an
181 * alternative threading implementation, you should either use
182 * this function only in the main thread, or mutex it.
183 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200184 * \param chain points to the start of the chain
185 * \param path directory / folder to read the certificate files from
186 *
187 * \return 0 if all certificates parsed successfully, a positive number
188 * if partly successful or a specific X509 or PEM error code
189 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200190int x509_crt_parse_path( x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200191#endif /* POLARSSL_FS_IO */
192
193/**
194 * \brief Returns an informational string about the
195 * certificate.
196 *
197 * \param buf Buffer to write to
198 * \param size Maximum size of buffer
199 * \param prefix A line prefix
200 * \param crt The X509 certificate to represent
201 *
202 * \return The amount of data written to the buffer, or -1 in
203 * case of an error.
204 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200205int x509_crt_info( char *buf, size_t size, const char *prefix,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200206 const x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200207
208/**
209 * \brief Verify the certificate signature
210 *
211 * The verify callback is a user-supplied callback that
212 * can clear / modify / add flags for a certificate. If set,
213 * the verification callback is called for each
214 * certificate in the chain (from the trust-ca down to the
215 * presented crt). The parameters for the callback are:
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200216 * (void *parameter, x509_crt *crt, int certificate_depth,
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200217 * int *flags). With the flags representing current flags for
218 * that specific certificate and the certificate depth from
219 * the bottom (Peer cert depth = 0).
220 *
221 * All flags left after returning from the callback
222 * are also returned to the application. The function should
223 * return 0 for anything but a fatal error.
224 *
225 * \param crt a certificate to be verified
226 * \param trust_ca the trusted CA chain
227 * \param ca_crl the CRL chain for trusted CA's
228 * \param cn expected Common Name (can be set to
229 * NULL if the CN must not be verified)
230 * \param flags result of the verification
231 * \param f_vrfy verification function
232 * \param p_vrfy verification parameter
233 *
234 * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
235 * in which case *flags will have one or more of
236 * the following values set:
237 * BADCERT_EXPIRED --
238 * BADCERT_REVOKED --
239 * BADCERT_CN_MISMATCH --
240 * BADCERT_NOT_TRUSTED
241 * or another error in case of a fatal error encountered
242 * during the verification process.
243 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200244int x509_crt_verify( x509_crt *crt,
245 x509_crt *trust_ca,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200246 x509_crl *ca_crl,
247 const char *cn, int *flags,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200248 int (*f_vrfy)(void *, x509_crt *, int, int *),
Paul Bakkerddf26b42013-09-18 13:46:23 +0200249 void *p_vrfy );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200250
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200251#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
252/**
253 * \brief Check usage of certificate against keyUsage extension.
254 *
255 * \param crt Leaf certificate used.
256 * \param usage Intended usage(s) (eg KU_KEY_ENCIPHERMENT before using the
257 * certificate to perform an RSA key exchange).
258 *
259 * \return 0 is these uses of the certificate are allowed,
Paul Bakker02ff5ce2014-04-09 15:53:09 +0200260 * POLARSSL_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200261 * is present but does not contain all the bits set in the
262 * usage argument.
263 *
264 * \note You should only call this function on leaf certificates, on
265 * (intermediate) CAs the keyUsage extension is automatically
266 * checked by \c x509_crt_verify().
267 */
268int x509_crt_check_key_usage( const x509_crt *crt, int usage );
269#endif /* POLARSSL_X509_CHECK_KEY_USAGE) */
270
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200271#if defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
272/**
273 * \brief Check usage of certificate against extentedJeyUsage.
274 *
275 * \param crt Leaf certificate used.
276 * \param usage_oid Intended usage (eg OID_SERVER_AUTH or OID_CLIENT_AUTH).
277 * \param usage_len Length of usage_oid (eg given by OID_SIZE()).
278 *
279 * \return 0 is this use of the certificate is allowed,
280 * POLARSSL_ERR_X509_BAD_INPUT_DATA if not.
281 *
282 * \note Usually only makes sense on leaf certificates.
283 */
284int x509_crt_check_extended_key_usage( const x509_crt *crt,
285 const char *usage_oid,
286 size_t usage_len );
287#endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE) */
288
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200289#if defined(POLARSSL_X509_CRL_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200290/**
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200291 * \brief Verify the certificate revocation status
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200292 *
293 * \param crt a certificate to be verified
294 * \param crl the CRL to verify against
295 *
296 * \return 1 if the certificate is revoked, 0 otherwise
297 *
298 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200299int x509_crt_revoked( const x509_crt *crt, const x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200300#endif /* POLARSSL_X509_CRL_PARSE_C */
301
302/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200303 * \brief Initialize a certificate (chain)
304 *
305 * \param crt Certificate chain to initialize
306 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200307void x509_crt_init( x509_crt *crt );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200308
309/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200310 * \brief Unallocate all certificate data
311 *
312 * \param crt Certificate chain to free
313 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200314void x509_crt_free( x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200315#endif /* POLARSSL_X509_CRT_PARSE_C */
316
317/* \} name */
318/* \} addtogroup x509_module */
319
320#if defined(POLARSSL_X509_CRT_WRITE_C)
321/**
322 * \brief Initialize a CRT writing context
323 *
324 * \param ctx CRT context to initialize
325 */
326void x509write_crt_init( x509write_cert *ctx );
327
328/**
329 * \brief Set the verion for a Certificate
330 * Default: X509_CRT_VERSION_3
331 *
332 * \param ctx CRT context to use
333 * \param version version to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or
334 * X509_CRT_VERSION_3)
335 */
336void x509write_crt_set_version( x509write_cert *ctx, int version );
337
338/**
339 * \brief Set the serial number for a Certificate.
340 *
341 * \param ctx CRT context to use
342 * \param serial serial number to set
343 *
344 * \return 0 if successful
345 */
346int x509write_crt_set_serial( x509write_cert *ctx, const mpi *serial );
347
348/**
349 * \brief Set the validity period for a Certificate
350 * Timestamps should be in string format for UTC timezone
351 * i.e. "YYYYMMDDhhmmss"
352 * e.g. "20131231235959" for December 31st 2013
353 * at 23:59:59
354 *
355 * \param ctx CRT context to use
356 * \param not_before not_before timestamp
357 * \param not_after not_after timestamp
358 *
359 * \return 0 if timestamp was parsed successfully, or
360 * a specific error code
361 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100362int x509write_crt_set_validity( x509write_cert *ctx, const char *not_before,
363 const char *not_after );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200364
365/**
366 * \brief Set the issuer name for a Certificate
367 * Issuer names should contain a comma-separated list
368 * of OID types and values:
369 * e.g. "C=NL,O=Offspark,CN=PolarSSL CA"
370 *
371 * \param ctx CRT context to use
372 * \param issuer_name issuer name to set
373 *
374 * \return 0 if issuer name was parsed successfully, or
375 * a specific error code
376 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100377int x509write_crt_set_issuer_name( x509write_cert *ctx,
378 const char *issuer_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200379
380/**
381 * \brief Set the subject name for a Certificate
382 * Subject names should contain a comma-separated list
383 * of OID types and values:
384 * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
385 *
386 * \param ctx CRT context to use
387 * \param subject_name subject name to set
388 *
389 * \return 0 if subject name was parsed successfully, or
390 * a specific error code
391 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100392int x509write_crt_set_subject_name( x509write_cert *ctx,
393 const char *subject_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200394
395/**
396 * \brief Set the subject public key for the certificate
397 *
398 * \param ctx CRT context to use
399 * \param key public key to include
400 */
401void x509write_crt_set_subject_key( x509write_cert *ctx, pk_context *key );
402
403/**
404 * \brief Set the issuer key used for signing the certificate
405 *
406 * \param ctx CRT context to use
407 * \param key private key to sign with
408 */
409void x509write_crt_set_issuer_key( x509write_cert *ctx, pk_context *key );
410
411/**
412 * \brief Set the MD algorithm to use for the signature
413 * (e.g. POLARSSL_MD_SHA1)
414 *
415 * \param ctx CRT context to use
Paul Bakkera36d23e2013-12-30 17:57:27 +0100416 * \param md_alg MD algorithm to use
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200417 */
418void x509write_crt_set_md_alg( x509write_cert *ctx, md_type_t md_alg );
419
420/**
421 * \brief Generic function to add to or replace an extension in the
422 * CRT
423 *
424 * \param ctx CRT context to use
425 * \param oid OID of the extension
426 * \param oid_len length of the OID
427 * \param critical if the extension is critical (per the RFC's definition)
428 * \param val value of the extension OCTET STRING
429 * \param val_len length of the value data
430 *
431 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
432 */
433int x509write_crt_set_extension( x509write_cert *ctx,
434 const char *oid, size_t oid_len,
435 int critical,
436 const unsigned char *val, size_t val_len );
437
438/**
439 * \brief Set the basicConstraints extension for a CRT
440 *
441 * \param ctx CRT context to use
442 * \param is_ca is this a CA certificate
443 * \param max_pathlen maximum length of certificate chains below this
444 * certificate (only for CA certificates, -1 is
445 * inlimited)
446 *
447 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
448 */
449int x509write_crt_set_basic_constraints( x509write_cert *ctx,
450 int is_ca, int max_pathlen );
451
Manuel Pégourié-Gonnard3daaf3d2013-10-27 14:22:02 +0100452#if defined(POLARSSL_SHA1_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200453/**
454 * \brief Set the subjectKeyIdentifier extension for a CRT
455 * Requires that x509write_crt_set_subject_key() has been
456 * called before
457 *
458 * \param ctx CRT context to use
459 *
460 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
461 */
462int x509write_crt_set_subject_key_identifier( x509write_cert *ctx );
463
464/**
465 * \brief Set the authorityKeyIdentifier extension for a CRT
466 * Requires that x509write_crt_set_issuer_key() has been
467 * called before
468 *
469 * \param ctx CRT context to use
470 *
471 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
472 */
473int x509write_crt_set_authority_key_identifier( x509write_cert *ctx );
Manuel Pégourié-Gonnard3daaf3d2013-10-27 14:22:02 +0100474#endif /* POLARSSL_SHA1_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200475
476/**
477 * \brief Set the Key Usage Extension flags
478 * (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN)
479 *
480 * \param ctx CRT context to use
481 * \param key_usage key usage flags to set
482 *
483 * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
484 */
485int x509write_crt_set_key_usage( x509write_cert *ctx, unsigned char key_usage );
486
487/**
488 * \brief Set the Netscape Cert Type flags
489 * (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL)
490 *
491 * \param ctx CRT context to use
492 * \param ns_cert_type Netscape Cert Type flags to set
493 *
494 * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
495 */
496int x509write_crt_set_ns_cert_type( x509write_cert *ctx,
497 unsigned char ns_cert_type );
498
499/**
500 * \brief Free the contents of a CRT write context
501 *
502 * \param ctx CRT context to free
503 */
504void x509write_crt_free( x509write_cert *ctx );
505
506/**
507 * \brief Write a built up certificate to a X509 DER structure
508 * Note: data is written at the end of the buffer! Use the
509 * return value to determine where you should start
510 * using the buffer
511 *
Paul Bakkera36d23e2013-12-30 17:57:27 +0100512 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200513 * \param buf buffer to write to
514 * \param size size of the buffer
515 * \param f_rng RNG function (for signature, see note)
516 * \param p_rng RNG parameter
517 *
518 * \return length of data written if successful, or a specific
519 * error code
520 *
521 * \note f_rng may be NULL if RSA is used for signature and the
522 * signature is made offline (otherwise f_rng is desirable
523 * for countermeasures against timing attacks).
524 * ECDSA signatures always require a non-NULL f_rng.
525 */
526int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
527 int (*f_rng)(void *, unsigned char *, size_t),
528 void *p_rng );
529
530#if defined(POLARSSL_PEM_WRITE_C)
531/**
532 * \brief Write a built up certificate to a X509 PEM string
533 *
Paul Bakkera36d23e2013-12-30 17:57:27 +0100534 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200535 * \param buf buffer to write to
536 * \param size size of the buffer
537 * \param f_rng RNG function (for signature, see note)
538 * \param p_rng RNG parameter
539 *
540 * \return 0 successful, or a specific error code
541 *
542 * \note f_rng may be NULL if RSA is used for signature and the
543 * signature is made offline (otherwise f_rng is desirable
544 * for countermeasures against timing attacks).
545 * ECDSA signatures always require a non-NULL f_rng.
546 */
547int x509write_crt_pem( x509write_cert *ctx, unsigned char *buf, size_t size,
548 int (*f_rng)(void *, unsigned char *, size_t),
549 void *p_rng );
550#endif /* POLARSSL_PEM_WRITE_C */
551#endif /* POLARSSL_X509_CRT_WRITE_C */
552
553#ifdef __cplusplus
554}
555#endif
556
557#endif /* x509_crt.h */