27#ifndef POLARSSL_X509_CRT_H
28#define POLARSSL_X509_CRT_H
30#if !defined(POLARSSL_CONFIG_FILE)
33#include POLARSSL_CONFIG_FILE
102#define X509_CRT_VERSION_1 0
103#define X509_CRT_VERSION_2 1
104#define X509_CRT_VERSION_3 2
106#define X509_RFC5280_MAX_SERIAL_LEN 32
107#define X509_RFC5280_UTC_TIME_LEN 15
127#if defined(POLARSSL_X509_CRT_PARSE_C)
157#if defined(POLARSSL_FS_IO)
248 const char *cn,
int *flags,
249 int (*f_vrfy)(
void *,
x509_crt *,
int,
int *),
252#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
272#if defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
286 const char *usage_oid,
290#if defined(POLARSSL_X509_CRL_PARSE_C)
321#if defined(POLARSSL_X509_CRT_WRITE_C)
364 const char *not_after );
379 const char *issuer_name );
394 const char *subject_name );
435 const char *oid,
size_t oid_len,
437 const unsigned char *val,
size_t val_len );
451 int is_ca,
int max_pathlen );
453#if defined(POLARSSL_SHA1_C)
498 unsigned char ns_cert_type );
528 int (*f_rng)(
void *,
unsigned char *,
size_t),
531#if defined(POLARSSL_PEM_WRITE_C)
549 int (*f_rng)(
void *,
unsigned char *,
size_t),
Configuration options (set of defines)
void x509write_crt_init(x509write_cert *ctx)
Initialize a CRT writing context.
x509_buf subject_id
Optional X.509 v2/v3 subject unique identifier.
x509_time valid_to
End time of certificate validity.
int max_pathlen
Optional Basic Constraint extension value: The maximum path length to the root certificate.
x509_name issuer
The parsed issuer data (named information object).
x509_buf v3_ext
Optional X.509 v3 extensions.
asn1_named_data * extensions
int x509_crt_check_key_usage(const x509_crt *crt, int usage)
Check usage of certificate against keyUsage extension.
int x509write_crt_set_ns_cert_type(x509write_cert *ctx, unsigned char ns_cert_type)
Set the Netscape Cert Type flags (e.g.
char not_after[X509_RFC5280_UTC_TIME_LEN+1]
pk_context pk
Container for the public key context.
void x509_crt_init(x509_crt *crt)
Initialize a certificate (chain)
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....
int ext_types
Bit string containing detected and parsed extensions.
int x509_crt_parse_der(x509_crt *chain, const unsigned char *buf, size_t buflen)
Parse a single DER formatted certificate and add it to the chained list.
int x509_crt_parse_file(x509_crt *chain, const char *path)
Load one or more certificates and add them to the chained list.
int x509_crt_parse_path(x509_crt *chain, const char *path)
Load one or more certificate files from a path and add them to the chained list.
pk_type_t sig_pk
Internal representation of the Public Key algorithm of the signature algorithm, e....
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 typ...
void * sig_opts
Signature options to be passed to pk_verify_ext(), e.g.
void x509write_crt_set_version(x509write_cert *ctx, int version)
Set the verion for a Certificate Default: X509_CRT_VERSION_3.
x509_buf serial
Unique id for certificate issued by a specific CA.
int x509_crt_revoked(const x509_crt *crt, const x509_crl *crl)
Verify the certificate revocation status.
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...
unsigned char key_usage
Optional key usage extension value: See the values in x509.h.
int version
The X.509 version.
int x509write_crt_set_basic_constraints(x509write_cert *ctx, int is_ca, int max_pathlen)
Set the basicConstraints extension for a CRT.
x509_time valid_from
Start time of certificate validity.
void x509_crt_free(x509_crt *crt)
Unallocate all certificate data.
int x509write_crt_pem(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 PEM string.
unsigned char ns_cert_type
Optional Netscape certificate type extension value: See the values in x509.h.
x509_buf raw
The raw certificate data (DER).
void x509write_crt_set_subject_key(x509write_cert *ctx, pk_context *key)
Set the subject public key for the certificate.
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!...
int x509write_crt_set_serial(x509write_cert *ctx, const mpi *serial)
Set the serial number for a Certificate.
md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
int x509_crt_info(char *buf, size_t size, const char *prefix, const x509_crt *crt)
Returns an informational string about the certificate.
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_subject_key_identifier(x509write_cert *ctx)
Set the subjectKeyIdentifier extension for a CRT Requires that x509write_crt_set_subject_key() has be...
int x509write_crt_set_key_usage(x509write_cert *ctx, unsigned char key_usage)
Set the Key Usage Extension flags (e.g.
x509_buf subject_raw
The raw subject data (DER).
x509_buf tbs
The raw certificate body (DER).
x509_name subject
The parsed subject data (named information object).
int ca_istrue
Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise.
#define X509_RFC5280_UTC_TIME_LEN
void x509write_crt_free(x509write_cert *ctx)
Free the contents of a CRT write context.
x509_buf sig
Signature: hash of the tbs part signed with the private key.
int x509_crt_verify(x509_crt *crt, x509_crt *trust_ca, x509_crl *ca_crl, const char *cn, int *flags, int(*f_vrfy)(void *, x509_crt *, int, int *), void *p_vrfy)
Verify the certificate signature.
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.
int x509_crt_check_extended_key_usage(const x509_crt *crt, const char *usage_oid, size_t usage_len)
Check usage of certificate against extentedJeyUsage.
struct _x509write_cert x509write_cert
Container for writing a certificate (CRT)
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 b...
char not_before[X509_RFC5280_UTC_TIME_LEN+1]
x509_buf sig_oid2
Signature algorithm.
void x509write_crt_set_issuer_key(x509write_cert *ctx, pk_context *key)
Set the issuer key used for signing the certificate.
x509_sequence ext_key_usage
Optional list of extended key usage OIDs.
x509_buf issuer_id
Optional X.509 v2/v3 issuer unique identifier.
x509_buf issuer_raw
The raw issuer data (DER).
asn1_named_data * subject
struct _x509_crt x509_crt
Container for an X.509 certificate.
struct _x509_crt * next
Next certificate in the CA-chain.
x509_sequence subject_alt_names
Optional list of Subject Alternative Names (Only dNSName supported).
int x509_crt_parse(x509_crt *chain, const unsigned char *buf, size_t buflen)
Parse one or more certificates and add them to the chained list.
x509_buf sig_oid1
Signature algorithm, e.g.
pk_type_t
Public key types.
Type-length-value structure that allows for ASN1 using DER.
Container for a sequence or list of 'named' ASN.1 data items.
Container for a sequence of ASN.1 items.
Certificate revocation list structure.
Container for an X.509 certificate.
Container for date and time (precision in seconds).
Container for writing a certificate (CRT)
X.509 generic defines and structures.
X.509 certificate revocation list parsing.