mbed TLS v1.3.14
|
The X.509 module provides X.509 support which includes: More...
Data Structures | |
struct | _x509_time |
Container for date and time (precision in seconds). More... | |
struct | _x509_crl_entry |
Certificate revocation list entry. More... | |
struct | _x509_crl |
Certificate revocation list structure. More... | |
struct | _x509_crt |
Container for an X.509 certificate. More... | |
struct | _x509write_cert |
Container for writing a certificate (CRT) More... | |
struct | _x509_csr |
Certificate Signing Request (CSR) structure. More... | |
struct | _x509write_csr |
Container for writing a CSR. More... | |
Macros | |
#define | POLARSSL_X509_MAX_INTERMEDIATE_CA 8 |
Maximum number of intermediate CAs in a verification chain. More... | |
Functions | |
int | dhm_parse_dhm (dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen) |
Parse DHM parameters. More... | |
int | dhm_parse_dhmfile (dhm_context *dhm, const char *path) |
Load and parse DHM parameters. More... | |
X509 Error codes | |
#define | POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080 |
Unavailable feature, e.g. More... | |
#define | POLARSSL_ERR_X509_UNKNOWN_OID -0x2100 |
Requested OID is unknown. More... | |
#define | POLARSSL_ERR_X509_INVALID_FORMAT -0x2180 |
The CRT/CRL/CSR format is invalid, e.g. More... | |
#define | POLARSSL_ERR_X509_INVALID_VERSION -0x2200 |
The CRT/CRL/CSR version element is invalid. More... | |
#define | POLARSSL_ERR_X509_INVALID_SERIAL -0x2280 |
The serial tag or value is invalid. More... | |
#define | POLARSSL_ERR_X509_INVALID_ALG -0x2300 |
The algorithm tag or value is invalid. More... | |
#define | POLARSSL_ERR_X509_INVALID_NAME -0x2380 |
The name tag or value is invalid. More... | |
#define | POLARSSL_ERR_X509_INVALID_DATE -0x2400 |
The date tag or value is invalid. More... | |
#define | POLARSSL_ERR_X509_INVALID_SIGNATURE -0x2480 |
The signature tag or value invalid. More... | |
#define | POLARSSL_ERR_X509_INVALID_EXTENSIONS -0x2500 |
The extension tag or value is invalid. More... | |
#define | POLARSSL_ERR_X509_UNKNOWN_VERSION -0x2580 |
CRT/CRL/CSR has an unsupported version number. More... | |
#define | POLARSSL_ERR_X509_UNKNOWN_SIG_ALG -0x2600 |
Signature algorithm (oid) is unsupported. More... | |
#define | POLARSSL_ERR_X509_SIG_MISMATCH -0x2680 |
Signature algorithms do not match. More... | |
#define | POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2700 |
Certificate verification failed, e.g. More... | |
#define | POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 |
Format not recognized as DER or PEM. More... | |
#define | POLARSSL_ERR_X509_BAD_INPUT_DATA -0x2800 |
Input invalid. More... | |
#define | POLARSSL_ERR_X509_MALLOC_FAILED -0x2880 |
Allocation of memory failed. More... | |
#define | POLARSSL_ERR_X509_FILE_IO_ERROR -0x2900 |
Read/write of file failed. More... | |
X509 Verify codes | |
#define | BADCERT_EXPIRED 0x01 |
The certificate validity has expired. More... | |
#define | BADCERT_REVOKED 0x02 |
The certificate has been revoked (is on a CRL). More... | |
#define | BADCERT_CN_MISMATCH 0x04 |
The certificate Common Name (CN) does not match with the expected CN. More... | |
#define | BADCERT_NOT_TRUSTED 0x08 |
The certificate is not correctly signed by the trusted CA. More... | |
#define | BADCRL_NOT_TRUSTED 0x10 |
The CRL is not correctly signed by the trusted CA. More... | |
#define | BADCRL_EXPIRED 0x20 |
The CRL is expired. More... | |
#define | BADCERT_MISSING 0x40 |
Certificate was missing. More... | |
#define | BADCERT_SKIP_VERIFY 0x80 |
Certificate verification was skipped. More... | |
#define | BADCERT_OTHER 0x0100 |
Other reason (can be used by verify callback) More... | |
#define | BADCERT_FUTURE 0x0200 |
The certificate validity starts in the future. More... | |
#define | BADCRL_FUTURE 0x0400 |
The CRL is from the future. More... | |
#define | BADCERT_KEY_USAGE 0x0800 |
Usage does not match the keyUsage extension. More... | |
#define | BADCERT_EXT_KEY_USAGE 0x1000 |
Usage does not match the extendedKeyUsage extension. More... | |
#define | BADCERT_NS_CERT_TYPE 0x2000 |
Usage does not match the nsCertType extension. More... | |
Structures for parsing X.509 certificates, CRLs and CSRs | |
typedef asn1_buf | x509_buf |
Type-length-value structure that allows for ASN1 using DER. More... | |
typedef asn1_bitstring | x509_bitstring |
Container for ASN1 bit strings. More... | |
typedef asn1_named_data | x509_name |
Container for ASN1 named information objects. More... | |
typedef asn1_sequence | x509_sequence |
Container for a sequence of ASN.1 items. More... | |
typedef struct _x509_time | x509_time |
Container for date and time (precision in seconds). More... | |
Structures and functions for parsing CRLs | |
typedef struct _x509_crl_entry | x509_crl_entry |
Certificate revocation list entry. More... | |
typedef struct _x509_crl | x509_crl |
Certificate revocation list structure. More... | |
int | x509_crl_parse_der (x509_crl *chain, const unsigned char *buf, size_t buflen) |
Parse a DER-encoded CRL and append it to the chained list. More... | |
int | x509_crl_parse (x509_crl *chain, const unsigned char *buf, size_t buflen) |
Parse one or more CRLs and append them to the chained list. More... | |
int | x509_crl_parse_file (x509_crl *chain, const char *path) |
Load one or more CRLs and append them to the chained list. More... | |
int | x509_crl_info (char *buf, size_t size, const char *prefix, const x509_crl *crl) |
Returns an informational string about the CRL. More... | |
void | x509_crl_init (x509_crl *crl) |
Initialize a CRL (chain) More... | |
void | x509_crl_free (x509_crl *crl) |
Unallocate all CRL data. More... | |
Structures and functions for parsing and writing X.509 certificates | |
typedef struct _x509_crt | x509_crt |
Container for an X.509 certificate. More... | |
typedef struct _x509write_cert | x509write_cert |
Container for writing a certificate (CRT) More... | |
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. More... | |
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. More... | |
int | x509_crt_parse_file (x509_crt *chain, const char *path) |
Load one or more certificates and add them to the chained list. More... | |
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. More... | |
int | x509_crt_info (char *buf, size_t size, const char *prefix, const x509_crt *crt) |
Returns an informational string about the certificate. More... | |
int | x509_crt_verify_info (char *buf, size_t size, const char *prefix, int flags) |
Returns an informational string about the verification status of a certificate. More... | |
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. More... | |
int | x509_crt_check_key_usage (const x509_crt *crt, int usage) |
Check usage of certificate against keyUsage extension. More... | |
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. More... | |
int | x509_crt_revoked (const x509_crt *crt, const x509_crl *crl) |
Verify the certificate revocation status. More... | |
void | x509_crt_init (x509_crt *crt) |
Initialize a certificate (chain) More... | |
void | x509_crt_free (x509_crt *crt) |
Unallocate all certificate data. More... | |
#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 |
Structures and functions for X.509 Certificate Signing Requests (CSR) | |
typedef struct _x509_csr | x509_csr |
Certificate Signing Request (CSR) structure. More... | |
typedef struct _x509write_csr | x509write_csr |
Container for writing a CSR. More... | |
int | x509_csr_parse_der (x509_csr *csr, const unsigned char *buf, size_t buflen) |
Load a Certificate Signing Request (CSR) in DER format. More... | |
int | x509_csr_parse (x509_csr *csr, const unsigned char *buf, size_t buflen) |
Load a Certificate Signing Request (CSR), DER or PEM format. More... | |
int | x509_csr_parse_file (x509_csr *csr, const char *path) |
Load a Certificate Signing Request (CSR) More... | |
int | x509_csr_info (char *buf, size_t size, const char *prefix, const x509_csr *csr) |
Returns an informational string about the CSR. More... | |
void | x509_csr_init (x509_csr *csr) |
Initialize a CSR. More... | |
void | x509_csr_free (x509_csr *csr) |
Unallocate all CSR data. More... | |
The X.509 module provides X.509 support which includes:
x509parse_crt()
and x509parse_crtfile()
).x509parse_crl()
andx509parse_crlfile()
).x509parse_key()
and x509parse_keyfile()
).x509parse_verify()
)x509write_crt_der()
and x509write_csr_der()
).This module can be used to build a certificate authority (CA) chain and verify its signature. It is also used to generate Certificate Signing Requests and X509 certificates just as a CA would do.
#define BADCERT_CN_MISMATCH 0x04 |
#define BADCERT_EXPIRED 0x01 |
#define BADCERT_EXT_KEY_USAGE 0x1000 |
#define BADCERT_FUTURE 0x0200 |
#define BADCERT_KEY_USAGE 0x0800 |
#define BADCERT_NOT_TRUSTED 0x08 |
#define BADCERT_NS_CERT_TYPE 0x2000 |
#define BADCERT_OTHER 0x0100 |
#define BADCERT_REVOKED 0x02 |
#define BADCERT_SKIP_VERIFY 0x80 |
#define BADCRL_NOT_TRUSTED 0x10 |
#define POLARSSL_ERR_X509_BAD_INPUT_DATA -0x2800 |
#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 |
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2700 |
#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080 |
#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2900 |
#define POLARSSL_ERR_X509_INVALID_ALG -0x2300 |
#define POLARSSL_ERR_X509_INVALID_DATE -0x2400 |
#define POLARSSL_ERR_X509_INVALID_EXTENSIONS -0x2500 |
#define POLARSSL_ERR_X509_INVALID_FORMAT -0x2180 |
#define POLARSSL_ERR_X509_INVALID_NAME -0x2380 |
#define POLARSSL_ERR_X509_INVALID_SERIAL -0x2280 |
#define POLARSSL_ERR_X509_INVALID_SIGNATURE -0x2480 |
#define POLARSSL_ERR_X509_INVALID_VERSION -0x2200 |
#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2880 |
#define POLARSSL_ERR_X509_SIG_MISMATCH -0x2680 |
#define POLARSSL_ERR_X509_UNKNOWN_OID -0x2100 |
#define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG -0x2600 |
#define POLARSSL_ERR_X509_UNKNOWN_VERSION -0x2580 |
#define POLARSSL_X509_MAX_INTERMEDIATE_CA 8 |
Maximum number of intermediate CAs in a verification chain.
That is, maximum length of the chain, excluding the end-entity certificate and the trusted root certificate.
Set this to a low value to prevent an adversary from making you waste resources verifying an overlong certificate chain.
#define X509_CRT_VERSION_1 0 |
Definition at line 98 of file x509_crt.h.
#define X509_CRT_VERSION_2 1 |
Definition at line 99 of file x509_crt.h.
#define X509_CRT_VERSION_3 2 |
Definition at line 100 of file x509_crt.h.
#define X509_RFC5280_MAX_SERIAL_LEN 32 |
Definition at line 102 of file x509_crt.h.
#define X509_RFC5280_UTC_TIME_LEN 15 |
Definition at line 103 of file x509_crt.h.
typedef asn1_bitstring x509_bitstring |
Certificate revocation list structure.
Every CRL may have multiple entries.
typedef struct _x509_crl_entry x509_crl_entry |
Certificate revocation list entry.
Contains the CA-specific serial numbers and revocation dates.
Container for an X.509 certificate.
The certificate may be chained.
typedef asn1_named_data x509_name |
typedef asn1_sequence x509_sequence |
typedef struct _x509_time x509_time |
Container for date and time (precision in seconds).
typedef struct _x509write_cert x509write_cert |
Container for writing a certificate (CRT)
typedef struct _x509write_csr x509write_csr |
Container for writing a CSR.
int dhm_parse_dhm | ( | dhm_context * | dhm, |
const unsigned char * | dhmin, | ||
size_t | dhminlen | ||
) |
Parse DHM parameters.
dhm | DHM context to be initialized |
dhmin | input buffer |
dhminlen | size of the buffer |
int dhm_parse_dhmfile | ( | dhm_context * | dhm, |
const char * | path | ||
) |
Load and parse DHM parameters.
dhm | DHM context to be initialized |
path | filename to read the DHM Parameters from |
void x509_crl_free | ( | x509_crl * | crl | ) |
Unallocate all CRL data.
crl | CRL chain to free |
int x509_crl_info | ( | char * | buf, |
size_t | size, | ||
const char * | prefix, | ||
const x509_crl * | crl | ||
) |
Returns an informational string about the CRL.
buf | Buffer to write to |
size | Maximum size of buffer |
prefix | A line prefix |
crl | The X509 CRL to represent |
Referenced by x509parse_crl_info().
void x509_crl_init | ( | x509_crl * | crl | ) |
Initialize a CRL (chain)
crl | CRL chain to initialize |
int x509_crl_parse | ( | x509_crl * | chain, |
const unsigned char * | buf, | ||
size_t | buflen | ||
) |
Parse one or more CRLs and append them to the chained list.
chain | points to the start of the chain |
buf | buffer holding the CRL data in PEM or DER format |
buflen | size of the buffer |
Referenced by x509parse_crl().
int x509_crl_parse_der | ( | x509_crl * | chain, |
const unsigned char * | buf, | ||
size_t | buflen | ||
) |
Parse a DER-encoded CRL and append it to the chained list.
chain | points to the start of the chain |
buf | buffer holding the CRL data in DER format |
buflen | size of the buffer |
int x509_crl_parse_file | ( | x509_crl * | chain, |
const char * | path | ||
) |
Load one or more CRLs and append them to the chained list.
chain | points to the start of the chain |
path | filename to read the CRLs from (in PEM or DER encoding) |
Referenced by x509parse_crlfile().
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.
crt | Leaf certificate used. |
usage_oid | Intended usage (eg OID_SERVER_AUTH or OID_CLIENT_AUTH). |
usage_len | Length of usage_oid (eg given by OID_SIZE()). |
int x509_crt_check_key_usage | ( | const x509_crt * | crt, |
int | usage | ||
) |
Check usage of certificate against keyUsage extension.
crt | Leaf certificate used. |
usage | Intended usage(s) (eg KU_KEY_ENCIPHERMENT before using the certificate to perform an RSA key exchange). |
x509_crt_verify()
. void x509_crt_free | ( | x509_crt * | crt | ) |
int x509_crt_info | ( | char * | buf, |
size_t | size, | ||
const char * | prefix, | ||
const x509_crt * | crt | ||
) |
Returns an informational string about the certificate.
buf | Buffer to write to |
size | Maximum size of buffer |
prefix | A line prefix |
crt | The X509 certificate to represent |
Referenced by x509parse_cert_info().
void x509_crt_init | ( | x509_crt * | crt | ) |
Initialize a certificate (chain)
crt | Certificate chain to initialize |
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.
Parses permissively. If some certificates can be parsed, the result is the number of failed certificates it encountered. If none complete correctly, the first error is returned.
chain | points to the start of the chain |
buf | buffer holding the certificate data |
buflen | size of the buffer |
Referenced by x509parse_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.
chain | points to the start of the chain |
buf | buffer holding the certificate DER data |
buflen | size of the buffer |
Referenced by x509parse_crt_der().
int x509_crt_parse_file | ( | x509_crt * | chain, |
const char * | path | ||
) |
Load one or more certificates and add them to the chained list.
Parses permissively. If some certificates can be parsed, the result is the number of failed certificates it encountered. If none complete correctly, the first error is returned.
chain | points to the start of the chain |
path | filename to read the certificates from |
Referenced by x509parse_crtfile().
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.
Parses permissively. If some certificates can be parsed, the result is the number of failed certificates it encountered. If none complete correctly, the first error is returned.
chain | points to the start of the chain |
path | directory / folder to read the certificate files from |
Referenced by x509parse_crtpath().
Verify the certificate revocation status.
crt | a certificate to be verified |
crl | the CRL to verify against |
Referenced by x509parse_revoked().
int x509_crt_verify | ( | x509_crt * | crt, |
x509_crt * | trust_ca, | ||
x509_crl * | ca_crl, | ||
const char * | cn, | ||
int * | flags, | ||
int(*)(void *, x509_crt *, int, int *) | f_vrfy, | ||
void * | p_vrfy | ||
) |
Verify the certificate signature.
The verify callback is a user-supplied callback that can clear / modify / add flags for a certificate. If set, the verification callback is called for each certificate in the chain (from the trust-ca down to the presented crt). The parameters for the callback are: (void *parameter, x509_crt *crt, int certificate_depth, int *flags). With the flags representing current flags for that specific certificate and the certificate depth from the bottom (Peer cert depth = 0).
All flags left after returning from the callback are also returned to the application. The function should return 0 for anything but a fatal error.
x509_crt_verify_info()
crt | a certificate to be verified |
trust_ca | the trusted CA chain |
ca_crl | the CRL chain for trusted CA's |
cn | expected Common Name (can be set to NULL if the CN must not be verified) |
flags | result of the verification |
f_vrfy | verification function |
p_vrfy | verification parameter |
Referenced by x509parse_verify().
int x509_crt_verify_info | ( | char * | buf, |
size_t | size, | ||
const char * | prefix, | ||
int | flags | ||
) |
Returns an informational string about the verification status of a certificate.
buf | Buffer to write to |
size | Maximum size of buffer |
prefix | A line prefix |
flags | Verification flags created by x509_crt_verify() |
void x509_csr_free | ( | x509_csr * | csr | ) |
Unallocate all CSR data.
csr | CSR to free |
int x509_csr_info | ( | char * | buf, |
size_t | size, | ||
const char * | prefix, | ||
const x509_csr * | csr | ||
) |
Returns an informational string about the CSR.
buf | Buffer to write to |
size | Maximum size of buffer |
prefix | A line prefix |
csr | The X509 CSR to represent |
Referenced by x509parse_csr_info().
void x509_csr_init | ( | x509_csr * | csr | ) |
Initialize a CSR.
csr | CSR to initialize |
int x509_csr_parse | ( | x509_csr * | csr, |
const unsigned char * | buf, | ||
size_t | buflen | ||
) |
Load a Certificate Signing Request (CSR), DER or PEM format.
csr | CSR context to fill |
buf | buffer holding the CRL data |
buflen | size of the buffer |
Referenced by x509parse_csr().
int x509_csr_parse_der | ( | x509_csr * | csr, |
const unsigned char * | buf, | ||
size_t | buflen | ||
) |
Load a Certificate Signing Request (CSR) in DER format.
csr | CSR context to fill |
buf | buffer holding the CRL data |
buflen | size of the buffer |
int x509_csr_parse_file | ( | x509_csr * | csr, |
const char * | path | ||
) |
Load a Certificate Signing Request (CSR)
csr | CSR context to fill |
path | filename to read the CSR from |
Referenced by x509parse_csrfile().