37 #if !defined(POLARSSL_CONFIG_FILE)
40 #include POLARSSL_CONFIG_FILE
43 #if defined(POLARSSL_X509_CRT_PARSE_C)
47 #if defined(POLARSSL_PEM_PARSE_C)
51 #if defined(POLARSSL_PLATFORM_C)
54 #define polarssl_malloc malloc
55 #define polarssl_free free
58 #if defined(POLARSSL_THREADING_C)
64 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
70 #if defined(EFIX64) || defined(EFI32)
74 #if defined(POLARSSL_FS_IO)
76 #if !defined(_WIN32) || defined(EFIX64) || defined(EFI32)
77 #include <sys/types.h>
86 static int x509_get_version(
unsigned char **p,
87 const unsigned char *end,
122 static int x509_get_dates(
unsigned char **p,
123 const unsigned char *end,
152 static int x509_get_uid(
unsigned char **p,
153 const unsigned char *end,
178 static int x509_get_basic_constraints(
unsigned char **p,
179 const unsigned char *end,
209 if( *ca_istrue != 0 )
216 if( ( ret =
asn1_get_int( p, end, max_pathlen ) ) != 0 )
228 static int x509_get_ns_cert_type(
unsigned char **p,
229 const unsigned char *end,
230 unsigned char *ns_cert_type)
243 *ns_cert_type = *bs.
p;
247 static int x509_get_key_usage(
unsigned char **p,
248 const unsigned char *end,
249 unsigned char *key_usage)
271 static int x509_get_ext_key_usage(
unsigned char **p,
272 const unsigned char *end,
281 if( ext_key_usage->
buf.
p == NULL )
314 static int x509_get_subject_alt_name(
unsigned char **p,
315 const unsigned char *end,
329 if( *p + len != end )
335 if( ( end - *p ) < 1 )
349 if( tag != ( ASN1_CONTEXT_SPECIFIC | 2 ) )
356 if( cur->
buf.
p != NULL )
361 if( cur->
next == NULL )
393 static int x509_get_crt_ext(
unsigned char **p,
394 const unsigned char *end,
399 unsigned char *end_ext_data, *end_ext_octet;
425 end_ext_data = *p + len;
436 if( ( end - *p ) < 1 )
441 if( ( ret =
asn1_get_bool( p, end_ext_data, &is_critical ) ) != 0 &&
450 end_ext_octet = *p + len;
452 if( end_ext_octet != end_ext_data )
466 #if !defined(POLARSSL_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
483 if( ( ret = x509_get_basic_constraints( p, end_ext_octet,
490 if( ( ret = x509_get_key_usage( p, end_ext_octet,
497 if( ( ret = x509_get_ext_key_usage( p, end_ext_octet,
504 if( ( ret = x509_get_subject_alt_name( p, end_ext_octet,
511 if( ( ret = x509_get_ns_cert_type( p, end_ext_octet,
531 static int x509_crt_parse_der_core(
x509_crt *crt,
const unsigned char *buf,
536 unsigned char *p, *end, *crt_end;
541 if( crt == NULL || buf == NULL )
549 memcpy( p, buf, buflen );
568 if( len > (
size_t) ( end - p ) )
598 if( ( ret = x509_get_version( &p, end, &crt->
version ) ) != 0 ||
647 if( ( ret = x509_get_dates( &p, end, &crt->
valid_from,
693 ret = x509_get_uid( &p, end, &crt->
issuer_id, 1 );
703 ret = x509_get_uid( &p, end, &crt->
subject_id, 2 );
711 #if !defined(POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3)
715 ret = x509_get_crt_ext( &p, end, crt);
721 #if !defined(POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3)
778 x509_crt *crt = chain, *prev = NULL;
783 if( crt == NULL || buf == NULL )
799 if( crt->
next == NULL )
807 if( ( ret = x509_crt_parse_der_core( crt, buf, buflen ) ) != 0 )
827 int success = 0, first_error = 0, total_failed = 0;
833 if( chain == NULL || buf == NULL )
840 #if defined(POLARSSL_PEM_PARSE_C)
841 if( strstr( (
const char *) buf,
"-----BEGIN CERTIFICATE-----" ) != NULL )
848 #if defined(POLARSSL_PEM_PARSE_C)
859 ret = pem_read_buffer( &pem,
860 "-----BEGIN CERTIFICATE-----",
861 "-----END CERTIFICATE-----",
862 buf, NULL, 0, &use_len );
886 if( first_error == 0 )
906 if( first_error == 0 )
919 return( total_failed );
920 else if( first_error )
921 return( first_error );
926 #if defined(POLARSSL_FS_IO)
941 memset( buf, 0, n + 1 );
947 #if defined(POLARSSL_THREADING_PTHREAD)
948 static threading_mutex_t readdir_mutex = PTHREAD_MUTEX_INITIALIZER;
954 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
956 WCHAR szDir[MAX_PATH];
957 char filename[MAX_PATH];
959 int len = (int) strlen( path );
961 WIN32_FIND_DATAW file_data;
964 if( len > MAX_PATH - 3 )
967 memset( szDir, 0,
sizeof(szDir) );
968 memset( filename, 0, MAX_PATH );
969 memcpy( filename, path, len );
970 filename[len++] =
'\\';
972 filename[len++] =
'*';
974 w_ret = MultiByteToWideChar( CP_ACP, 0, filename, len, szDir,
977 hFind = FindFirstFileW( szDir, &file_data );
978 if (hFind == INVALID_HANDLE_VALUE)
981 len = MAX_PATH - len;
986 if( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
989 w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
990 lstrlenW(file_data.cFileName),
1000 while( FindNextFileW( hFind, &file_data ) != 0 );
1002 if (GetLastError() != ERROR_NO_MORE_FILES)
1009 struct dirent *entry;
1010 char entry_name[255];
1011 DIR *dir = opendir( path );
1016 #if defined(POLARSSL_THREADING_PTHREAD)
1021 while( ( entry = readdir( dir ) ) != NULL )
1023 snprintf( entry_name,
sizeof entry_name,
"%s/%s", path, entry->d_name );
1025 if( stat( entry_name, &sb ) == -1 )
1032 if( !S_ISREG( sb.st_mode ) )
1046 #if defined(POLARSSL_THREADING_PTHREAD)
1057 #if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
1061 #if !defined vsnprintf
1062 #define vsnprintf _vsnprintf
1072 static int compat_snprintf(
char *str,
size_t size,
const char *format, ...)
1077 va_start( ap, format );
1079 res = vsnprintf( str, size, format, ap );
1085 return( (
int) size + 20 );
1090 #define snprintf compat_snprintf
1093 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL -2
1095 #define SAFE_SNPRINTF() \
1100 if ( (unsigned int) ret > n ) { \
1102 return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\
1105 n -= (unsigned int) ret; \
1106 p += (unsigned int) ret; \
1109 static int x509_info_subject_alt_name(
char **buf,
size_t *size,
1116 const char *sep =
"";
1119 while( cur != NULL )
1121 if( cur->
buf.
len + sep_len >= n )
1124 return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL );
1127 n -= cur->
buf.
len + sep_len;
1128 for( i = 0; i < sep_len; i++ )
1130 for( i = 0; i < cur->
buf.
len; i++ )
1131 *p++ = cur->
buf.
p[i];
1147 #define PRINT_ITEM(i) \
1149 ret = snprintf( p, n, "%s" i, sep ); \
1154 #define CERT_TYPE(type,name) \
1155 if( ns_cert_type & type ) \
1158 static int x509_info_cert_type(
char **buf,
size_t *size,
1159 unsigned char ns_cert_type )
1164 const char *sep =
"";
1181 #define KEY_USAGE(code,name) \
1182 if( key_usage & code ) \
1185 static int x509_info_key_usage(
char **buf,
size_t *size,
1186 unsigned char key_usage )
1191 const char *sep =
"";
1207 static int x509_info_ext_key_usage(
char **buf,
size_t *size,
1215 const char *sep =
"";
1217 while( cur != NULL )
1222 ret = snprintf( p, n,
"%s%s", sep, desc );
1239 #define BEFORE_COLON 18
1241 int x509_crt_info(
char *buf,
size_t size,
const char *prefix,
1247 const char *desc = NULL;
1248 char key_size_str[BEFORE_COLON];
1253 ret = snprintf( p, n,
"%scert. version : %d\n",
1256 ret = snprintf( p, n,
"%sserial number : ",
1263 ret = snprintf( p, n,
"\n%sissuer name : ", prefix );
1268 ret = snprintf( p, n,
"\n%ssubject name : ", prefix );
1273 ret = snprintf( p, n,
"\n%sissued on : " \
1274 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
1280 ret = snprintf( p, n,
"\n%sexpires on : " \
1281 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
1287 ret = snprintf( p, n,
"\n%ssigned using : ", prefix );
1292 ret = snprintf( p, n,
"???" );
1294 ret = snprintf( p, n,
"%s", desc );
1304 ret = snprintf( p, n,
"\n%s%-" BC
"s: %d bits", prefix, key_size_str,
1314 ret = snprintf( p, n,
"\n%sbasic constraints : CA=%s", prefix,
1320 ret = snprintf( p, n,
", max_pathlen=%d", crt->
max_pathlen - 1 );
1327 ret = snprintf( p, n,
"\n%ssubject alt name : ", prefix );
1330 if( ( ret = x509_info_subject_alt_name( &p, &n,
1337 ret = snprintf( p, n,
"\n%scert. type : ", prefix );
1340 if( ( ret = x509_info_cert_type( &p, &n, crt->
ns_cert_type ) ) != 0 )
1346 ret = snprintf( p, n,
"\n%skey usage : ", prefix );
1349 if( ( ret = x509_info_key_usage( &p, &n, crt->
key_usage ) ) != 0 )
1355 ret = snprintf( p, n,
"\n%sext key usage : ", prefix );
1358 if( ( ret = x509_info_ext_key_usage( &p, &n,
1363 ret = snprintf( p, n,
"\n" );
1366 return( (
int) ( size - n ) );
1369 #if defined(POLARSSL_X509_CHECK_KEY_USAGE)
1380 #if defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
1382 const char *usage_oid,
1398 if( cur_oid->
len == usage_len &&
1399 memcmp( cur_oid->
p, usage_oid, usage_len ) == 0 )
1412 #if defined(POLARSSL_X509_CRL_PARSE_C)
1420 while( cur != NULL && cur->
serial.
len != 0 )
1454 while( crl_list != NULL )
1461 crl_list = crl_list->
next;
1468 #if defined(POLARSSL_X509_CHECK_KEY_USAGE)
1480 if( md_info == NULL )
1489 md( md_info, crl_list->
tbs.
p, crl_list->
tbs.
len, hash );
1517 crl_list = crl_list->
next;
1524 static int x509_name_cmp(
const void *s1,
const void *s2,
size_t len )
1528 const unsigned char *n1 = s1, *n2 = s2;
1530 for( i = 0; i < len; i++ )
1532 diff = n1[i] ^ n2[i];
1538 ( ( n1[i] >=
'a' && n1[i] <=
'z' ) ||
1539 ( n1[i] >=
'A' && n1[i] <=
'Z' ) ) )
1550 static int x509_wildcard_verify(
const char *cn,
x509_buf *name )
1555 if( name->
len < 3 || name->
p[0] !=
'*' || name->
p[1] !=
'.' )
1558 for( i = 0; i < strlen( cn ); ++i )
1570 if( strlen( cn ) - cn_idx == name->
len - 1 &&
1571 x509_name_cmp( name->
p + 1, cn + cn_idx, name->
len - 1 ) == 0 )
1583 static int x509_crt_check_parent(
const x509_crt *child,
1595 #if defined(POLARSSL_X509_CHECK_KEY_USAGE)
1603 static int x509_crt_verify_top(
1605 x509_crl *ca_crl,
int path_cnt,
int *flags,
1606 int (*f_vrfy)(
void *,
x509_crt *,
int,
int *),
1610 int ca_flags = 0, check_path_cnt = path_cnt + 1;
1626 if( md_info == NULL )
1636 for( ; trust_ca != NULL; trust_ca = trust_ca->
next )
1638 if( x509_crt_check_parent( child, trust_ca ) != 0 )
1677 if( trust_ca != NULL &&
1682 #if defined(POLARSSL_X509_CRL_PARSE_C)
1684 *flags |= x509_crt_verifycrl( child, trust_ca, ca_crl );
1695 if( NULL != f_vrfy )
1697 if( ( ret = f_vrfy( p_vrfy, trust_ca, path_cnt + 1,
1698 &ca_flags ) ) != 0 )
1706 if( NULL != f_vrfy )
1708 if( ( ret = f_vrfy(p_vrfy, child, path_cnt, flags ) ) != 0 )
1717 static int x509_crt_verify_child(
1719 x509_crl *ca_crl,
int path_cnt,
int *flags,
1720 int (*f_vrfy)(
void *,
x509_crt *,
int,
int *),
1724 int parent_flags = 0;
1736 if( md_info == NULL )
1755 #if defined(POLARSSL_X509_CRL_PARSE_C)
1757 *flags |= x509_crt_verifycrl(child, parent, ca_crl);
1761 for( grandparent = parent->
next;
1762 grandparent != NULL;
1763 grandparent = grandparent->
next )
1765 if( x509_crt_check_parent( parent, grandparent ) == 0 )
1770 if( grandparent != NULL )
1772 ret = x509_crt_verify_child( parent, grandparent, trust_ca, ca_crl,
1773 path_cnt + 1, &parent_flags, f_vrfy, p_vrfy );
1779 ret = x509_crt_verify_top( parent, trust_ca, ca_crl,
1780 path_cnt + 1, &parent_flags, f_vrfy, p_vrfy );
1786 if( NULL != f_vrfy )
1787 if( ( ret = f_vrfy( p_vrfy, child, path_cnt, flags ) ) != 0 )
1790 *flags |= parent_flags;
1801 const char *cn,
int *flags,
1802 int (*f_vrfy)(
void *,
x509_crt *,
int,
int *),
1817 cn_len = strlen( cn );
1823 while( cur != NULL )
1825 if( cur->
buf.
len == cn_len &&
1826 x509_name_cmp( cn, cur->
buf.
p, cn_len ) == 0 )
1830 memcmp( cur->
buf.
p,
"*.", 2 ) == 0 &&
1831 x509_wildcard_verify( cn, &cur->
buf ) )
1842 while( name != NULL )
1846 if( name->
val.
len == cn_len &&
1847 x509_name_cmp( name->
val.
p, cn, cn_len ) == 0 )
1851 memcmp( name->
val.
p,
"*.", 2 ) == 0 &&
1852 x509_wildcard_verify( cn, &name->
val ) )
1865 for( parent = crt->
next; parent != NULL; parent = parent->
next )
1867 if( x509_crt_check_parent( crt, parent ) == 0 )
1872 if( parent != NULL )
1874 ret = x509_crt_verify_child( crt, parent, trust_ca, ca_crl,
1875 pathlen, flags, f_vrfy, p_vrfy );
1881 ret = x509_crt_verify_top( crt, trust_ca, ca_crl,
1882 pathlen, flags, f_vrfy, p_vrfy );
1898 memset( crt, 0,
sizeof(
x509_crt) );
1921 while( name_cur != NULL )
1923 name_prv = name_cur;
1924 name_cur = name_cur->
next;
1925 memset( name_prv, 0,
sizeof(
x509_name ) );
1930 while( name_cur != NULL )
1932 name_prv = name_cur;
1933 name_cur = name_cur->
next;
1934 memset( name_prv, 0,
sizeof(
x509_name ) );
1939 while( seq_cur != NULL )
1942 seq_cur = seq_cur->
next;
1948 while( seq_cur != NULL )
1951 seq_cur = seq_cur->
next;
1956 if( cert_cur->
raw.
p != NULL )
1958 memset( cert_cur->
raw.
p, 0, cert_cur->
raw.
len );
1962 cert_cur = cert_cur->
next;
1964 while( cert_cur != NULL );
1969 cert_prv = cert_cur;
1970 cert_cur = cert_cur->
next;
1972 memset( cert_prv, 0,
sizeof(
x509_crt ) );
1973 if( cert_prv != crt )
1976 while( cert_cur != NULL );
int md(const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
Output = message_digest( input buffer )
int x509_time_expired(const x509_time *time)
Check a given x509_time against the system time and check if it is not expired.
int asn1_get_sequence_of(unsigned char **p, const unsigned char *end, asn1_sequence *cur, int tag)
Parses and splits an ASN.1 "SEQUENCE OF <tag>" Updated the pointer to immediately behind the full seq...
x509_sequence subject_alt_names
Optional list of Subject Alternative Names (Only dNSName supported).
#define KU_NON_REPUDIATION
int(* polarssl_mutex_lock)(threading_mutex_t *mutex)
int x509_get_name(unsigned char **p, const unsigned char *end, x509_name *cur)
#define POLARSSL_ERR_X509_INVALID_DATE
The date tag or value is invalid.
asn1_buf buf
Buffer containing the given ASN.1 item.
int x509_get_serial(unsigned char **p, const unsigned char *end, x509_buf *serial)
x509_buf raw
The raw certificate data (DER).
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
int ext_types
Bit string containing detected and parsed extensions.
Certificate revocation list entry.
size_t pk_get_size(const pk_context *ctx)
Get the size in bits of the underlying key.
#define OID_ANY_EXTENDED_KEY_USAGE
anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 }
#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT
Format not recognized as DER or PEM.
#define EXT_BASIC_CONSTRAINTS
unsigned char ns_cert_type
Optional Netscape certificate type extension value: See the values in x509.h.
#define KU_DATA_ENCIPHERMENT
x509_buf issuer_raw
The raw issuer data (DER).
#define POLARSSL_ERR_X509_INVALID_FORMAT
The CRT/CRL/CSR format is invalid, e.g.
int x509_key_size_helper(char *buf, size_t size, const char *name)
#define NS_CERT_TYPE_OBJECT_SIGNING
int asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value.
size_t len
ASN1 length, e.g.
int x509_get_alg_null(unsigned char **p, const unsigned char *end, x509_buf *alg)
Container for date and time (precision in seconds).
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.
x509_buf sig_oid2
Signature algorithm.
int oid_get_x509_ext_type(const asn1_buf *oid, int *ext_type)
Translate an X.509 extension OID into local values.
void x509_crt_free(x509_crt *crt)
Unallocate all certificate data.
Configuration options (set of defines)
#define OID_CMP(oid_str, oid_buf)
Compares two asn1_buf structures for the same OID.
x509_buf tbs
The raw certificate body (DER).
x509_buf serial
Unique id for certificate issued by a specific CA.
md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
#define NS_CERT_TYPE_OBJECT_SIGNING_CA
int ca_istrue
Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise...
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.
int max_pathlen
Optional Basic Constraint extension value: The maximum path length to the root certificate.
int x509_get_sig(unsigned char **p, const unsigned char *end, x509_buf *sig)
const char * pk_get_name(const pk_context *ctx)
Access the type name.
#define BADCRL_NOT_TRUSTED
CRL is not correctly signed by the trusted CA.
#define POLARSSL_ERR_ASN1_INVALID_LENGTH
Error when trying to determine the length or invalid length.
Container for ASN1 bit strings.
#define POLARSSL_ERR_X509_UNKNOWN_VERSION
CRT/CRL/CSR has an unsupported version number.
Object Identifier (OID) database.
#define OID_AT_CN
id-at-commonName AttributeType:= {id-at 3}
struct _x509_crt * next
Next certificate in the CA-chain.
int x509_crt_check_key_usage(const x509_crt *crt, int usage)
Check usage of certificate against keyUsage extension.
x509_crl_entry entry
The CRL entries containing the certificate revocation times for this CA.
asn1_buf val
The named value.
Container for a sequence of ASN.1 items.
#define NS_CERT_TYPE_RESERVED
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
int x509_get_time(unsigned char **p, const unsigned char *end, x509_time *time)
#define BADCERT_EXPIRED
The certificate validity has expired.
#define BADCERT_FUTURE
The certificate validity starts in the future.
unsigned char * p
Raw ASN1 data for the bit string.
Threading abstraction layer.
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED
Certificate verification failed, e.g.
Container for an X.509 certificate.
Privacy Enhanced Mail (PEM) decoding.
x509_time valid_from
Start time of certificate validity.
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...
asn1_buf oid
The object identifier.
#define NS_CERT_TYPE_EMAIL
int pk_verify(pk_context *ctx, md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature.
x509_sequence ext_key_usage
Optional list of extended key usage OIDs.
void x509_crt_init(x509_crt *crt)
Initialize a certificate (chain)
unsigned char * p
ASN1 data, e.g.
int oid_get_sig_alg_desc(const asn1_buf *oid, const char **desc)
Translate SignatureAlgorithm OID into description.
x509_name subject
The parsed subject data (named information object).
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.
int pk_can_do(pk_context *ctx, pk_type_t type)
Tell if a context can do the operation given by type.
x509_buf tbs
The raw certificate body (DER).
int asn1_get_bool(unsigned char **p, const unsigned char *end, int *val)
Retrieve a boolean ASN.1 tag and its value.
x509_time valid_to
End time of certificate validity.
struct _x509_crl_entry * next
md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
X.509 certificate parsing and writing.
#define NS_CERT_TYPE_SSL_CA
int x509_get_sig_alg(const x509_buf *sig_oid, md_type_t *md_alg, pk_type_t *pk_alg)
x509_buf sig_oid1
Signature algorithm, e.g.
#define POLARSSL_ERR_ASN1_OUT_OF_DATA
Out of data when parsing an ASN1 data structure.
#define EXT_EXTENDED_KEY_USAGE
int pk_parse_subpubkey(unsigned char **p, const unsigned char *end, pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
int x509_load_file(const char *path, unsigned char **buf, size_t *n)
#define POLARSSL_ERR_ASN1_MALLOC_FAILED
Memory allocation failed.
#define ASN1_CONTEXT_SPECIFIC
#define BADCERT_NOT_TRUSTED
The certificate is not correctly signed by the trusted CA.
#define POLARSSL_ERR_X509_FILE_IO_ERROR
Read/write of file failed.
int x509_crt_revoked(const x509_crt *crt, const x509_crl *crl)
Verify the certificate revocation status.
Container for a sequence or list of 'named' ASN.1 data items.
Type-length-value structure that allows for ASN1 using DER.
pk_type_t sig_pk
< Internal representation of the Public Key algorithm of the signature algorithm, e...
size_t len
ASN1 length, e.g.
#define BADCRL_FUTURE
The CRL is from the future.
x509_name issuer
The parsed issuer data (named information object).
void pk_free(pk_context *ctx)
Free a pk_context.
#define POLARSSL_MD_MAX_SIZE
int(* polarssl_mutex_unlock)(threading_mutex_t *mutex)
#define NS_CERT_TYPE_EMAIL_CA
#define BADCERT_REVOKED
The certificate has been revoked (is on a CRL).
#define BADCRL_EXPIRED
CRL is expired.
int asn1_get_len(unsigned char **p, const unsigned char *end, size_t *len)
Get the length of an ASN.1 element.
#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE
Unavailable feature, e.g.
int asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag.
#define KU_DIGITAL_SIGNATURE
int x509_get_ext(unsigned char **p, const unsigned char *end, x509_buf *ext, int tag)
#define NS_CERT_TYPE_SSL_SERVER
#define POLARSSL_ERR_X509_INVALID_VERSION
The CRT/CRL/CSR version element is invalid.
Certificate revocation list structure.
int asn1_get_bitstring(unsigned char **p, const unsigned char *end, asn1_bitstring *bs)
Retrieve a bitstring ASN.1 tag and its value.
pk_context pk
Container for the public key context.
#define POLARSSL_ERR_THREADING_MUTEX_ERROR
Locking / unlocking / free failed with error code.
struct _asn1_named_data * next
The next entry in the sequence.
int size
Output length of the digest function.
x509_buf issuer_id
Optional X.509 v2/v3 issuer unique identifier.
#define POLARSSL_ERR_X509_INVALID_EXTENSIONS
The extension tag or value is invalid.
#define ASN1_OCTET_STRING
int x509_time_future(const x509_time *time)
Check a given x509_time against the system time and check if it is not from the future.
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.
x509_buf v3_ext
Optional X.509 v3 extensions.
#define POLARSSL_ERR_X509_BAD_INPUT_DATA
Input invalid.
x509_buf subject_id
Optional X.509 v2/v3 subject unique identifier.
#define BADCERT_CN_MISMATCH
The certificate Common Name (CN) does not match with the expected CN.
int version
The X.509 version.
#define POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT
No PEM header or footer found.
pk_type_t sig_pk
< Internal representation of the Public Key algorithm of the signature algorithm, e...
x509_time revocation_date
x509_buf issuer_raw
The raw issuer data (DER).
int x509_crt_info(char *buf, size_t size, const char *prefix, const x509_crt *crt)
Returns an informational string about the certificate.
#define NS_CERT_TYPE_SSL_CLIENT
#define POLARSSL_ERR_X509_MALLOC_FAILED
Allocation of memory failed.
#define POLARSSL_ERR_PEM_BAD_INPUT_DATA
Bad input parameters to function.
unsigned char key_usage
Optional key usage extension value: See the values in x509.h.
x509_buf subject_raw
The raw subject data (DER).
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.
Message digest information.
int oid_get_extended_key_usage(const asn1_buf *oid, const char **desc)
Translate Extended Key Usage OID into description.
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
#define KU_KEY_ENCIPHERMENT
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...
#define POLARSSL_ERR_X509_SIG_MISMATCH
Signature algorithms do not match.
struct _asn1_sequence * next
The next entry in the sequence.
int x509_crt_parse_file(x509_crt *chain, const char *path)
Load one or more certificates and add them to the chained list.
x509_buf sig
Signature: hash of the tbs part signed with the private key.
#define EXT_SUBJECT_ALT_NAME