The X.509 module provides X.509 support which includes:
More...
Functions to read in DHM parameters, a certificate, CRL or private RSA key |
int | x509parse_crt (x509_cert *chain, const unsigned char *buf, size_t buflen) |
| Parse one or more certificates and add them to the chained list.
|
int | x509parse_crtfile (x509_cert *chain, const char *path) |
| Load one or more certificates and add them to the chained list.
|
int | x509parse_crtpath (x509_cert *chain, const char *path) |
| Load one or more certificate files from a path and add them to the chained list.
|
int | x509parse_crl (x509_crl *chain, const unsigned char *buf, size_t buflen) |
| Parse one or more CRLs and add them to the chained list.
|
int | x509parse_crlfile (x509_crl *chain, const char *path) |
| Load one or more CRLs and add them to the chained list.
|
int | x509parse_key (rsa_context *rsa, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen) |
| Parse a private RSA key.
|
int | x509parse_keyfile (rsa_context *rsa, const char *path, const char *password) |
| Load and parse a private RSA key.
|
int | x509parse_public_key (rsa_context *rsa, const unsigned char *key, size_t keylen) |
| Parse a public RSA key.
|
int | x509parse_public_keyfile (rsa_context *rsa, const char *path) |
| Load and parse a public RSA key.
|
int | x509parse_dhm (dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen) |
| Parse DHM parameters.
|
int | x509parse_dhmfile (dhm_context *dhm, const char *path) |
| Load and parse DHM parameters.
|
Functions to verify a certificate |
int | x509parse_verify (x509_cert *crt, x509_cert *trust_ca, x509_crl *ca_crl, const char *cn, int *flags, int(*f_vrfy)(void *, x509_cert *, int, int *), void *p_vrfy) |
| Verify the certificate signature.
|
int | x509parse_revoked (const x509_cert *crt, const x509_crl *crl) |
| Verify the certificate signature.
|
Detailed Description
The X.509 module provides X.509 support which includes:
This module can be used to build a certificate authority (CA) chain and verify its signature. It is also used to get a (RSA) private key for signing and decryption.
Macro Definition Documentation
#define BADCERT_CN_MISMATCH 0x04 |
The certificate Common Name (CN) does not match with the expected CN.
Definition at line 74 of file x509.h.
#define BADCERT_EXPIRED 0x01 |
The certificate validity has expired.
Definition at line 72 of file x509.h.
#define BADCERT_MISSING 0x40 |
Certificate was missing.
Definition at line 78 of file x509.h.
#define BADCERT_NOT_TRUSTED 0x08 |
The certificate is not correctly signed by the trusted CA.
Definition at line 75 of file x509.h.
#define BADCERT_OTHER 0x0100 |
Other reason (can be used by verify callback)
Definition at line 80 of file x509.h.
#define BADCERT_REVOKED 0x02 |
The certificate has been revoked (is on a CRL).
Definition at line 73 of file x509.h.
#define BADCERT_SKIP_VERIFY 0x80 |
Certificate verification was skipped.
Definition at line 79 of file x509.h.
#define BADCRL_EXPIRED 0x20 |
CRL is expired.
Definition at line 77 of file x509.h.
#define BADCRL_NOT_TRUSTED 0x10 |
CRL is not correctly signed by the trusted CA.
Definition at line 76 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x2300 |
The algorithm tag or value is invalid.
Definition at line 48 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x2400 |
The date tag or value is invalid.
Definition at line 50 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x2580 |
The extension tag or value is invalid.
Definition at line 53 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_FORMAT -0x2180 |
The certificate format is invalid, e.g.
different type expected.
Definition at line 45 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x2380 |
The name tag or value is invalid.
Definition at line 49 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_PEM -0x2100 |
The PEM-encoded certificate contains invalid elements, e.g.
invalid character.
Definition at line 44 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x2480 |
The pubkey tag or value is invalid (only RSA is supported).
Definition at line 51 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_SERIAL -0x2280 |
The serial tag or value is invalid.
Definition at line 47 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x2500 |
The signature tag or value invalid.
Definition at line 52 of file x509.h.
#define POLARSSL_ERR_X509_CERT_INVALID_VERSION -0x2200 |
The certificate version element is invalid.
Definition at line 46 of file x509.h.
#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x2780 |
Certificate signature algorithms do not match.
(see x509_cert
sig_oid)
Definition at line 57 of file x509.h.
#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2980 |
Format not recognized as DER or PEM.
Definition at line 61 of file x509.h.
#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x2680 |
Signature algorithm (oid) is unsupported.
Definition at line 55 of file x509.h.
#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x2600 |
Certificate or CRL has an unsupported version number.
Definition at line 54 of file x509.h.
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2800 |
Certificate verification failed, e.g.
CRL, CA or signature check failed.
Definition at line 58 of file x509.h.
#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080 |
Unavailable feature, e.g.
RSA hashing/encryption combination.
Definition at line 43 of file x509.h.
#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2B00 |
Read/write of file failed.
Definition at line 64 of file x509.h.
#define POLARSSL_ERR_X509_INVALID_INPUT -0x2A00 |
Input invalid.
Definition at line 62 of file x509.h.
#define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x2900 |
Invalid RSA key tag or value.
Definition at line 60 of file x509.h.
#define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x2880 |
Unsupported RSA key version.
Definition at line 59 of file x509.h.
#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2A80 |
Allocation of memory failed.
Definition at line 63 of file x509.h.
#define POLARSSL_ERR_X509_UNKNOWN_PK_ALG -0x2700 |
Key algorithm is unsupported (only RSA is supported).
Definition at line 56 of file x509.h.
Typedef Documentation
Container for ASN1 bit strings.
Definition at line 256 of file x509.h.
Type-length-value structure that allows for ASN1 using DER.
Definition at line 251 of file x509.h.
Container for an X.509 certificate.
The certificate may be chained.
Certificate revocation list structure.
Every CRL may have multiple entries.
Certificate revocation list entry.
Contains the CA-specific serial numbers and revocation dates.
Container for ASN1 named information objects.
It allows for Relative Distinguished Names (e.g. cn=polarssl,ou=code,etc.).
Container for a sequence of ASN.1 items.
Definition at line 273 of file x509.h.
Container for date and time (precision in seconds).
Function Documentation
Unallocate all CRL data.
- Parameters:
-
Unallocate all certificate data.
- Parameters:
-
crt | Certificate chain to free |
int x509parse_crl |
( |
x509_crl * |
chain, |
|
|
const unsigned char * |
buf, |
|
|
size_t |
buflen |
|
) |
| |
Parse one or more CRLs and add them to the chained list.
- Parameters:
-
chain | points to the start of the chain |
buf | buffer holding the CRL data |
buflen | size of the buffer |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_crlfile |
( |
x509_crl * |
chain, |
|
|
const char * |
path |
|
) |
| |
Load one or more CRLs and add them to the chained list.
- Parameters:
-
chain | points to the start of the chain |
path | filename to read the CRLs from |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_crt |
( |
x509_cert * |
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.
- Parameters:
-
chain | points to the start of the chain |
buf | buffer holding the certificate data |
buflen | size of the buffer |
- Returns:
- 0 if all certificates parsed successfully, a positive number if partly successful or a specific X509 or PEM error code
int x509parse_crtfile |
( |
x509_cert * |
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.
- Parameters:
-
chain | points to the start of the chain |
path | filename to read the certificates from |
- Returns:
- 0 if all certificates parsed successfully, a positive number if partly successful or a specific X509 or PEM error code
int x509parse_crtpath |
( |
x509_cert * |
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.
- Parameters:
-
chain | points to the start of the chain |
path | directory / folder to read the certificate files from |
- Returns:
- 0 if all certificates parsed successfully, a positive number if partly successful or a specific X509 or PEM error code
int x509parse_dhm |
( |
dhm_context * |
dhm, |
|
|
const unsigned char * |
dhmin, |
|
|
size_t |
dhminlen |
|
) |
| |
Parse DHM parameters.
- Parameters:
-
dhm | DHM context to be initialized |
dhmin | input buffer |
dhminlen | size of the buffer |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_dhmfile |
( |
dhm_context * |
dhm, |
|
|
const char * |
path |
|
) |
| |
Load and parse DHM parameters.
- Parameters:
-
dhm | DHM context to be initialized |
path | filename to read the DHM Parameters from |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_key |
( |
rsa_context * |
rsa, |
|
|
const unsigned char * |
key, |
|
|
size_t |
keylen, |
|
|
const unsigned char * |
pwd, |
|
|
size_t |
pwdlen |
|
) |
| |
Parse a private RSA key.
- Parameters:
-
rsa | RSA context to be initialized |
key | input buffer |
keylen | size of the buffer |
pwd | password for decryption (optional) |
pwdlen | size of the password |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_keyfile |
( |
rsa_context * |
rsa, |
|
|
const char * |
path, |
|
|
const char * |
password |
|
) |
| |
Load and parse a private RSA key.
- Parameters:
-
rsa | RSA context to be initialized |
path | filename to read the private key from |
password | password to decrypt the file (can be NULL) |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_public_key |
( |
rsa_context * |
rsa, |
|
|
const unsigned char * |
key, |
|
|
size_t |
keylen |
|
) |
| |
Parse a public RSA key.
- Parameters:
-
rsa | RSA context to be initialized |
key | input buffer |
keylen | size of the buffer |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
int x509parse_public_keyfile |
( |
rsa_context * |
rsa, |
|
|
const char * |
path |
|
) |
| |
Load and parse a public RSA key.
- Parameters:
-
rsa | RSA context to be initialized |
path | filename to read the private key from |
- Returns:
- 0 if successful, or a specific X509 or PEM error code
Verify the certificate signature.
- Parameters:
-
crt | a certificate to be verified |
crl | the CRL to verify against |
- Returns:
- 1 if the certificate is revoked, 0 otherwise
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_cert *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.
- Parameters:
-
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 |
- Returns:
- 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED, in which case *flags will have one or more of the following values set: BADCERT_EXPIRED – BADCERT_REVOKED – BADCERT_CN_MISMATCH – BADCERT_NOT_TRUSTED or another error in case of a fatal error encountered during the verification process.