#include "polarssl/config.h"
#include "polarssl/x509.h"
#include "polarssl/asn1.h"
#include "polarssl/oid.h"
#include "polarssl/pem.h"
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include "polarssl/x509_crt.h"
#include "polarssl/certs.h"
Go to the source code of this file.
Defines | |
#define | polarssl_malloc malloc |
#define | polarssl_free free |
#define | POLARSSL_ERR_DEBUG_BUF_TOO_SMALL -2 |
#define | SAFE_SNPRINTF() |
Functions | |
int | x509_get_serial (unsigned char **p, const unsigned char *end, x509_buf *serial) |
int | x509_get_alg_null (unsigned char **p, const unsigned char *end, x509_buf *alg) |
static int | x509_get_attr_type_value (unsigned char **p, const unsigned char *end, x509_name *cur) |
int | x509_get_name (unsigned char **p, const unsigned char *end, x509_name *cur) |
int | x509_get_time (unsigned char **p, const unsigned char *end, x509_time *time) |
int | x509_get_sig (unsigned char **p, const unsigned char *end, x509_buf *sig) |
int | x509_get_sig_alg (const x509_buf *sig_oid, md_type_t *md_alg, pk_type_t *pk_alg) |
int | x509_get_ext (unsigned char **p, const unsigned char *end, x509_buf *ext, int tag) |
int | x509_load_file (const char *path, unsigned char **buf, size_t *n) |
int | x509_dn_gets (char *buf, size_t size, const x509_name *dn) |
Store the certificate DN in printable form into buf; no more than size characters will be written. | |
int | x509_serial_gets (char *buf, size_t size, const x509_buf *serial) |
Store the certificate serial in printable form into buf; no more than size characters will be written. | |
int | x509_key_size_helper (char *buf, size_t size, const char *name) |
const char * | x509_oid_get_description (x509_buf *oid) |
Give an known OID, return its descriptive string. | |
int | x509_oid_get_numeric_string (char *buf, size_t size, x509_buf *oid) |
Give an OID, return a string version of its OID number. | |
int | x509_time_expired (const x509_time *to) |
Check a given x509_time against the system time and check if it is valid. | |
int | x509_self_test (int verbose) |
Checkup routine. |
#define polarssl_free free |
#define polarssl_malloc malloc |
#define SAFE_SNPRINTF | ( | ) |
{ \ if( ret == -1 ) \ return( -1 ); \ \ if ( (unsigned int) ret > n ) { \ p[n - 1] = '\0'; \ return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\ } \ \ n -= (unsigned int) ret; \ p += (unsigned int) ret; \ }
int x509_dn_gets | ( | char * | buf, | |
size_t | size, | |||
const x509_name * | dn | |||
) |
Store the certificate DN in printable form into buf; no more than size characters will be written.
buf | Buffer to write to | |
size | Maximum size of buffer | |
dn | The X509 name to represent |
Definition at line 488 of file x509.c.
References _asn1_buf::len, _asn1_named_data::next, _asn1_named_data::oid, oid_get_attr_short_name(), _asn1_buf::p, SAFE_SNPRINTF, and _asn1_named_data::val.
Referenced by test_suite_x509_dn_gets(), x509_crl_info(), x509_crt_info(), and x509_csr_info().
int x509_get_alg_null | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_buf * | alg | |||
) |
Definition at line 110 of file x509.c.
References asn1_get_alg_null(), and POLARSSL_ERR_X509_INVALID_ALG.
Referenced by x509_crl_parse(), x509_crt_parse_der_core(), and x509_csr_parse().
static int x509_get_attr_type_value | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_name * | cur | |||
) | [static] |
Definition at line 130 of file x509.c.
References ASN1_BMP_STRING, ASN1_CONSTRUCTED, asn1_get_len(), asn1_get_tag(), ASN1_IA5_STRING, ASN1_OID, ASN1_PRINTABLE_STRING, ASN1_SEQUENCE, ASN1_T61_STRING, ASN1_UNIVERSAL_STRING, ASN1_UTF8_STRING, _asn1_buf::len, _asn1_named_data::next, _asn1_named_data::oid, _asn1_buf::p, POLARSSL_ERR_ASN1_OUT_OF_DATA, POLARSSL_ERR_ASN1_UNEXPECTED_TAG, POLARSSL_ERR_X509_INVALID_NAME, _asn1_buf::tag, and _asn1_named_data::val.
Referenced by x509_get_name().
int x509_get_ext | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_buf * | ext, | |||
int | tag | |||
) |
Definition at line 351 of file x509.c.
References ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, asn1_get_tag(), ASN1_SEQUENCE, _asn1_buf::len, _asn1_buf::p, POLARSSL_ERR_ASN1_LENGTH_MISMATCH, POLARSSL_ERR_X509_INVALID_EXTENSIONS, and _asn1_buf::tag.
Referenced by x509_get_crl_ext(), and x509_get_crt_ext().
int x509_get_name | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_name * | cur | |||
) |
Definition at line 192 of file x509.c.
References ASN1_CONSTRUCTED, asn1_get_tag(), ASN1_SET, _asn1_named_data::next, POLARSSL_ERR_X509_INVALID_NAME, POLARSSL_ERR_X509_MALLOC_FAILED, polarssl_malloc, x509_get_attr_type_value(), and x509_get_name().
Referenced by x509_crl_parse(), x509_crt_parse_der_core(), x509_csr_parse(), and x509_get_name().
int x509_get_serial | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_buf * | serial | |||
) |
Definition at line 79 of file x509.c.
References ASN1_CONTEXT_SPECIFIC, asn1_get_len(), ASN1_INTEGER, ASN1_PRIMITIVE, _asn1_buf::len, _asn1_buf::p, POLARSSL_ERR_ASN1_OUT_OF_DATA, POLARSSL_ERR_ASN1_UNEXPECTED_TAG, POLARSSL_ERR_X509_INVALID_SERIAL, and _asn1_buf::tag.
Referenced by x509_crt_parse_der_core(), and x509_get_entries().
int x509_get_sig | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_buf * | sig | |||
) |
Definition at line 314 of file x509.c.
References asn1_get_bitstring_null(), _asn1_buf::len, _asn1_buf::p, POLARSSL_ERR_ASN1_OUT_OF_DATA, POLARSSL_ERR_X509_INVALID_SIGNATURE, and _asn1_buf::tag.
Referenced by x509_crl_parse(), x509_crt_parse_der_core(), and x509_csr_parse().
Definition at line 336 of file x509.c.
References oid_get_sig_alg(), and POLARSSL_ERR_X509_UNKNOWN_SIG_ALG.
Referenced by x509_crl_parse(), x509_crt_parse_der_core(), and x509_csr_parse().
int x509_get_time | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
x509_time * | time | |||
) |
Definition at line 250 of file x509.c.
References ASN1_GENERALIZED_TIME, asn1_get_len(), ASN1_UTC_TIME, _x509_time::day, _x509_time::hour, _x509_time::min, _x509_time::mon, POLARSSL_ERR_ASN1_OUT_OF_DATA, POLARSSL_ERR_ASN1_UNEXPECTED_TAG, POLARSSL_ERR_X509_INVALID_DATE, _x509_time::sec, tag, and _x509_time::year.
Referenced by x509_crl_parse(), x509_get_dates(), and x509_get_entries().
int x509_key_size_helper | ( | char * | buf, | |
size_t | size, | |||
const char * | name | |||
) |
Definition at line 582 of file x509.c.
References POLARSSL_ERR_DEBUG_BUF_TOO_SMALL, and SAFE_SNPRINTF.
Referenced by x509_crt_info(), and x509_csr_info().
int x509_load_file | ( | const char * | path, | |
unsigned char ** | buf, | |||
size_t * | n | |||
) |
Definition at line 392 of file x509.c.
References POLARSSL_ERR_X509_FILE_IO_ERROR, POLARSSL_ERR_X509_MALLOC_FAILED, polarssl_free, and polarssl_malloc.
Referenced by x509_crl_parse_file(), x509_crt_parse_file(), and x509_csr_parse_file().
const char* x509_oid_get_description | ( | x509_buf * | oid | ) |
Give an known OID, return its descriptive string.
oid | buffer containing the oid |
Definition at line 600 of file x509.c.
References oid_get_extended_key_usage().
int x509_oid_get_numeric_string | ( | char * | buf, | |
size_t | size, | |||
x509_buf * | oid | |||
) |
Give an OID, return a string version of its OID number.
(Deprecated. Use oid_get_numeric_string() instead)
buf | Buffer to write to | |
size | Maximum size of buffer | |
oid | Buffer containing the OID |
Definition at line 614 of file x509.c.
References oid_get_numeric_string().
int x509_self_test | ( | int | verbose | ) |
Checkup routine.
Definition at line 705 of file x509.c.
References POLARSSL_ERR_X509_FEATURE_UNAVAILABLE, test_ca_crt, test_cli_crt, x509_crt_free(), x509_crt_init(), x509_crt_parse(), and x509_crt_verify().
Referenced by test_suite_x509_selftest().
int x509_serial_gets | ( | char * | buf, | |
size_t | size, | |||
const x509_buf * | serial | |||
) |
Store the certificate serial in printable form into buf; no more than size characters will be written.
buf | Buffer to write to | |
size | Maximum size of buffer | |
serial | The X509 serial to represent |
Definition at line 548 of file x509.c.
References _asn1_buf::len, _asn1_buf::p, and SAFE_SNPRINTF.
Referenced by x509_crl_info(), and x509_crt_info().
int x509_time_expired | ( | const x509_time * | time | ) |
Check a given x509_time against the system time and check if it is valid.
time | x509_time to check |
Definition at line 623 of file x509.c.
References _x509_time::day, _x509_time::hour, _x509_time::min, _x509_time::mon, _x509_time::sec, and _x509_time::year.
Referenced by test_suite_x509_time_expired(), x509_crt_revoked(), x509_crt_verify_child(), x509_crt_verify_top(), and x509_crt_verifycrl().