#include "rsa.h"Go to the source code of this file.
Data Structures | |
| struct | _x509_buf |
| struct | _x509_name |
| struct | _x509_time |
| struct | _x509_cert |
Defines | |
| #define | ERR_ASN1_OUT_OF_DATA 0x0014 |
| #define | ERR_ASN1_UNEXPECTED_TAG 0x0016 |
| #define | ERR_ASN1_INVALID_LENGTH 0x0018 |
| #define | ERR_ASN1_LENGTH_MISMATCH 0x001A |
| #define | ERR_ASN1_INVALID_DATA 0x001C |
| #define | ERR_X509_FEATURE_UNAVAILABLE 0x0020 |
| #define | ERR_X509_CERT_INVALID_PEM 0x0040 |
| #define | ERR_X509_CERT_INVALID_FORMAT 0x0060 |
| #define | ERR_X509_CERT_INVALID_VERSION 0x0080 |
| #define | ERR_X509_CERT_INVALID_SERIAL 0x00A0 |
| #define | ERR_X509_CERT_INVALID_ALG 0x00C0 |
| #define | ERR_X509_CERT_INVALID_NAME 0x00E0 |
| #define | ERR_X509_CERT_INVALID_DATE 0x0100 |
| #define | ERR_X509_CERT_INVALID_PUBKEY 0x0120 |
| #define | ERR_X509_CERT_INVALID_SIGNATURE 0x0140 |
| #define | ERR_X509_CERT_INVALID_EXTENSIONS 0x0160 |
| #define | ERR_X509_CERT_UNKNOWN_VERSION 0x0180 |
| #define | ERR_X509_CERT_UNKNOWN_SIG_ALG 0x01A0 |
| #define | ERR_X509_CERT_UNKNOWN_PK_ALG 0x01C0 |
| #define | ERR_X509_CERT_SIG_MISMATCH 0x01E0 |
| #define | ERR_X509_KEY_INVALID_PEM 0x0200 |
| #define | ERR_X509_KEY_INVALID_VERSION 0x0220 |
| #define | ERR_X509_KEY_INVALID_FORMAT 0x0240 |
| #define | ERR_X509_KEY_INVALID_ENC_IV 0x0260 |
| #define | ERR_X509_KEY_UNKNOWN_ENC_ALG 0x0280 |
| #define | ERR_X509_KEY_PASSWORD_REQUIRED 0x02A0 |
| #define | ERR_X509_KEY_PASSWORD_MISMATCH 0x02C0 |
| #define | ERR_X509_SIG_VERIFY_FAILED 0x02E0 |
| #define | BADCERT_HAS_EXPIRED 1 |
| #define | BADCERT_CN_MISMATCH 2 |
| #define | BADCERT_NOT_TRUSTED 4 |
| #define | ASN1_BOOLEAN 0x01 |
| #define | ASN1_INTEGER 0x02 |
| #define | ASN1_BIT_STRING 0x03 |
| #define | ASN1_OCTET_STRING 0x04 |
| #define | ASN1_NULL 0x05 |
| #define | ASN1_OID 0x06 |
| #define | ASN1_UTF8_STRING 0x0C |
| #define | ASN1_SEQUENCE 0x10 |
| #define | ASN1_SET 0x11 |
| #define | ASN1_PRINTABLE_STRING 0x13 |
| #define | ASN1_T61_STRING 0x14 |
| #define | ASN1_IA5_STRING 0x16 |
| #define | ASN1_UTC_TIME 0x17 |
| #define | ASN1_UNIVERSAL_STRING 0x1C |
| #define | ASN1_BMP_STRING 0x1E |
| #define | ASN1_PRIMITIVE 0x00 |
| #define | ASN1_CONSTRUCTED 0x20 |
| #define | ASN1_CONTEXT_SPECIFIC 0x80 |
| #define | X520_COMMON_NAME 3 |
| #define | X520_COUNTRY 6 |
| #define | X520_LOCALITY 7 |
| #define | X520_STATE 8 |
| #define | X520_ORGANIZATION 10 |
| #define | X520_ORG_UNIT 11 |
| #define | PKCS9_EMAIL 1 |
| #define | OID_X520 "\x55\x04" |
| #define | OID_PKCS1 "\x2A\x86\x48\x86\xF7\x0D\x01\x01" |
| #define | OID_PKCS1_RSA "\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01" |
| #define | OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09" |
Typedefs | |
| typedef struct _x509_buf | x509_buf |
| typedef struct _x509_name | x509_name |
| typedef struct _x509_time | x509_time |
| typedef struct _x509_cert | x509_cert |
Functions | |
| int | x509_add_certs (x509_cert *chain, unsigned char *buf, int buflen) |
| Parse one or more certificates and add them to the chain. | |
| int | x509_read_crtfile (x509_cert *chain, char *path) |
| Load one or more certificates and add them to the chain. | |
| int | x509_parse_key (rsa_context *rsa, unsigned char *buf, int buflen, unsigned char *pwd, int pwdlen) |
| Parse a private RSA key. | |
| int | x509_read_keyfile (rsa_context *rsa, char *path, char *password) |
| Load and parse a private RSA key. | |
| int | x509_dn_gets (char *buf, char *end, x509_name *dn) |
| Store the certificate DN in printable form into buf; no more than (end - buf) characters will be written. | |
| char * | x509_cert_info (x509_cert *crt) |
| Return an informational string about the certificate, or NULL if memory allocation failed. | |
| int | x509_is_cert_expired (x509_cert *crt) |
| Return 0 if the certificate is still valid, or BADCERT_HAS_EXPIRED. | |
| int | x509_verify_cert (x509_cert *crt, x509_cert *trust_ca, char *cn, int *flags) |
| Verify the certificate signature. | |
| void | x509_free_cert (x509_cert *crt) |
| Unallocate all certificate data. | |
| int | x509_self_test (int verbose) |
| Checkup routine. | |
Definition in file x509.h.
| #define ASN1_BIT_STRING 0x03 |
| #define ASN1_BMP_STRING 0x1E |
| #define ASN1_BOOLEAN 0x01 |
| #define ASN1_CONSTRUCTED 0x20 |
Definition at line 69 of file x509.h.
Referenced by x509_add_certs(), x509_get_alg(), x509_get_dates(), x509_get_ext(), x509_get_name(), x509_get_pubkey(), x509_get_uid(), x509_get_version(), and x509_parse_key().
| #define ASN1_CONTEXT_SPECIFIC 0x80 |
Definition at line 70 of file x509.h.
Referenced by x509_get_ext(), x509_get_serial(), x509_get_uid(), and x509_get_version().
| #define ASN1_IA5_STRING 0x16 |
| #define ASN1_INTEGER 0x02 |
Definition at line 54 of file x509.h.
Referenced by asn1_get_int(), asn1_get_mpi(), and x509_get_serial().
| #define ASN1_NULL 0x05 |
| #define ASN1_OCTET_STRING 0x04 |
| #define ASN1_OID 0x06 |
| #define ASN1_PRIMITIVE 0x00 |
| #define ASN1_PRINTABLE_STRING 0x13 |
| #define ASN1_SEQUENCE 0x10 |
Definition at line 60 of file x509.h.
Referenced by x509_add_certs(), x509_get_alg(), x509_get_dates(), x509_get_ext(), x509_get_name(), x509_get_pubkey(), and x509_parse_key().
| #define ASN1_SET 0x11 |
| #define ASN1_T61_STRING 0x14 |
| #define ASN1_UNIVERSAL_STRING 0x1C |
| #define ASN1_UTC_TIME 0x17 |
| #define ASN1_UTF8_STRING 0x0C |
| #define BADCERT_CN_MISMATCH 2 |
| #define BADCERT_HAS_EXPIRED 1 |
| #define BADCERT_NOT_TRUSTED 4 |
| #define ERR_ASN1_INVALID_LENGTH 0x0018 |
Definition at line 18 of file x509.h.
Referenced by asn1_get_bool(), asn1_get_int(), and asn1_get_len().
| #define ERR_ASN1_LENGTH_MISMATCH 0x001A |
Definition at line 19 of file x509.h.
Referenced by x509_add_certs(), x509_get_alg(), x509_get_dates(), x509_get_ext(), x509_get_name(), x509_get_pubkey(), x509_get_version(), and x509_parse_key().
| #define ERR_ASN1_OUT_OF_DATA 0x0014 |
Definition at line 16 of file x509.h.
Referenced by asn1_get_len(), asn1_get_tag(), x509_get_name(), x509_get_pubkey(), and x509_get_serial().
| #define ERR_ASN1_UNEXPECTED_TAG 0x0016 |
Definition at line 17 of file x509.h.
Referenced by asn1_get_tag(), x509_get_ext(), x509_get_name(), x509_get_serial(), x509_get_uid(), and x509_get_version().
| #define ERR_X509_CERT_INVALID_ALG 0x00C0 |
| #define ERR_X509_CERT_INVALID_DATE 0x0100 |
| #define ERR_X509_CERT_INVALID_EXTENSIONS 0x0160 |
| #define ERR_X509_CERT_INVALID_FORMAT 0x0060 |
| #define ERR_X509_CERT_INVALID_NAME 0x00E0 |
| #define ERR_X509_CERT_INVALID_PEM 0x0040 |
| #define ERR_X509_CERT_INVALID_PUBKEY 0x0120 |
| #define ERR_X509_CERT_INVALID_SERIAL 0x00A0 |
| #define ERR_X509_CERT_INVALID_SIGNATURE 0x0140 |
| #define ERR_X509_CERT_INVALID_VERSION 0x0080 |
| #define ERR_X509_CERT_SIG_MISMATCH 0x01E0 |
| #define ERR_X509_CERT_UNKNOWN_PK_ALG 0x01C0 |
| #define ERR_X509_CERT_UNKNOWN_SIG_ALG 0x01A0 |
| #define ERR_X509_CERT_UNKNOWN_VERSION 0x0180 |
| #define ERR_X509_FEATURE_UNAVAILABLE 0x0020 |
| #define ERR_X509_KEY_INVALID_ENC_IV 0x0260 |
| #define ERR_X509_KEY_INVALID_FORMAT 0x0240 |
| #define ERR_X509_KEY_INVALID_PEM 0x0200 |
| #define ERR_X509_KEY_INVALID_VERSION 0x0220 |
| #define ERR_X509_KEY_PASSWORD_MISMATCH 0x02C0 |
| #define ERR_X509_KEY_PASSWORD_REQUIRED 0x02A0 |
| #define ERR_X509_KEY_UNKNOWN_ENC_ALG 0x0280 |
| #define ERR_X509_SIG_VERIFY_FAILED 0x02E0 |
| #define OID_PKCS1 "\x2A\x86\x48\x86\xF7\x0D\x01\x01" |
| #define OID_PKCS1_RSA "\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01" |
| #define OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09" |
| #define OID_X520 "\x55\x04" |
| #define PKCS9_EMAIL 1 |
| #define X520_COMMON_NAME 3 |
| #define X520_COUNTRY 6 |
| #define X520_LOCALITY 7 |
| #define X520_ORG_UNIT 11 |
| #define X520_ORGANIZATION 10 |
| #define X520_STATE 8 |
| typedef struct _x509_cert x509_cert |
| typedef struct _x509_name x509_name |
| typedef struct _x509_time x509_time |
Parse one or more certificates and add them to the chain.
| chain | points to the start of the chain | |
| buf | buffer holding the certificate data | |
| buflen | size of the buffer |
Definition at line 646 of file x509read.c.
References ASN1_CONSTRUCTED, asn1_get_tag(), ASN1_SEQUENCE, base64_decode(), _x509_cert::ca_istrue, rsa_context::E, ERR_ASN1_LENGTH_MISMATCH, ERR_BASE64_INVALID_CHARACTER, ERR_X509_CERT_INVALID_FORMAT, ERR_X509_CERT_INVALID_PEM, ERR_X509_CERT_SIG_MISMATCH, ERR_X509_CERT_UNKNOWN_SIG_ALG, ERR_X509_CERT_UNKNOWN_VERSION, _x509_cert::issuer, _x509_cert::issuer_id, _x509_cert::issuer_raw, rsa_context::len, _x509_buf::len, _x509_cert::max_pathlen, mpi_msb(), rsa_context::N, _x509_cert::next, OID_PKCS1, _x509_buf::p, _x509_cert::pk_oid, _x509_cert::raw, _x509_cert::rsa, rsa_check_pubkey(), _x509_cert::serial, _x509_cert::sig, _x509_cert::sig_oid1, _x509_cert::sig_oid2, _x509_cert::subject, _x509_cert::subject_id, _x509_cert::subject_raw, _x509_cert::tbs, _x509_cert::v3_ext, _x509_cert::valid_from, _x509_cert::valid_to, _x509_cert::version, x509_add_certs(), x509_free_cert(), x509_get_alg(), x509_get_dates(), x509_get_ext(), x509_get_name(), x509_get_pubkey(), x509_get_serial(), x509_get_sig(), x509_get_uid(), and x509_get_version().
Referenced by main(), x509_add_certs(), and x509_read_crtfile().
| char* x509_cert_info | ( | x509_cert * | crt | ) |
Return an informational string about the certificate, or NULL if memory allocation failed.
Definition at line 1391 of file x509read.c.
References _x509_time::day, _x509_time::hour, _x509_cert::issuer, _x509_buf::len, _x509_time::min, _x509_time::mon, mpi::n, rsa_context::N, _x509_buf::p, _x509_cert::rsa, RSA_MD2, RSA_MD4, RSA_MD5, RSA_SHA1, _x509_time::sec, _x509_cert::serial, _x509_cert::sig_oid1, _x509_cert::subject, _x509_cert::valid_from, _x509_cert::valid_to, _x509_cert::version, x509_dn_gets(), and _x509_time::year.
Store the certificate DN in printable form into buf; no more than (end - buf) characters will be written.
Definition at line 1308 of file x509read.c.
References _x509_buf::len, _x509_name::next, _x509_name::oid, OID_PKCS9, OID_X520, _x509_buf::p, PKCS9_EMAIL, _x509_name::val, X520_COMMON_NAME, X520_COUNTRY, X520_LOCALITY, X520_ORG_UNIT, X520_ORGANIZATION, and X520_STATE.
Referenced by x509_cert_info().
| void x509_free_cert | ( | x509_cert * | crt | ) |
Unallocate all certificate data.
Definition at line 1598 of file x509read.c.
References _x509_cert::issuer, _x509_cert::next, _x509_name::next, _x509_buf::p, _x509_cert::raw, _x509_cert::rsa, rsa_free(), and _x509_cert::subject.
Referenced by main(), ssl_free(), and x509_add_certs().
Return 0 if the certificate is still valid, or BADCERT_HAS_EXPIRED.
Definition at line 1452 of file x509read.c.
References BADCERT_HAS_EXPIRED, _x509_time::day, _x509_time::mon, _x509_cert::valid_to, and _x509_time::year.
Referenced by x509_verify_cert().
| int x509_parse_key | ( | rsa_context * | rsa, | |
| unsigned char * | buf, | |||
| int | buflen, | |||
| unsigned char * | pwd, | |||
| int | pwdlen | |||
| ) |
Parse a private RSA key.
| rsa | RSA context to be initialized | |
| buf | input buffer | |
| buflen | size of the buffer | |
| pwd | password for decryption (optional) | |
| pwdlen | size of the password |
Definition at line 1077 of file x509read.c.
References ASN1_CONSTRUCTED, asn1_get_int(), asn1_get_mpi(), asn1_get_tag(), ASN1_SEQUENCE, base64_decode(), rsa_context::D, rsa_context::DP, rsa_context::DQ, rsa_context::E, ERR_ASN1_LENGTH_MISMATCH, ERR_BASE64_INVALID_CHARACTER, ERR_X509_FEATURE_UNAVAILABLE, ERR_X509_KEY_INVALID_ENC_IV, ERR_X509_KEY_INVALID_FORMAT, ERR_X509_KEY_INVALID_PEM, ERR_X509_KEY_INVALID_VERSION, ERR_X509_KEY_PASSWORD_MISMATCH, ERR_X509_KEY_PASSWORD_REQUIRED, ERR_X509_KEY_UNKNOWN_ENC_ALG, rsa_context::len, mpi_msb(), rsa_context::N, rsa_context::P, rsa_context::Q, rsa_context::QP, rsa_check_privkey(), rsa_free(), rsa_context::ver, x509_des3_decrypt(), and x509_des3_getiv().
Referenced by main(), and x509_read_keyfile().
Load one or more certificates and add them to the chain.
| chain | points to the start of the chain | |
| path | filename to read the certificates from |
Definition at line 974 of file x509read.c.
References f, and x509_add_certs().
| int x509_read_keyfile | ( | rsa_context * | rsa, | |
| char * | path, | |||
| char * | password | |||
| ) |
Load and parse a private RSA key.
| rsa | RSA context to be initialized | |
| path | filename to read the private key from | |
| pwd | password to decrypt the file (can be NULL) |
Definition at line 1261 of file x509read.c.
References f, and x509_parse_key().
Checkup routine.
Definition at line 1726 of file x509read.c.
Referenced by main().
Verify the certificate signature.
| crt | a certificate to be verified | |
| trust_ca | the trusted CA chain | |
| cn | expected Common Name (can be set to NULL if the CN must not be verified) | |
| flags | result of the verification |
Definition at line 1497 of file x509read.c.
References BADCERT_CN_MISMATCH, BADCERT_NOT_TRUSTED, _x509_cert::ca_istrue, ERR_X509_SIG_VERIFY_FAILED, _x509_cert::issuer_raw, _x509_buf::len, _x509_cert::max_pathlen, _x509_cert::next, _x509_name::next, _x509_name::oid, _x509_buf::p, _x509_cert::rsa, rsa_pkcs1_verify(), _x509_cert::sig, _x509_cert::sig_oid1, _x509_cert::subject, _x509_cert::subject_raw, _x509_cert::tbs, _x509_name::val, _x509_cert::version, x509_hash(), and x509_is_cert_expired().
1.5.4