2012-02-14 00:11:30 +01:00
|
|
|
/**
|
|
|
|
* \file x509write.h
|
|
|
|
*
|
|
|
|
* \brief X509 buffer writing functionality
|
|
|
|
*
|
2013-06-27 14:29:21 +02:00
|
|
|
* Copyright (C) 2006-2013, Brainspark B.V.
|
2012-02-14 00:11:30 +01:00
|
|
|
*
|
|
|
|
* This file is part of PolarSSL (http://www.polarssl.org)
|
|
|
|
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
#ifndef POLARSSL_X509_WRITE_H
|
|
|
|
#define POLARSSL_X509_WRITE_H
|
|
|
|
|
2013-04-19 14:51:29 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-08-25 14:47:27 +02:00
|
|
|
#include "x509.h"
|
2012-02-14 00:11:30 +01:00
|
|
|
|
2013-08-25 11:47:51 +02:00
|
|
|
/**
|
|
|
|
* \addtogroup x509_module
|
|
|
|
* \{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \name X509 Write Error codes
|
|
|
|
* \{
|
|
|
|
*/
|
2013-08-25 11:21:30 +02:00
|
|
|
#define POLARSSL_ERR_X509WRITE_UNKNOWN_OID -0x5F80 /**< Requested OID is unknown. */
|
|
|
|
#define POLARSSL_ERR_X509WRITE_BAD_INPUT_DATA -0x5F00 /**< Failed to allocate memory. */
|
|
|
|
#define POLARSSL_ERR_X509WRITE_MALLOC_FAILED -0x5E80 /**< Failed to allocate memory. */
|
2013-08-25 11:47:51 +02:00
|
|
|
/* \} name */
|
|
|
|
/* \} addtogroup x509_module */
|
2013-08-25 10:18:25 +02:00
|
|
|
|
2013-06-27 14:29:21 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-08-25 11:47:51 +02:00
|
|
|
/**
|
|
|
|
* \addtogroup x509_module
|
|
|
|
* \{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \name Structures for writing X.509 CSRs (Certificate Signing Request)
|
|
|
|
* \{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for a CSR
|
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
typedef struct _x509write_csr
|
2012-02-14 00:11:30 +01:00
|
|
|
{
|
2013-09-11 12:14:26 +02:00
|
|
|
pk_context *key;
|
2013-09-09 12:02:36 +02:00
|
|
|
asn1_named_data *subject;
|
2013-08-25 10:18:25 +02:00
|
|
|
md_type_t md_alg;
|
2013-08-26 12:05:14 +02:00
|
|
|
asn1_named_data *extensions;
|
2012-02-14 00:11:30 +01:00
|
|
|
}
|
2013-09-09 12:08:11 +02:00
|
|
|
x509write_csr;
|
2013-08-25 10:18:25 +02:00
|
|
|
|
2013-09-06 09:55:26 +02:00
|
|
|
#define X509_CRT_VERSION_1 0
|
|
|
|
#define X509_CRT_VERSION_2 1
|
|
|
|
#define X509_CRT_VERSION_3 2
|
|
|
|
|
|
|
|
#define X509_RFC5280_MAX_SERIAL_LEN 32
|
|
|
|
#define X509_RFC5280_UTC_TIME_LEN 15
|
2012-02-14 00:11:30 +01:00
|
|
|
|
2013-08-25 11:47:51 +02:00
|
|
|
/**
|
2013-09-06 09:55:26 +02:00
|
|
|
* Container for writing a certificate (CRT)
|
2013-08-25 11:47:51 +02:00
|
|
|
*/
|
2013-09-06 09:55:26 +02:00
|
|
|
typedef struct _x509write_cert
|
2013-08-25 10:18:25 +02:00
|
|
|
{
|
2013-09-06 09:55:26 +02:00
|
|
|
int version;
|
|
|
|
mpi serial;
|
2013-09-12 05:39:46 +02:00
|
|
|
pk_context *subject_key;
|
|
|
|
pk_context *issuer_key;
|
2013-09-09 12:02:36 +02:00
|
|
|
asn1_named_data *subject;
|
|
|
|
asn1_named_data *issuer;
|
2013-08-25 10:18:25 +02:00
|
|
|
md_type_t md_alg;
|
2013-09-06 09:55:26 +02:00
|
|
|
char not_before[X509_RFC5280_UTC_TIME_LEN + 1];
|
|
|
|
char not_after[X509_RFC5280_UTC_TIME_LEN + 1];
|
2013-08-26 12:05:14 +02:00
|
|
|
asn1_named_data *extensions;
|
2013-08-25 10:18:25 +02:00
|
|
|
}
|
2013-09-06 09:55:26 +02:00
|
|
|
x509write_cert;
|
2013-08-25 10:18:25 +02:00
|
|
|
|
2013-09-10 16:16:50 +02:00
|
|
|
/* \} name */
|
2013-08-25 11:47:51 +02:00
|
|
|
/* \} addtogroup x509_module */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Initialize a CSR context
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to initialize
|
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
void x509write_csr_init( x509write_csr *ctx );
|
2013-08-25 11:47:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the subject name for a CSR
|
|
|
|
* Subject names should contain a comma-separated list
|
|
|
|
* of OID types and values:
|
|
|
|
* e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to use
|
|
|
|
* \param subject_name subject name to set
|
|
|
|
*
|
|
|
|
* \return 0 if subject name was parsed successfully, or
|
|
|
|
* a specific error code
|
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
int x509write_csr_set_subject_name( x509write_csr *ctx, char *subject_name );
|
2013-08-25 11:47:51 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-11 22:48:40 +02:00
|
|
|
* \brief Set the key for a CSR (public key will be included,
|
2013-08-25 11:47:51 +02:00
|
|
|
* private key used to sign the CSR when writing it)
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to use
|
2013-09-11 22:48:40 +02:00
|
|
|
* \param key Asymetric key to include
|
2013-08-25 11:47:51 +02:00
|
|
|
*/
|
2013-09-11 22:48:40 +02:00
|
|
|
void x509write_csr_set_key( x509write_csr *ctx, pk_context *key );
|
2013-08-25 11:47:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the MD algorithm to use for the signature
|
|
|
|
* (e.g. POLARSSL_MD_SHA1)
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to use
|
2013-09-10 16:16:50 +02:00
|
|
|
* \param md_alg MD algorithm to use
|
2013-08-25 11:47:51 +02:00
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
void x509write_csr_set_md_alg( x509write_csr *ctx, md_type_t md_alg );
|
2013-08-25 11:47:51 +02:00
|
|
|
|
2013-08-25 14:47:27 +02:00
|
|
|
/**
|
|
|
|
* \brief Set the Key Usage Extension flags
|
|
|
|
* (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN)
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to use
|
2013-08-26 13:41:01 +02:00
|
|
|
* \param key_usage key usage flags to set
|
2013-08-26 12:05:14 +02:00
|
|
|
*
|
|
|
|
* \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
2013-08-25 14:47:27 +02:00
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
int x509write_csr_set_key_usage( x509write_csr *ctx, unsigned char key_usage );
|
2013-08-25 14:47:27 +02:00
|
|
|
|
2013-08-26 13:41:01 +02:00
|
|
|
/**
|
|
|
|
* \brief Set the Netscape Cert Type flags
|
|
|
|
* (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL)
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to use
|
|
|
|
* \param ns_cert_type Netscape Cert Type flags to set
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
int x509write_csr_set_ns_cert_type( x509write_csr *ctx,
|
|
|
|
unsigned char ns_cert_type );
|
2013-08-26 13:41:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Generic function to add to or replace an extension in the CSR
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to use
|
|
|
|
* \param oid OID of the extension
|
|
|
|
* \param oid_len length of the OID
|
|
|
|
* \param val value of the extension OCTET STRING
|
|
|
|
* \param val_len length of the value data
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
int x509write_csr_set_extension( x509write_csr *ctx,
|
2013-08-26 13:41:01 +02:00
|
|
|
const char *oid, size_t oid_len,
|
|
|
|
const unsigned char *val, size_t val_len );
|
|
|
|
|
2013-08-25 11:47:51 +02:00
|
|
|
/**
|
|
|
|
* \brief Free the contents of a CSR context
|
|
|
|
*
|
|
|
|
* \param ctx CSR context to free
|
|
|
|
*/
|
2013-09-09 12:08:11 +02:00
|
|
|
void x509write_csr_free( x509write_csr *ctx );
|
2013-08-25 10:18:25 +02:00
|
|
|
|
2013-09-06 09:55:26 +02:00
|
|
|
/**
|
|
|
|
* \brief Initialize a CRT writing context
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to initialize
|
|
|
|
*/
|
|
|
|
void x509write_crt_init( x509write_cert *ctx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the verion for a Certificate
|
|
|
|
* Default: X509_CRT_VERSION_3
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param version version to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or
|
|
|
|
* X509_CRT_VERSION_3)
|
|
|
|
*/
|
|
|
|
void x509write_crt_set_version( x509write_cert *ctx, int version );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the serial number for a Certificate.
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param serial serial number to set
|
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_serial( x509write_cert *ctx, const mpi *serial );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the validity period for a Certificate
|
|
|
|
* Timestamps should be in string format for UTC timezone
|
|
|
|
* i.e. "YYYYMMDDhhmmss"
|
|
|
|
* e.g. "20131231235959" for December 31st 2013
|
|
|
|
* at 23:59:59
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param not_before not_before timestamp
|
|
|
|
* \param not_after not_after timestamp
|
|
|
|
*
|
|
|
|
* \return 0 if timestamp was parsed successfully, or
|
|
|
|
* a specific error code
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_validity( x509write_cert *ctx, char *not_before,
|
|
|
|
char *not_after );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the issuer name for a Certificate
|
|
|
|
* Issuer names should contain a comma-separated list
|
|
|
|
* of OID types and values:
|
|
|
|
* e.g. "C=NL,O=Offspark,CN=PolarSSL CA"
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param issuer_name issuer name to set
|
|
|
|
*
|
|
|
|
* \return 0 if issuer name was parsed successfully, or
|
|
|
|
* a specific error code
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_issuer_name( x509write_cert *ctx, char *issuer_name );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the subject name for a Certificate
|
|
|
|
* Subject names should contain a comma-separated list
|
|
|
|
* of OID types and values:
|
|
|
|
* e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param subject_name subject name to set
|
|
|
|
*
|
|
|
|
* \return 0 if subject name was parsed successfully, or
|
|
|
|
* a specific error code
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_subject_name( x509write_cert *ctx, char *subject_name );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the subject public key for the certificate
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
2013-09-12 05:21:54 +02:00
|
|
|
* \param key public key to include
|
2013-09-06 09:55:26 +02:00
|
|
|
*/
|
2013-09-12 05:21:54 +02:00
|
|
|
void x509write_crt_set_subject_key( x509write_cert *ctx, pk_context *key );
|
2013-09-06 09:55:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the issuer key used for signing the certificate
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
2013-09-12 05:21:54 +02:00
|
|
|
* \param key private key to sign with
|
2013-09-06 09:55:26 +02:00
|
|
|
*/
|
2013-09-12 05:21:54 +02:00
|
|
|
void x509write_crt_set_issuer_key( x509write_cert *ctx, pk_context *key );
|
2013-09-06 09:55:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the MD algorithm to use for the signature
|
|
|
|
* (e.g. POLARSSL_MD_SHA1)
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param md_ald MD algorithm to use
|
|
|
|
*/
|
|
|
|
void x509write_crt_set_md_alg( x509write_cert *ctx, md_type_t md_alg );
|
|
|
|
|
2013-09-06 19:27:21 +02:00
|
|
|
/**
|
|
|
|
* \brief Generic function to add to or replace an extension in the
|
|
|
|
* CRT
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param oid OID of the extension
|
|
|
|
* \param oid_len length of the OID
|
|
|
|
* \param critical if the extension is critical (per the RFC's definition)
|
|
|
|
* \param val value of the extension OCTET STRING
|
|
|
|
* \param val_len length of the value data
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_extension( x509write_cert *ctx,
|
|
|
|
const char *oid, size_t oid_len,
|
|
|
|
int critical,
|
|
|
|
const unsigned char *val, size_t val_len );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the basicConstraints extension for a CRT
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param is_ca is this a CA certificate
|
|
|
|
* \param max_pathlen maximum length of certificate chains below this
|
|
|
|
* certificate (only for CA certificates, -1 is
|
|
|
|
* inlimited)
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_basic_constraints( x509write_cert *ctx,
|
|
|
|
int is_ca, int max_pathlen );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the subjectKeyIdentifier extension for a CRT
|
|
|
|
* Requires that x509write_crt_set_subject_key() has been
|
|
|
|
* called before
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_subject_key_identifier( x509write_cert *ctx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the authorityKeyIdentifier extension for a CRT
|
|
|
|
* Requires that x509write_crt_set_issuer_key() has been
|
|
|
|
* called before
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_authority_key_identifier( x509write_cert *ctx );
|
2013-08-25 10:18:25 +02:00
|
|
|
|
2013-08-25 11:47:51 +02:00
|
|
|
/**
|
2013-09-09 12:37:54 +02:00
|
|
|
* \brief Set the Key Usage Extension flags
|
|
|
|
* (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN)
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param key_usage key usage flags to set
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_key_usage( x509write_cert *ctx, unsigned char key_usage );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the Netscape Cert Type flags
|
|
|
|
* (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL)
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to use
|
|
|
|
* \param ns_cert_type Netscape Cert Type flags to set
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED
|
|
|
|
*/
|
|
|
|
int x509write_crt_set_ns_cert_type( x509write_cert *ctx,
|
|
|
|
unsigned char ns_cert_type );
|
|
|
|
|
2013-09-06 09:55:26 +02:00
|
|
|
/**
|
|
|
|
* \brief Free the contents of a CRT write context
|
|
|
|
*
|
|
|
|
* \param ctx CRT context to free
|
|
|
|
*/
|
|
|
|
void x509write_crt_free( x509write_cert *ctx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Write a built up certificate to a X509 DER structure
|
2013-08-25 11:47:51 +02:00
|
|
|
* Note: data is written at the end of the buffer! Use the
|
|
|
|
* return value to determine where you should start
|
|
|
|
* using the buffer
|
|
|
|
*
|
2013-09-06 09:55:26 +02:00
|
|
|
* \param crt certificate to write away
|
2013-08-25 11:47:51 +02:00
|
|
|
* \param buf buffer to write to
|
|
|
|
* \param size size of the buffer
|
2013-09-12 05:59:05 +02:00
|
|
|
* \param f_rng RNG function (for signature, see note)
|
|
|
|
* \param p_rng RNG parameter
|
2013-08-25 11:47:51 +02:00
|
|
|
*
|
|
|
|
* \return length of data written if successful, or a specific
|
|
|
|
* error code
|
2013-09-12 05:59:05 +02:00
|
|
|
*
|
|
|
|
* \note f_rng may be NULL if RSA is used for signature and the
|
|
|
|
* signature is made offline (otherwise f_rng is desirable
|
|
|
|
* for countermeasures against timing attacks).
|
|
|
|
* ECDSA signatures always require a non-NULL f_rng.
|
2013-08-25 11:47:51 +02:00
|
|
|
*/
|
2013-09-12 05:59:05 +02:00
|
|
|
int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
|
|
|
|
int (*f_rng)(void *, unsigned char *, size_t),
|
|
|
|
void *p_rng );
|
2013-08-25 11:47:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Write a CSR (Certificate Signing Request) to a
|
|
|
|
* DER structure
|
|
|
|
* Note: data is written at the end of the buffer! Use the
|
|
|
|
* return value to determine where you should start
|
|
|
|
* using the buffer
|
|
|
|
*
|
2013-09-10 16:16:50 +02:00
|
|
|
* \param ctx CSR to write away
|
2013-08-25 11:47:51 +02:00
|
|
|
* \param buf buffer to write to
|
|
|
|
* \param size size of the buffer
|
2013-09-11 22:48:40 +02:00
|
|
|
* \param f_rng RNG function (for signature, see note)
|
|
|
|
* \param p_rng RNG parameter
|
2013-08-25 11:47:51 +02:00
|
|
|
*
|
|
|
|
* \return length of data written if successful, or a specific
|
|
|
|
* error code
|
2013-09-11 22:48:40 +02:00
|
|
|
*
|
|
|
|
* \note f_rng may be NULL if RSA is used for signature and the
|
|
|
|
* signature is made offline (otherwise f_rng is desirable
|
|
|
|
* for countermeasures against timing attacks).
|
|
|
|
* ECDSA signatures always require a non-NULL f_rng.
|
2013-08-25 11:47:51 +02:00
|
|
|
*/
|
2013-09-11 22:48:40 +02:00
|
|
|
int x509write_csr_der( x509write_csr *ctx, unsigned char *buf, size_t size,
|
|
|
|
int (*f_rng)(void *, unsigned char *, size_t),
|
|
|
|
void *p_rng );
|
2012-02-14 00:11:30 +01:00
|
|
|
|
2013-09-15 20:03:26 +02:00
|
|
|
#if defined(POLARSSL_PEM_C)
|
2013-08-26 17:22:23 +02:00
|
|
|
/**
|
2013-09-06 09:55:26 +02:00
|
|
|
* \brief Write a built up certificate to a X509 PEM string
|
|
|
|
*
|
|
|
|
* \param crt certificate to write away
|
|
|
|
* \param buf buffer to write to
|
|
|
|
* \param size size of the buffer
|
2013-09-12 05:59:05 +02:00
|
|
|
* \param f_rng RNG function (for signature, see note)
|
|
|
|
* \param p_rng RNG parameter
|
2013-09-06 09:55:26 +02:00
|
|
|
*
|
|
|
|
* \return 0 successful, or a specific error code
|
2013-09-12 05:59:05 +02:00
|
|
|
*
|
|
|
|
* \note f_rng may be NULL if RSA is used for signature and the
|
|
|
|
* signature is made offline (otherwise f_rng is desirable
|
|
|
|
* for countermeasures against timing attacks).
|
|
|
|
* ECDSA signatures always require a non-NULL f_rng.
|
2013-09-06 09:55:26 +02:00
|
|
|
*/
|
2013-09-12 05:59:05 +02:00
|
|
|
int x509write_crt_pem( x509write_cert *ctx, unsigned char *buf, size_t size,
|
|
|
|
int (*f_rng)(void *, unsigned char *, size_t),
|
|
|
|
void *p_rng );
|
2013-09-06 09:55:26 +02:00
|
|
|
|
2013-08-26 16:54:13 +02:00
|
|
|
/**
|
|
|
|
* \brief Write a CSR (Certificate Signing Request) to a
|
|
|
|
* PEM string
|
|
|
|
*
|
2013-09-10 16:16:50 +02:00
|
|
|
* \param ctx CSR to write away
|
2013-08-26 16:54:13 +02:00
|
|
|
* \param buf buffer to write to
|
|
|
|
* \param size size of the buffer
|
2013-09-11 22:48:40 +02:00
|
|
|
* \param f_rng RNG function (for signature, see note)
|
|
|
|
* \param p_rng RNG parameter
|
2013-08-26 16:54:13 +02:00
|
|
|
*
|
|
|
|
* \return 0 successful, or a specific error code
|
2013-09-11 22:48:40 +02:00
|
|
|
*
|
|
|
|
* \note f_rng may be NULL if RSA is used for signature and the
|
|
|
|
* signature is made offline (otherwise f_rng is desirable
|
|
|
|
* for couermeasures against timing attacks).
|
|
|
|
* ECDSA signatures always require a non-NULL f_rng.
|
2013-08-26 16:54:13 +02:00
|
|
|
*/
|
2013-09-11 22:48:40 +02:00
|
|
|
int x509write_csr_pem( x509write_csr *ctx, unsigned char *buf, size_t size,
|
|
|
|
int (*f_rng)(void *, unsigned char *, size_t),
|
|
|
|
void *p_rng );
|
2013-09-15 20:03:26 +02:00
|
|
|
#endif /* POLARSSL_PEM_C */
|
2013-08-26 16:54:13 +02:00
|
|
|
|
2013-06-27 14:29:21 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-14 00:11:30 +01:00
|
|
|
#endif /* POLARSSL_X509_WRITE_H */
|