#include "polarssl/config.h"#include "polarssl/x509_crt.h"#include "polarssl/oid.h"#include "polarssl/asn1write.h"#include "polarssl/sha1.h"#include "polarssl/pem.h"
Go to the source code of this file.
Defines | |
| #define | PEM_BEGIN_CRT "-----BEGIN CERTIFICATE-----\n" |
| #define | PEM_END_CRT "-----END CERTIFICATE-----\n" |
Functions | |
| void | x509write_crt_init (x509write_cert *ctx) |
| Initialize a CRT writing context. | |
| void | x509write_crt_free (x509write_cert *ctx) |
| Free the contents of a CRT write context. | |
| void | x509write_crt_set_version (x509write_cert *ctx, int version) |
| Set the verion for a Certificate Default: X509_CRT_VERSION_3. | |
| void | x509write_crt_set_md_alg (x509write_cert *ctx, md_type_t md_alg) |
| Set the MD algorithm to use for the signature (e.g. | |
| void | x509write_crt_set_subject_key (x509write_cert *ctx, pk_context *key) |
| Set the subject public key for the certificate. | |
| void | x509write_crt_set_issuer_key (x509write_cert *ctx, pk_context *key) |
| Set the issuer key used for signing the certificate. | |
| int | x509write_crt_set_subject_name (x509write_cert *ctx, const char *subject_name) |
| Set the subject name for a Certificate Subject names should contain a comma-separated list of OID types and values: e.g. | |
| int | x509write_crt_set_issuer_name (x509write_cert *ctx, const char *issuer_name) |
| Set the issuer name for a Certificate Issuer names should contain a comma-separated list of OID types and values: e.g. | |
| int | x509write_crt_set_serial (x509write_cert *ctx, const mpi *serial) |
| Set the serial number for a Certificate. | |
| int | x509write_crt_set_validity (x509write_cert *ctx, const char *not_before, const char *not_after) |
| Set the validity period for a Certificate Timestamps should be in string format for UTC timezone i.e. | |
| 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) |
| Generic function to add to or replace an extension in the CRT. | |
| int | x509write_crt_set_basic_constraints (x509write_cert *ctx, int is_ca, int max_pathlen) |
| Set the basicConstraints extension for a CRT. | |
| int | x509write_crt_set_subject_key_identifier (x509write_cert *ctx) |
| Set the subjectKeyIdentifier extension for a CRT Requires that x509write_crt_set_subject_key() has been called before. | |
| int | x509write_crt_set_authority_key_identifier (x509write_cert *ctx) |
| Set the authorityKeyIdentifier extension for a CRT Requires that x509write_crt_set_issuer_key() has been called before. | |
| int | x509write_crt_set_key_usage (x509write_cert *ctx, unsigned char key_usage) |
| Set the Key Usage Extension flags (e.g. | |
| int | x509write_crt_set_ns_cert_type (x509write_cert *ctx, unsigned char ns_cert_type) |
| Set the Netscape Cert Type flags (e.g. | |
| static int | x509_write_time (unsigned char **p, unsigned char *start, const char *time, size_t size) |
| int | x509write_crt_der (x509write_cert *ctx, unsigned char *buf, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
| Write a built up certificate to a X509 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. | |
| int | x509write_crt_pem (x509write_cert *crt, unsigned char *buf, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
| Write a built up certificate to a X509 PEM string. | |
| #define PEM_BEGIN_CRT "-----BEGIN CERTIFICATE-----\n" |
Definition at line 406 of file x509write_crt.c.
Referenced by x509write_crt_pem().
| #define PEM_END_CRT "-----END CERTIFICATE-----\n" |
Definition at line 407 of file x509write_crt.c.
Referenced by x509write_crt_pem().
| static int x509_write_time | ( | unsigned char ** | p, | |
| unsigned char * | start, | |||
| const char * | time, | |||
| size_t | size | |||
| ) | [static] |
Definition at line 251 of file x509write_crt.c.
References ASN1_CHK_ADD, ASN1_GENERALIZED_TIME, ASN1_UTC_TIME, asn1_write_len(), asn1_write_raw_buffer(), and asn1_write_tag().
Referenced by x509write_crt_der().
| int x509write_crt_der | ( | x509write_cert * | ctx, | |
| unsigned char * | buf, | |||
| size_t | size, | |||
| int(*)(void *, unsigned char *, size_t) | f_rng, | |||
| void * | p_rng | |||
| ) |
Write a built up certificate to a X509 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.
| crt | certificate to write away | |
| buf | buffer to write to | |
| size | size of the buffer | |
| f_rng | RNG function (for signature, see note) | |
| p_rng | RNG parameter |
Definition at line 280 of file x509write_crt.c.
References ASN1_CHK_ADD, ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, ASN1_SEQUENCE, asn1_write_algorithm_identifier(), asn1_write_int(), asn1_write_len(), asn1_write_mpi(), asn1_write_tag(), _x509write_cert::extensions, _x509write_cert::issuer, _x509write_cert::issuer_key, md(), _x509write_cert::md_alg, md_info_from_type(), _x509write_cert::not_after, _x509write_cert::not_before, oid_get_oid_by_sig_alg(), pk_get_type(), pk_sign(), pk_write_pubkey_der(), POLARSSL_MPI_MAX_SIZE, POLARSSL_PK_ECDSA, POLARSSL_PK_ECKEY, _x509write_cert::serial, _x509write_cert::subject, _x509write_cert::subject_key, _x509write_cert::version, X509_RFC5280_UTC_TIME_LEN, x509_write_extensions(), x509_write_names(), x509_write_sig(), and x509_write_time().
Referenced by x509write_crt_pem().
| void x509write_crt_free | ( | x509write_cert * | ctx | ) |
Free the contents of a CRT write context.
| ctx | CRT context to free |
Definition at line 53 of file x509write_crt.c.
References asn1_free_named_data_list(), _x509write_cert::extensions, _x509write_cert::issuer, mpi_free(), _x509write_cert::serial, and _x509write_cert::subject.
| void x509write_crt_init | ( | x509write_cert * | ctx | ) |
Initialize a CRT writing context.
| ctx | CRT context to initialize |
Definition at line 45 of file x509write_crt.c.
References mpi_init(), _x509write_cert::serial, _x509write_cert::version, and X509_CRT_VERSION_3.
| int x509write_crt_pem | ( | x509write_cert * | ctx, | |
| unsigned char * | buf, | |||
| size_t | size, | |||
| int(*)(void *, unsigned char *, size_t) | f_rng, | |||
| void * | p_rng | |||
| ) |
Write a built up certificate to a X509 PEM string.
| crt | certificate to write away | |
| buf | buffer to write to | |
| size | size of the buffer | |
| f_rng | RNG function (for signature, see note) | |
| p_rng | RNG parameter |
Definition at line 410 of file x509write_crt.c.
References PEM_BEGIN_CRT, PEM_END_CRT, pem_write_buffer(), and x509write_crt_der().
| int x509write_crt_set_authority_key_identifier | ( | x509write_cert * | ctx | ) |
Set the authorityKeyIdentifier extension for a CRT Requires that x509write_crt_set_issuer_key() has been called before.
| ctx | CRT context to use |
Definition at line 184 of file x509write_crt.c.
References ASN1_CHK_ADD, ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, ASN1_SEQUENCE, asn1_write_len(), asn1_write_tag(), _x509write_cert::issuer_key, OID_AUTHORITY_KEY_IDENTIFIER, OID_SIZE, pk_write_pubkey(), POLARSSL_MPI_MAX_SIZE, sha1(), and x509write_crt_set_extension().
| int x509write_crt_set_basic_constraints | ( | x509write_cert * | ctx, | |
| int | is_ca, | |||
| int | max_pathlen | |||
| ) |
Set the basicConstraints extension for a CRT.
| ctx | CRT context to use | |
| is_ca | is this a CA certificate | |
| max_pathlen | maximum length of certificate chains below this certificate (only for CA certificates, -1 is inlimited) |
Definition at line 131 of file x509write_crt.c.
References ASN1_CHK_ADD, ASN1_CONSTRUCTED, ASN1_SEQUENCE, asn1_write_bool(), asn1_write_int(), asn1_write_len(), asn1_write_tag(), OID_BASIC_CONSTRAINTS, OID_SIZE, POLARSSL_ERR_X509_BAD_INPUT_DATA, and x509write_crt_set_extension().
| 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 | |||
| ) |
Generic function to add to or replace an extension in the CRT.
| ctx | CRT context to use | |
| oid | OID of the extension | |
| oid_len | length of the OID | |
| critical | if the extension is critical (per the RFC's definition) | |
| val | value of the extension OCTET STRING | |
| val_len | length of the value data |
Definition at line 122 of file x509write_crt.c.
References _x509write_cert::extensions, and x509_set_extension().
Referenced by x509write_crt_set_authority_key_identifier(), x509write_crt_set_basic_constraints(), x509write_crt_set_key_usage(), x509write_crt_set_ns_cert_type(), and x509write_crt_set_subject_key_identifier().
| void x509write_crt_set_issuer_key | ( | x509write_cert * | ctx, | |
| pk_context * | key | |||
| ) |
Set the issuer key used for signing the certificate.
| ctx | CRT context to use | |
| key | private key to sign with |
Definition at line 79 of file x509write_crt.c.
References _x509write_cert::issuer_key.
| int x509write_crt_set_issuer_name | ( | x509write_cert * | ctx, | |
| const char * | issuer_name | |||
| ) |
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"
| ctx | CRT context to use | |
| issuer_name | issuer name to set |
Definition at line 90 of file x509write_crt.c.
References _x509write_cert::issuer, and x509_string_to_names().
| int x509write_crt_set_key_usage | ( | x509write_cert * | ctx, | |
| unsigned char | key_usage | |||
| ) |
Set the Key Usage Extension flags (e.g.
KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN)
| ctx | CRT context to use | |
| key_usage | key usage flags to set |
Definition at line 210 of file x509write_crt.c.
References asn1_write_bitstring(), OID_KEY_USAGE, OID_SIZE, and x509write_crt_set_extension().
| void x509write_crt_set_md_alg | ( | x509write_cert * | ctx, | |
| md_type_t | md_alg | |||
| ) |
Set the MD algorithm to use for the signature (e.g.
POLARSSL_MD_SHA1)
| ctx | CRT context to use | |
| md_ald | MD algorithm to use |
Definition at line 69 of file x509write_crt.c.
References _x509write_cert::md_alg.
| int x509write_crt_set_ns_cert_type | ( | x509write_cert * | ctx, | |
| unsigned char | ns_cert_type | |||
| ) |
Set the Netscape Cert Type flags (e.g.
NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL)
| ctx | CRT context to use | |
| ns_cert_type | Netscape Cert Type flags to set |
Definition at line 230 of file x509write_crt.c.
References asn1_write_bitstring(), OID_NS_CERT_TYPE, OID_SIZE, and x509write_crt_set_extension().
| int x509write_crt_set_serial | ( | x509write_cert * | ctx, | |
| const mpi * | serial | |||
| ) |
Set the serial number for a Certificate.
| ctx | CRT context to use | |
| serial | serial number to set |
Definition at line 96 of file x509write_crt.c.
References mpi_copy(), and _x509write_cert::serial.
| void x509write_crt_set_subject_key | ( | x509write_cert * | ctx, | |
| pk_context * | key | |||
| ) |
Set the subject public key for the certificate.
| ctx | CRT context to use | |
| key | public key to include |
Definition at line 74 of file x509write_crt.c.
References _x509write_cert::subject_key.
| int x509write_crt_set_subject_key_identifier | ( | x509write_cert * | ctx | ) |
Set the subjectKeyIdentifier extension for a CRT Requires that x509write_crt_set_subject_key() has been called before.
| ctx | CRT context to use |
Definition at line 162 of file x509write_crt.c.
References ASN1_CHK_ADD, ASN1_OCTET_STRING, asn1_write_len(), asn1_write_tag(), OID_SIZE, OID_SUBJECT_KEY_IDENTIFIER, pk_write_pubkey(), POLARSSL_MPI_MAX_SIZE, sha1(), _x509write_cert::subject_key, and x509write_crt_set_extension().
| int x509write_crt_set_subject_name | ( | x509write_cert * | ctx, | |
| const char * | subject_name | |||
| ) |
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"
| ctx | CRT context to use | |
| subject_name | subject name to set |
Definition at line 84 of file x509write_crt.c.
References _x509write_cert::subject, and x509_string_to_names().
| int x509write_crt_set_validity | ( | x509write_cert * | ctx, | |
| const char * | not_before, | |||
| const char * | not_after | |||
| ) |
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
| ctx | CRT context to use | |
| not_before | not_before timestamp | |
| not_after | not_after timestamp |
Definition at line 106 of file x509write_crt.c.
References _x509write_cert::not_after, _x509write_cert::not_before, POLARSSL_ERR_X509_BAD_INPUT_DATA, and X509_RFC5280_UTC_TIME_LEN.
| void x509write_crt_set_version | ( | x509write_cert * | ctx, | |
| int | version | |||
| ) |
Set the verion for a Certificate Default: X509_CRT_VERSION_3.
| ctx | CRT context to use | |
| version | version to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or X509_CRT_VERSION_3) |
Definition at line 64 of file x509write_crt.c.
References _x509write_cert::version.
1.6.1