Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

x509_crt.h File Reference

x509_crt.h File Reference

X.509 certificate parsing and writing. More...

Go to the source code of this file.

Data Structures

struct  _x509_crt
 Container for an X.509 certificate. More...
struct  _x509write_cert
 Container for writing a certificate (CRT) More...

Functions

void x509write_crt_init (x509write_cert *ctx)
 Initialize a CRT writing context.
void x509write_crt_set_version (x509write_cert *ctx, int version)
 Set the verion for a Certificate Default: X509_CRT_VERSION_3.
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_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_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.
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.
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 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.
void x509write_crt_free (x509write_cert *ctx)
 Free the contents of a CRT write context.
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 *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.

Structures and functions for parsing and writing X.509 certificates

typedef struct _x509_crt x509_crt
 Container for an X.509 certificate.
typedef struct _x509write_cert x509write_cert
 Container for writing a certificate (CRT)
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 (x509_crt *chain, const unsigned char *buf, size_t buflen)
 Parse one or more certificates and add them 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.
int x509_crt_info (char *buf, size_t size, const char *prefix, const x509_crt *crt)
 Returns an informational string about the certificate.
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.
int x509_crt_check_key_usage (const x509_crt *crt, int usage)
 Check usage of certificate against keyUsage extension.
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.
int x509_crt_revoked (const x509_crt *crt, const x509_crl *crl)
 Verify the certificate revocation status.
void x509_crt_init (x509_crt *crt)
 Initialize a certificate (chain)
void x509_crt_free (x509_crt *crt)
 Unallocate all certificate data.

Detailed Description

X.509 certificate parsing and writing.

Copyright (C) 2006-2013, Brainspark B.V.

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.

Definition in file x509_crt.h.


Function Documentation

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.

Parameters:
ctxcertificate to write away
bufbuffer to write to
sizesize of the buffer
f_rngRNG function (for signature, see note)
p_rngRNG parameter
Returns:
length of data written if successful, or a specific error code
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.

Definition at line 286 of file x509write_crt.c.

void x509write_crt_free ( x509write_cert ctx )

Free the contents of a CRT write context.

Parameters:
ctxCRT context to free

Definition at line 57 of file x509write_crt.c.

void x509write_crt_init ( x509write_cert ctx )

Initialize a CRT writing context.

Parameters:
ctxCRT context to initialize

Definition at line 49 of file x509write_crt.c.

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.

Parameters:
ctxcertificate to write away
bufbuffer to write to
sizesize of the buffer
f_rngRNG function (for signature, see note)
p_rngRNG parameter
Returns:
0 successful, or a specific error code
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.

Definition at line 422 of file x509write_crt.c.

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.

Parameters:
ctxCRT context to use
Returns:
0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED

Definition at line 189 of file x509write_crt.c.

int x509write_crt_set_basic_constraints ( x509write_cert ctx,
int  is_ca,
int  max_pathlen 
)

Set the basicConstraints extension for a CRT.

Parameters:
ctxCRT context to use
is_cais this a CA certificate
max_pathlenmaximum length of certificate chains below this certificate (only for CA certificates, -1 is inlimited)
Returns:
0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED

Definition at line 135 of file x509write_crt.c.

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.

Parameters:
ctxCRT context to use
oidOID of the extension
oid_lenlength of the OID
criticalif the extension is critical (per the RFC's definition)
valvalue of the extension OCTET STRING
val_lenlength of the value data
Returns:
0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED

Definition at line 126 of file x509write_crt.c.

void x509write_crt_set_issuer_key ( x509write_cert ctx,
pk_context key 
)

Set the issuer key used for signing the certificate.

Parameters:
ctxCRT context to use
keyprivate key to sign with

Definition at line 83 of file x509write_crt.c.

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"

Parameters:
ctxCRT context to use
issuer_nameissuer name to set
Returns:
0 if issuer name was parsed successfully, or a specific error code

Definition at line 94 of file x509write_crt.c.

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)

Parameters:
ctxCRT context to use
key_usagekey usage flags to set
Returns:
0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED

Definition at line 216 of file x509write_crt.c.

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)

Parameters:
ctxCRT context to use
md_algMD algorithm to use

Definition at line 73 of file x509write_crt.c.

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)

Parameters:
ctxCRT context to use
ns_cert_typeNetscape Cert Type flags to set
Returns:
0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED

Definition at line 236 of file x509write_crt.c.

int x509write_crt_set_serial ( x509write_cert ctx,
const mpi serial 
)

Set the serial number for a Certificate.

Parameters:
ctxCRT context to use
serialserial number to set
Returns:
0 if successful

Definition at line 100 of file x509write_crt.c.

void x509write_crt_set_subject_key ( x509write_cert ctx,
pk_context key 
)

Set the subject public key for the certificate.

Parameters:
ctxCRT context to use
keypublic key to include

Definition at line 78 of file x509write_crt.c.

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.

Parameters:
ctxCRT context to use
Returns:
0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED

Definition at line 167 of file x509write_crt.c.

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"

Parameters:
ctxCRT context to use
subject_namesubject name to set
Returns:
0 if subject name was parsed successfully, or a specific error code

Definition at line 88 of file x509write_crt.c.

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

Parameters:
ctxCRT context to use
not_beforenot_before timestamp
not_afternot_after timestamp
Returns:
0 if timestamp was parsed successfully, or a specific error code

Definition at line 110 of file x509write_crt.c.

void x509write_crt_set_version ( x509write_cert ctx,
int  version 
)

Set the verion for a Certificate Default: X509_CRT_VERSION_3.

Parameters:
ctxCRT context to use
versionversion to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or X509_CRT_VERSION_3)

Definition at line 68 of file x509write_crt.c.