blob: 86686316cdaf09fc6fc6eaee12b534c2d016604d [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 */
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +020095 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)
Manuel Pégourié-Gonnardf75f2f72014-06-05 15:14:28 +020097 void *sig_opts; /**< Signature options to be passed to pk_verify_ext(), eg for RSASSA-PSS */
Manuel Pégourié-Gonnard59a75d52014-01-22 10:12:57 +010098 x509_buf sig_params; /**< Parameters for the signature algorithm */
99#endif
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200100
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200101 struct _x509_crt *next; /**< Next certificate in the CA-chain. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200102}
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200103x509_crt;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200104
105#define X509_CRT_VERSION_1 0
106#define X509_CRT_VERSION_2 1
107#define X509_CRT_VERSION_3 2
108
109#define X509_RFC5280_MAX_SERIAL_LEN 32
110#define X509_RFC5280_UTC_TIME_LEN 15
111
112/**
113 * Container for writing a certificate (CRT)
114 */
115typedef struct _x509write_cert
116{
117 int version;
118 mpi serial;
119 pk_context *subject_key;
120 pk_context *issuer_key;
121 asn1_named_data *subject;
122 asn1_named_data *issuer;
123 md_type_t md_alg;
124 char not_before[X509_RFC5280_UTC_TIME_LEN + 1];
125 char not_after[X509_RFC5280_UTC_TIME_LEN + 1];
126 asn1_named_data *extensions;
127}
128x509write_cert;
129
130#if defined(POLARSSL_X509_CRT_PARSE_C)
131/**
132 * \brief Parse a single DER formatted certificate and add it
133 * to the chained list.
134 *
135 * \param chain points to the start of the chain
136 * \param buf buffer holding the certificate DER data
137 * \param buflen size of the buffer
138 *
139 * \return 0 if successful, or a specific X509 or PEM error code
140 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200141int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200142 size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200143
144/**
145 * \brief Parse one or more certificates and add them
146 * to the chained list. Parses permissively. If some
147 * certificates can be parsed, the result is the number
148 * of failed certificates it encountered. If none complete
149 * correctly, the first error is returned.
150 *
151 * \param chain points to the start of the chain
152 * \param buf buffer holding the certificate data
153 * \param buflen size of the buffer
154 *
155 * \return 0 if all certificates parsed successfully, a positive number
156 * if partly successful or a specific X509 or PEM error code
157 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200158int x509_crt_parse( x509_crt *chain, const unsigned char *buf, size_t buflen );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200159
160#if defined(POLARSSL_FS_IO)
161/**
162 * \brief Load one or more certificates and add them
163 * to the chained list. Parses permissively. If some
164 * certificates can be parsed, the result is the number
165 * of failed certificates it encountered. If none complete
166 * correctly, the first error is returned.
167 *
168 * \param chain points to the start of the chain
169 * \param path filename to read the certificates from
170 *
171 * \return 0 if all certificates parsed successfully, a positive number
172 * if partly successful or a specific X509 or PEM error code
173 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200174int x509_crt_parse_file( x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200175
176/**
177 * \brief Load one or more certificate files from a path and add them
178 * to the chained list. Parses permissively. If some
179 * certificates can be parsed, the result is the number
180 * of failed certificates it encountered. If none complete
181 * correctly, the first error is returned.
182 *
Manuel Pégourié-Gonnarde3339ce2013-11-28 17:16:41 +0100183 * \warning This function is NOT thread-safe unless
184 * POLARSSL_THREADING_PTHREADS is defined. If you're using an
185 * alternative threading implementation, you should either use
186 * this function only in the main thread, or mutex it.
187 *
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200188 * \param chain points to the start of the chain
189 * \param path directory / folder to read the certificate files from
190 *
191 * \return 0 if all certificates parsed successfully, a positive number
192 * if partly successful or a specific X509 or PEM error code
193 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200194int x509_crt_parse_path( x509_crt *chain, const char *path );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200195#endif /* POLARSSL_FS_IO */
196
197/**
198 * \brief Returns an informational string about the
199 * certificate.
200 *
201 * \param buf Buffer to write to
202 * \param size Maximum size of buffer
203 * \param prefix A line prefix
204 * \param crt The X509 certificate to represent
205 *
206 * \return The amount of data written to the buffer, or -1 in
207 * case of an error.
208 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200209int x509_crt_info( char *buf, size_t size, const char *prefix,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200210 const x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200211
212/**
213 * \brief Verify the certificate signature
214 *
215 * The verify callback is a user-supplied callback that
216 * can clear / modify / add flags for a certificate. If set,
217 * the verification callback is called for each
218 * certificate in the chain (from the trust-ca down to the
219 * presented crt). The parameters for the callback are:
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200220 * (void *parameter, x509_crt *crt, int certificate_depth,
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200221 * int *flags). With the flags representing current flags for
222 * that specific certificate and the certificate depth from
223 * the bottom (Peer cert depth = 0).
224 *
225 * All flags left after returning from the callback
226 * are also returned to the application. The function should
227 * return 0 for anything but a fatal error.
228 *
229 * \param crt a certificate to be verified
230 * \param trust_ca the trusted CA chain
231 * \param ca_crl the CRL chain for trusted CA's
232 * \param cn expected Common Name (can be set to
233 * NULL if the CN must not be verified)
234 * \param flags result of the verification
235 * \param f_vrfy verification function
236 * \param p_vrfy verification parameter
237 *
238 * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
239 * in which case *flags will have one or more of
240 * the following values set:
241 * BADCERT_EXPIRED --
242 * BADCERT_REVOKED --
243 * BADCERT_CN_MISMATCH --
244 * BADCERT_NOT_TRUSTED
245 * or another error in case of a fatal error encountered
246 * during the verification process.
247 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200248int x509_crt_verify( x509_crt *crt,
249 x509_crt *trust_ca,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200250 x509_crl *ca_crl,
251 const char *cn, int *flags,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200252 int (*f_vrfy)(void *, x509_crt *, int, int *),
Paul Bakkerddf26b42013-09-18 13:46:23 +0200253 void *p_vrfy );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200254
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200255#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
256/**
257 * \brief Check usage of certificate against keyUsage extension.
258 *
259 * \param crt Leaf certificate used.
260 * \param usage Intended usage(s) (eg KU_KEY_ENCIPHERMENT before using the
261 * certificate to perform an RSA key exchange).
262 *
263 * \return 0 is these uses of the certificate are allowed,
Paul Bakker02ff5ce2014-04-09 15:53:09 +0200264 * POLARSSL_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200265 * is present but does not contain all the bits set in the
266 * usage argument.
267 *
268 * \note You should only call this function on leaf certificates, on
269 * (intermediate) CAs the keyUsage extension is automatically
270 * checked by \c x509_crt_verify().
271 */
272int x509_crt_check_key_usage( const x509_crt *crt, int usage );
273#endif /* POLARSSL_X509_CHECK_KEY_USAGE) */
274
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200275#if defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
276/**
277 * \brief Check usage of certificate against extentedJeyUsage.
278 *
279 * \param crt Leaf certificate used.
280 * \param usage_oid Intended usage (eg OID_SERVER_AUTH or OID_CLIENT_AUTH).
281 * \param usage_len Length of usage_oid (eg given by OID_SIZE()).
282 *
283 * \return 0 is this use of the certificate is allowed,
284 * POLARSSL_ERR_X509_BAD_INPUT_DATA if not.
285 *
286 * \note Usually only makes sense on leaf certificates.
287 */
288int x509_crt_check_extended_key_usage( const x509_crt *crt,
289 const char *usage_oid,
290 size_t usage_len );
291#endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE) */
292
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200293#if defined(POLARSSL_X509_CRL_PARSE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200294/**
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200295 * \brief Verify the certificate revocation status
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200296 *
297 * \param crt a certificate to be verified
298 * \param crl the CRL to verify against
299 *
300 * \return 1 if the certificate is revoked, 0 otherwise
301 *
302 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200303int x509_crt_revoked( const x509_crt *crt, const x509_crl *crl );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200304#endif /* POLARSSL_X509_CRL_PARSE_C */
305
306/**
Paul Bakker369d2eb2013-09-18 11:58:25 +0200307 * \brief Initialize a certificate (chain)
308 *
309 * \param crt Certificate chain to initialize
310 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200311void x509_crt_init( x509_crt *crt );
Paul Bakker369d2eb2013-09-18 11:58:25 +0200312
313/**
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200314 * \brief Unallocate all certificate data
315 *
316 * \param crt Certificate chain to free
317 */
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200318void x509_crt_free( x509_crt *crt );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200319#endif /* POLARSSL_X509_CRT_PARSE_C */
320
321/* \} name */
322/* \} addtogroup x509_module */
323
324#if defined(POLARSSL_X509_CRT_WRITE_C)
325/**
326 * \brief Initialize a CRT writing context
327 *
328 * \param ctx CRT context to initialize
329 */
330void x509write_crt_init( x509write_cert *ctx );
331
332/**
333 * \brief Set the verion for a Certificate
334 * Default: X509_CRT_VERSION_3
335 *
336 * \param ctx CRT context to use
337 * \param version version to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or
338 * X509_CRT_VERSION_3)
339 */
340void x509write_crt_set_version( x509write_cert *ctx, int version );
341
342/**
343 * \brief Set the serial number for a Certificate.
344 *
345 * \param ctx CRT context to use
346 * \param serial serial number to set
347 *
348 * \return 0 if successful
349 */
350int x509write_crt_set_serial( x509write_cert *ctx, const mpi *serial );
351
352/**
353 * \brief Set the validity period for a Certificate
354 * Timestamps should be in string format for UTC timezone
355 * i.e. "YYYYMMDDhhmmss"
356 * e.g. "20131231235959" for December 31st 2013
357 * at 23:59:59
358 *
359 * \param ctx CRT context to use
360 * \param not_before not_before timestamp
361 * \param not_after not_after timestamp
362 *
363 * \return 0 if timestamp was parsed successfully, or
364 * a specific error code
365 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100366int x509write_crt_set_validity( x509write_cert *ctx, const char *not_before,
367 const char *not_after );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200368
369/**
370 * \brief Set the issuer name for a Certificate
371 * Issuer names should contain a comma-separated list
372 * of OID types and values:
373 * e.g. "C=NL,O=Offspark,CN=PolarSSL CA"
374 *
375 * \param ctx CRT context to use
376 * \param issuer_name issuer name to set
377 *
378 * \return 0 if issuer name was parsed successfully, or
379 * a specific error code
380 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100381int x509write_crt_set_issuer_name( x509write_cert *ctx,
382 const char *issuer_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200383
384/**
385 * \brief Set the subject name for a Certificate
386 * Subject names should contain a comma-separated list
387 * of OID types and values:
388 * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
389 *
390 * \param ctx CRT context to use
391 * \param subject_name subject name to set
392 *
393 * \return 0 if subject name was parsed successfully, or
394 * a specific error code
395 */
Paul Bakker50dc8502013-10-28 21:19:10 +0100396int x509write_crt_set_subject_name( x509write_cert *ctx,
397 const char *subject_name );
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200398
399/**
400 * \brief Set the subject public key for the certificate
401 *
402 * \param ctx CRT context to use
403 * \param key public key to include
404 */
405void x509write_crt_set_subject_key( x509write_cert *ctx, pk_context *key );
406
407/**
408 * \brief Set the issuer key used for signing the certificate
409 *
410 * \param ctx CRT context to use
411 * \param key private key to sign with
412 */
413void x509write_crt_set_issuer_key( x509write_cert *ctx, pk_context *key );
414
415/**
416 * \brief Set the MD algorithm to use for the signature
417 * (e.g. POLARSSL_MD_SHA1)
418 *
419 * \param ctx CRT context to use
Paul Bakkera36d23e2013-12-30 17:57:27 +0100420 * \param md_alg MD algorithm to use
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200421 */
422void x509write_crt_set_md_alg( x509write_cert *ctx, md_type_t md_alg );
423
424/**
425 * \brief Generic function to add to or replace an extension in the
426 * CRT
427 *
428 * \param ctx CRT context to use
429 * \param oid OID of the extension
430 * \param oid_len length of the OID
431 * \param critical if the extension is critical (per the RFC's definition)
432 * \param val value of the extension OCTET STRING
433 * \param val_len length of the value data
434 *
435 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
436 */
437int x509write_crt_set_extension( x509write_cert *ctx,
438 const char *oid, size_t oid_len,
439 int critical,
440 const unsigned char *val, size_t val_len );
441
442/**
443 * \brief Set the basicConstraints extension for a CRT
444 *
445 * \param ctx CRT context to use
446 * \param is_ca is this a CA certificate
447 * \param max_pathlen maximum length of certificate chains below this
448 * certificate (only for CA certificates, -1 is
449 * inlimited)
450 *
451 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
452 */
453int x509write_crt_set_basic_constraints( x509write_cert *ctx,
454 int is_ca, int max_pathlen );
455
Manuel Pégourié-Gonnard3daaf3d2013-10-27 14:22:02 +0100456#if defined(POLARSSL_SHA1_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200457/**
458 * \brief Set the subjectKeyIdentifier extension for a CRT
459 * Requires that x509write_crt_set_subject_key() has been
460 * called before
461 *
462 * \param ctx CRT context to use
463 *
464 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
465 */
466int x509write_crt_set_subject_key_identifier( x509write_cert *ctx );
467
468/**
469 * \brief Set the authorityKeyIdentifier extension for a CRT
470 * Requires that x509write_crt_set_issuer_key() has been
471 * called before
472 *
473 * \param ctx CRT context to use
474 *
475 * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
476 */
477int x509write_crt_set_authority_key_identifier( x509write_cert *ctx );
Manuel Pégourié-Gonnard3daaf3d2013-10-27 14:22:02 +0100478#endif /* POLARSSL_SHA1_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200479
480/**
481 * \brief Set the Key Usage Extension flags
482 * (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN)
483 *
484 * \param ctx CRT context to use
485 * \param key_usage key usage flags to set
486 *
487 * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
488 */
489int x509write_crt_set_key_usage( x509write_cert *ctx, unsigned char key_usage );
490
491/**
492 * \brief Set the Netscape Cert Type flags
493 * (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL)
494 *
495 * \param ctx CRT context to use
496 * \param ns_cert_type Netscape Cert Type flags to set
497 *
498 * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
499 */
500int x509write_crt_set_ns_cert_type( x509write_cert *ctx,
501 unsigned char ns_cert_type );
502
503/**
504 * \brief Free the contents of a CRT write context
505 *
506 * \param ctx CRT context to free
507 */
508void x509write_crt_free( x509write_cert *ctx );
509
510/**
511 * \brief Write a built up certificate to a X509 DER structure
512 * Note: data is written at the end of the buffer! Use the
513 * return value to determine where you should start
514 * using the buffer
515 *
Paul Bakkera36d23e2013-12-30 17:57:27 +0100516 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200517 * \param buf buffer to write to
518 * \param size size of the buffer
519 * \param f_rng RNG function (for signature, see note)
520 * \param p_rng RNG parameter
521 *
522 * \return length of data written if successful, or a specific
523 * error code
524 *
525 * \note f_rng may be NULL if RSA is used for signature and the
526 * signature is made offline (otherwise f_rng is desirable
527 * for countermeasures against timing attacks).
528 * ECDSA signatures always require a non-NULL f_rng.
529 */
530int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
531 int (*f_rng)(void *, unsigned char *, size_t),
532 void *p_rng );
533
534#if defined(POLARSSL_PEM_WRITE_C)
535/**
536 * \brief Write a built up certificate to a X509 PEM string
537 *
Paul Bakkera36d23e2013-12-30 17:57:27 +0100538 * \param ctx certificate to write away
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200539 * \param buf buffer to write to
540 * \param size size of the buffer
541 * \param f_rng RNG function (for signature, see note)
542 * \param p_rng RNG parameter
543 *
544 * \return 0 successful, or a specific error code
545 *
546 * \note f_rng may be NULL if RSA is used for signature and the
547 * signature is made offline (otherwise f_rng is desirable
548 * for countermeasures against timing attacks).
549 * ECDSA signatures always require a non-NULL f_rng.
550 */
551int x509write_crt_pem( x509write_cert *ctx, unsigned char *buf, size_t size,
552 int (*f_rng)(void *, unsigned char *, size_t),
553 void *p_rng );
554#endif /* POLARSSL_PEM_WRITE_C */
555#endif /* POLARSSL_X509_CRT_WRITE_C */
556
557#ifdef __cplusplus
558}
559#endif
560
561#endif /* x509_crt.h */