36 #if !defined(POLARSSL_CONFIG_FILE)
39 #include POLARSSL_CONFIG_FILE
42 #if defined(POLARSSL_X509_CRL_PARSE_C)
46 #if defined(POLARSSL_PEM_PARSE_C)
50 #if defined(POLARSSL_PLATFORM_C)
53 #define polarssl_malloc malloc
54 #define polarssl_free free
59 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
66 #if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32)
71 static void polarssl_zeroize(
void *v,
size_t n ) {
72 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
78 static int x509_crl_get_version(
unsigned char **p,
79 const unsigned char *end,
101 static int x509_get_crl_ext(
unsigned char **p,
102 const unsigned char *end,
136 static int x509_get_crl_entry_ext(
unsigned char **p,
137 const unsigned char *end,
167 if( end != *p + ext->
len )
190 static int x509_get_entries(
unsigned char **p,
191 const unsigned char *end,
210 end = *p + entry_len;
215 const unsigned char *end2;
224 cur_entry->
raw.
p = *p;
225 cur_entry->
raw.
len = len2;
235 if( ( ret = x509_get_crl_entry_ext( p, end2,
243 if( cur_entry->
next == NULL )
246 cur_entry = cur_entry->
next;
261 unsigned char *p, *end;
265 #if defined(POLARSSL_PEM_PARSE_C)
270 memset( &sig_params1, 0,
sizeof(
x509_buf ) );
271 memset( &sig_params2, 0,
sizeof(
x509_buf ) );
278 if( crl == NULL || buf == NULL )
291 if( crl->
next == NULL )
301 #if defined(POLARSSL_PEM_PARSE_C)
303 ret = pem_read_buffer( &pem,
304 "-----BEGIN X509 CRL-----",
305 "-----END X509 CRL-----",
306 buf, NULL, 0, &use_len );
340 memcpy( p, buf, buflen );
362 if( len != (
size_t) ( end - p ) )
390 if( ( ret = x509_crl_get_version( &p, end, &crl->
version ) ) != 0 ||
463 if( ( ret = x509_get_entries( &p, end, &crl->
entry ) ) != 0 )
475 ret = x509_get_crl_ext( &p, end, &crl->
crl_ext );
505 sig_params1.
len != sig_params2.
len ||
506 memcmp( sig_params1.
p, sig_params2.
p, sig_params1.
len ) != 0 )
529 if( crl->
next == NULL )
544 #if defined(POLARSSL_FS_IO)
559 polarssl_zeroize( buf, n + 1 );
566 #if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
570 #if !defined vsnprintf
571 #define vsnprintf _vsnprintf
581 static int compat_snprintf(
char *str,
size_t size,
const char *format, ... )
586 va_start( ap, format );
588 res = vsnprintf( str, size, format, ap );
594 return( (
int) size + 20 );
599 #define snprintf compat_snprintf
602 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL -2
604 #define SAFE_SNPRINTF() \
609 if( (unsigned int) ret > n ) { \
611 return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
614 n -= (unsigned int) ret; \
615 p += (unsigned int) ret; \
621 #define BEFORE_COLON 14
626 int x509_crl_info(
char *buf,
size_t size,
const char *prefix,
637 ret = snprintf( p, n,
"%sCRL version : %d",
641 ret = snprintf( p, n,
"\n%sissuer name : ", prefix );
646 ret = snprintf( p, n,
"\n%sthis update : " \
647 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
653 ret = snprintf( p, n,
"\n%snext update : " \
654 "%04d-%02d-%02d %02d:%02d:%02d", prefix,
662 ret = snprintf( p, n,
"\n%sRevoked certificates:",
666 while( entry != NULL && entry->
raw.
len != 0 )
668 ret = snprintf( p, n,
"\n%sserial number: ",
675 ret = snprintf( p, n,
" revocation date: " \
676 "%04d-%02d-%02d %02d:%02d:%02d",
685 ret = snprintf( p, n,
"\n%ssigned using : ", prefix );
692 ret = snprintf( p, n,
"\n" );
695 return( (
int) ( size - n ) );
723 #if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
728 while( name_cur != NULL )
731 name_cur = name_cur->
next;
732 polarssl_zeroize( name_prv,
sizeof(
x509_name ) );
737 while( entry_cur != NULL )
739 entry_prv = entry_cur;
740 entry_cur = entry_cur->
next;
745 if( crl_cur->
raw.
p != NULL )
747 polarssl_zeroize( crl_cur->
raw.
p, crl_cur->
raw.
len );
751 crl_cur = crl_cur->
next;
753 while( crl_cur != NULL );
759 crl_cur = crl_cur->
next;
761 polarssl_zeroize( crl_prv,
sizeof(
x509_crl ) );
765 while( crl_cur != NULL );
void x509_crl_init(x509_crl *crl)
Initialize a CRL (chain)
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.
int version
CRL version (1=v1, 2=v2)
int x509_get_serial(unsigned char **p, const unsigned char *end, x509_buf *serial)
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
Certificate revocation list entry.
int x509_get_sig_alg(const x509_buf *sig_oid, const x509_buf *sig_params, md_type_t *md_alg, pk_type_t *pk_alg, void **sig_opts)
#define POLARSSL_ERR_X509_INVALID_FORMAT
The CRT/CRL/CSR format is invalid, e.g.
int asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value.
void * sig_opts
Signature options to be passed to pk_verify_ext(), e.g.
Configuration options (set of defines)
#define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG
Signature algorithm (oid) is unsupported.
int x509_get_sig(unsigned char **p, const unsigned char *end, x509_buf *sig)
#define POLARSSL_ERR_X509_UNKNOWN_VERSION
CRT/CRL/CSR has an unsupported version number.
x509_name issuer
The parsed issuer data (named information object).
int x509_crl_parse_file(x509_crl *chain, const char *path)
Load one or more CRLs and add them to the chained list.
Object Identifier (OID) database.
int x509_crl_parse(x509_crl *chain, const unsigned char *buf, size_t buflen)
Parse one or more CRLs and add them to the chained list.
int x509_crl_info(char *buf, size_t size, const char *prefix, const x509_crl *crl)
Returns an informational string about the CRL.
int x509_get_alg(unsigned char **p, const unsigned char *end, x509_buf *alg, x509_buf *params)
x509_crl_entry entry
The CRL entries containing the certificate revocation times for this CA.
int x509_get_time(unsigned char **p, const unsigned char *end, x509_time *time)
Privacy Enhanced Mail (PEM) decoding.
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...
void x509_crl_free(x509_crl *crl)
Unallocate all CRL data.
unsigned char * p
ASN1 data, e.g.
x509_buf tbs
The raw certificate body (DER).
struct _x509_crl_entry * next
md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
#define POLARSSL_ERR_ASN1_OUT_OF_DATA
Out of data when parsing an ASN1 data structure.
int x509_sig_alg_gets(char *buf, size_t size, const x509_buf *sig_oid, pk_type_t pk_alg, md_type_t md_alg, const void *sig_opts)
int x509_load_file(const char *path, unsigned char **buf, size_t *n)
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.g.
size_t len
ASN1 length, e.g.
X.509 certificate revocation list parsing.
int asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag.
int x509_get_ext(unsigned char **p, const unsigned char *end, x509_buf *ext, int tag)
#define POLARSSL_ERR_X509_INVALID_VERSION
The CRT/CRL/CSR version element is invalid.
Certificate revocation list structure.
struct _asn1_named_data * next
The next entry in the sequence.
#define POLARSSL_ERR_X509_INVALID_EXTENSIONS
The extension tag or value is invalid.
#define POLARSSL_ERR_X509_BAD_INPUT_DATA
Input invalid.
x509_buf raw
The raw certificate data (DER).
#define POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT
No PEM header or footer found.
x509_time revocation_date
x509_buf issuer_raw
The raw issuer data (DER).
#define POLARSSL_ERR_X509_MALLOC_FAILED
Allocation of memory failed.
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
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.