#include "xyssl/config.h"#include "xyssl/x509.h"#include "xyssl/base64.h"#include "xyssl/des.h"#include "xyssl/md2.h"#include "xyssl/md4.h"#include "xyssl/md5.h"#include "xyssl/sha1.h"#include <string.h>#include <stdlib.h>#include <stdio.h>#include <time.h>#include "xyssl/certs.h"Go to the source code of this file.
| Functions | |
| static int | asn1_get_len (unsigned char **p, unsigned char *end, int *len) | 
| static int | asn1_get_tag (unsigned char **p, unsigned char *end, int *len, int tag) | 
| static int | asn1_get_bool (unsigned char **p, unsigned char *end, int *val) | 
| static int | asn1_get_int (unsigned char **p, unsigned char *end, int *val) | 
| static int | asn1_get_mpi (unsigned char **p, unsigned char *end, mpi *X) | 
| static int | x509_get_version (unsigned char **p, unsigned char *end, int *ver) | 
| static int | x509_get_serial (unsigned char **p, unsigned char *end, x509_buf *serial) | 
| static int | x509_get_alg (unsigned char **p, unsigned char *end, x509_buf *alg) | 
| static int | x509_get_name (unsigned char **p, unsigned char *end, x509_name *cur) | 
| static int | x509_get_dates (unsigned char **p, unsigned char *end, x509_time *from, x509_time *to) | 
| static int | x509_get_pubkey (unsigned char **p, unsigned char *end, x509_buf *pk_alg_oid, mpi *N, mpi *E) | 
| static int | x509_get_sig (unsigned char **p, unsigned char *end, x509_buf *sig) | 
| static int | x509_get_uid (unsigned char **p, unsigned char *end, x509_buf *uid, int n) | 
| static int | x509_get_ext (unsigned char **p, unsigned char *end, x509_buf *ext, int *ca_istrue, int *max_pathlen) | 
| int | x509parse_crt (x509_cert *chain, unsigned char *buf, int buflen) | 
| Parse one or more certificates and add them to the chained list. | |
| int | x509parse_crtfile (x509_cert *chain, char *path) | 
| Load one or more certificates and add them to the chained list. | |
| static int | x509_get_iv (unsigned char *s, unsigned char iv[8]) | 
| static void | x509_des3_decrypt (unsigned char des3_iv[8], unsigned char *buf, int buflen, unsigned char *pwd, int pwdlen) | 
| int | x509parse_key (rsa_context *rsa, unsigned char *buf, int buflen, unsigned char *pwd, int pwdlen) | 
| Parse a private RSA key. | |
| int | x509parse_keyfile (rsa_context *rsa, char *path, char *pwd) | 
| Load and parse a private RSA key. | |
| int | x509parse_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 * | x509parse_cert_info (char *prefix, x509_cert *crt) | 
| Returns an informational string about the certificate. | |
| int | x509parse_expired (x509_cert *crt) | 
| Return 0 if the certificate is still valid, or BADCERT_EXPIRED. | |
| static void | x509_hash (unsigned char *in, int len, int alg, unsigned char *out) | 
| int | x509parse_verify (x509_cert *crt, x509_cert *trust_ca, char *cn, int *flags) | 
| Verify the certificate signature. | |
| void | x509_free (x509_cert *crt) | 
| Unallocate all certificate data. | |
| int | x509_self_test (int verbose) | 
| Checkup routine. | |
Definition at line 108 of file x509parse.c.
References ASN1_BOOLEAN, asn1_get_tag(), and XYSSL_ERR_ASN1_INVALID_LENGTH.
Referenced by x509_get_ext().
Definition at line 126 of file x509parse.c.
References asn1_get_tag(), ASN1_INTEGER, and XYSSL_ERR_ASN1_INVALID_LENGTH.
Referenced by x509_get_ext(), x509_get_version(), and x509parse_key().
Definition at line 52 of file x509parse.c.
References XYSSL_ERR_ASN1_INVALID_LENGTH, and XYSSL_ERR_ASN1_OUT_OF_DATA.
Referenced by asn1_get_tag(), x509_get_name(), and x509_get_serial().
Definition at line 149 of file x509parse.c.
References asn1_get_tag(), ASN1_INTEGER, and mpi_read_binary().
Referenced by x509_get_pubkey(), and x509parse_key().
Definition at line 93 of file x509parse.c.
References asn1_get_len(), XYSSL_ERR_ASN1_OUT_OF_DATA, and XYSSL_ERR_ASN1_UNEXPECTED_TAG.
Referenced by asn1_get_bool(), asn1_get_int(), asn1_get_mpi(), x509_get_alg(), x509_get_dates(), x509_get_ext(), x509_get_name(), x509_get_pubkey(), x509_get_sig(), x509_get_uid(), x509_get_version(), x509parse_crt(), and x509parse_key().
| static void x509_des3_decrypt | ( | unsigned char | des3_iv[8], | |
| unsigned char * | buf, | |||
| int | buflen, | |||
| unsigned char * | pwd, | |||
| int | pwdlen | |||
| ) |  [static] | 
Definition at line 1042 of file x509parse.c.
References des3_crypt_cbc(), des3_set3key_dec(), DES_DECRYPT, md5_finish(), md5_starts(), and md5_update().
Referenced by x509parse_key().
| void x509_free | ( | x509_cert * | crt | ) | 
Unallocate all certificate data.
Definition at line 1613 of file x509parse.c.
References _x509_cert::issuer, _x509_buf::len, _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(), ssl_test(), x509_self_test(), and x509parse_crt().
Definition at line 229 of file x509parse.c.
References ASN1_CONSTRUCTED, asn1_get_tag(), ASN1_NULL, ASN1_OID, ASN1_SEQUENCE, _x509_buf::len, _x509_buf::p, _x509_buf::tag, XYSSL_ERR_ASN1_LENGTH_MISMATCH, and XYSSL_ERR_X509_CERT_INVALID_ALG.
Referenced by x509_get_pubkey(), and x509parse_crt().
| static int x509_get_dates | ( | unsigned char ** | p, | |
| unsigned char * | end, | |||
| x509_time * | from, | |||
| x509_time * | to | |||
| ) |  [static] | 
Definition at line 358 of file x509parse.c.
References ASN1_CONSTRUCTED, asn1_get_tag(), ASN1_SEQUENCE, ASN1_UTC_TIME, _x509_time::day, _x509_time::hour, _x509_time::min, _x509_time::mon, _x509_time::sec, XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_X509_CERT_INVALID_DATE, and _x509_time::year.
Referenced by x509parse_crt().
| static int x509_get_ext | ( | unsigned char ** | p, | |
| unsigned char * | end, | |||
| x509_buf * | ext, | |||
| int * | ca_istrue, | |||
| int * | max_pathlen | |||
| ) |  [static] | 
Definition at line 530 of file x509parse.c.
References ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, asn1_get_bool(), asn1_get_int(), asn1_get_tag(), ASN1_OCTET_STRING, ASN1_SEQUENCE, _x509_buf::len, _x509_buf::p, _x509_buf::tag, XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_ASN1_UNEXPECTED_TAG, and XYSSL_ERR_X509_CERT_INVALID_EXTENSIONS.
Referenced by x509parse_crt().
| static int x509_get_iv | ( | unsigned char * | s, | |
| unsigned char | iv[8] | |||
| ) |  [static] | 
Definition at line 1018 of file x509parse.c.
References XYSSL_ERR_X509_KEY_INVALID_ENC_IV.
Referenced by x509parse_key().
Definition at line 276 of file x509parse.c.
References ASN1_BMP_STRING, ASN1_CONSTRUCTED, asn1_get_len(), asn1_get_tag(), ASN1_IA5_STRING, ASN1_OID, ASN1_PRINTABLE_STRING, ASN1_SEQUENCE, ASN1_SET, ASN1_T61_STRING, ASN1_UNIVERSAL_STRING, ASN1_UTF8_STRING, _x509_buf::len, _x509_name::next, _x509_name::oid, _x509_buf::p, _x509_buf::tag, _x509_name::val, XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_ASN1_OUT_OF_DATA, XYSSL_ERR_ASN1_UNEXPECTED_TAG, and XYSSL_ERR_X509_CERT_INVALID_NAME.
Referenced by x509parse_crt().
| static int x509_get_pubkey | ( | unsigned char ** | p, | |
| unsigned char * | end, | |||
| x509_buf * | pk_alg_oid, | |||
| mpi * | N, | |||
| mpi * | E | |||
| ) |  [static] | 
Definition at line 421 of file x509parse.c.
References ASN1_BIT_STRING, ASN1_CONSTRUCTED, asn1_get_mpi(), asn1_get_tag(), ASN1_SEQUENCE, _x509_buf::len, OID_PKCS1_RSA, _x509_buf::p, x509_get_alg(), XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_ASN1_OUT_OF_DATA, XYSSL_ERR_X509_CERT_INVALID_PUBKEY, and XYSSL_ERR_X509_CERT_UNKNOWN_PK_ALG.
Referenced by x509parse_crt().
Definition at line 198 of file x509parse.c.
References ASN1_CONTEXT_SPECIFIC, asn1_get_len(), ASN1_INTEGER, ASN1_PRIMITIVE, _x509_buf::len, _x509_buf::p, _x509_buf::tag, XYSSL_ERR_ASN1_OUT_OF_DATA, XYSSL_ERR_ASN1_UNEXPECTED_TAG, and XYSSL_ERR_X509_CERT_INVALID_SERIAL.
Referenced by x509parse_crt().
Definition at line 476 of file x509parse.c.
References ASN1_BIT_STRING, asn1_get_tag(), _x509_buf::len, _x509_buf::p, _x509_buf::tag, and XYSSL_ERR_X509_CERT_INVALID_SIGNATURE.
Referenced by x509parse_crt().
Definition at line 501 of file x509parse.c.
References ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, asn1_get_tag(), _x509_buf::len, _x509_buf::p, _x509_buf::tag, and XYSSL_ERR_ASN1_UNEXPECTED_TAG.
Referenced by x509parse_crt().
Definition at line 168 of file x509parse.c.
References ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, asn1_get_int(), asn1_get_tag(), XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_ASN1_UNEXPECTED_TAG, and XYSSL_ERR_X509_CERT_INVALID_VERSION.
Referenced by x509parse_crt().
Checkup routine.
Definition at line 1675 of file x509parse.c.
References rsa_free(), test_ca_crt, test_ca_key, test_ca_pwd, test_cli_crt, x509_free(), x509parse_crt(), x509parse_key(), and x509parse_verify().
Referenced by main().
| char* x509parse_cert_info | ( | char * | prefix, | |
| x509_cert * | crt | |||
| ) | 
Returns an informational string about the certificate.
Definition at line 1399 of file x509parse.c.
References buf, _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, x509parse_dn_gets(), and _x509_time::year.
Referenced by debug_print_crt(), and main().
Parse one or more certificates and add them to the chained list.
| chain | points to the start of the chain | |
| buf | buffer holding the certificate data | |
| buflen | size of the buffer | 
Definition at line 647 of file x509parse.c.
References ASN1_CONSTRUCTED, asn1_get_tag(), ASN1_SEQUENCE, base64_decode(), _x509_cert::ca_istrue, rsa_context::E, _x509_cert::issuer, _x509_cert::issuer_id, _x509_cert::issuer_raw, rsa_context::len, _x509_buf::len, _x509_cert::max_pathlen, mpi_size(), 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_free(), x509_get_alg(), x509_get_dates(), x509_get_ext(), x509_get_name(), x509_get_pubkey(), x509_get_serial(), x509_get_sig(), x509_get_uid(), x509_get_version(), x509parse_crt(), XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_BASE64_INVALID_CHARACTER, XYSSL_ERR_X509_CERT_INVALID_FORMAT, XYSSL_ERR_X509_CERT_INVALID_PEM, XYSSL_ERR_X509_CERT_SIG_MISMATCH, XYSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG, and XYSSL_ERR_X509_CERT_UNKNOWN_VERSION.
Referenced by main(), ssl_parse_certificate(), ssl_test(), x509_self_test(), x509parse_crt(), and x509parse_crtfile().
Load one or more certificates and add them to the chained list.
| chain | points to the start of the chain | |
| path | filename to read the certificates from | 
Definition at line 979 of file x509parse.c.
References buf, f, and x509parse_crt().
Store the certificate DN in printable form into buf; no more than (end - buf) characters will be written.
Definition at line 1316 of file x509parse.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 x509parse_cert_info().
Return 0 if the certificate is still valid, or BADCERT_EXPIRED.
Definition at line 1458 of file x509parse.c.
References BADCERT_EXPIRED, _x509_time::day, _x509_time::mon, _x509_cert::valid_to, and _x509_time::year.
Referenced by x509parse_verify().
| int x509parse_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 1082 of file x509parse.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, rsa_context::len, mpi_size(), rsa_context::N, rsa_context::P, rsa_context::Q, rsa_context::QP, rsa_check_privkey(), rsa_free(), rsa_context::ver, x509_des3_decrypt(), x509_get_iv(), XYSSL_ERR_ASN1_LENGTH_MISMATCH, XYSSL_ERR_BASE64_INVALID_CHARACTER, XYSSL_ERR_X509_FEATURE_UNAVAILABLE, XYSSL_ERR_X509_KEY_INVALID_ENC_IV, XYSSL_ERR_X509_KEY_INVALID_FORMAT, XYSSL_ERR_X509_KEY_INVALID_PEM, XYSSL_ERR_X509_KEY_INVALID_VERSION, XYSSL_ERR_X509_KEY_PASSWORD_MISMATCH, XYSSL_ERR_X509_KEY_PASSWORD_REQUIRED, and XYSSL_ERR_X509_KEY_UNKNOWN_ENC_ALG.
Referenced by main(), ssl_test(), x509_self_test(), and x509parse_keyfile().
| int x509parse_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 1269 of file x509parse.c.
References buf, f, and x509parse_key().
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 1503 of file x509parse.c.
References BADCERT_CN_MISMATCH, BADCERT_NOT_TRUSTED, _x509_cert::ca_istrue, cur, _x509_cert::issuer_raw, _x509_buf::len, _x509_cert::max_pathlen, _x509_cert::next, _x509_name::next, _x509_name::oid, OID_CN, _x509_buf::p, _x509_cert::rsa, rsa_pkcs1_verify(), RSA_PUBLIC, _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(), x509parse_expired(), and XYSSL_ERR_X509_CERT_VERIFY_FAILED.
Referenced by ssl_parse_certificate(), and x509_self_test().
 1.6.3
 1.6.3