mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Update external polarssl to 1.3.8
There were some fixes back on March 13th, 2014 for fixing compiling on MIPS64. Also some fixes on June 25th, 2014 for SPARC64 fixes. Probably more things, but those are what I care about.
This commit is contained in:
501
Externals/polarssl/library/x509.c
vendored
501
Externals/polarssl/library/x509.c
vendored
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X.509 certificate and private key decoding
|
||||
* X.509 common functions for parsing and verification
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -25,16 +25,19 @@
|
||||
/*
|
||||
* The ITU-T X.509 standard defines a certificate format for PKI.
|
||||
*
|
||||
* http://www.ietf.org/rfc/rfc3279.txt
|
||||
* http://www.ietf.org/rfc/rfc3280.txt
|
||||
*
|
||||
* ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-1v2.asc
|
||||
* http://www.ietf.org/rfc/rfc5280.txt (Certificates and CRLs)
|
||||
* http://www.ietf.org/rfc/rfc3279.txt (Alg IDs for CRLs)
|
||||
* http://www.ietf.org/rfc/rfc2986.txt (CSRs, aka PKCS#10)
|
||||
*
|
||||
* http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
|
||||
* http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
|
||||
*/
|
||||
|
||||
#if !defined(POLARSSL_CONFIG_FILE)
|
||||
#include "polarssl/config.h"
|
||||
#else
|
||||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_X509_USE_C)
|
||||
|
||||
@ -45,9 +48,10 @@
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
@ -118,6 +122,223 @@ int x509_get_alg_null( unsigned char **p, const unsigned char *end,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse an algorithm identifier with (optional) paramaters
|
||||
*/
|
||||
int x509_get_alg( unsigned char **p, const unsigned char *end,
|
||||
x509_buf *alg, x509_buf *params )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if( ( ret = asn1_get_alg( p, end, alg, params ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
|
||||
/*
|
||||
* HashAlgorithm ::= AlgorithmIdentifier
|
||||
*
|
||||
* AlgorithmIdentifier ::= SEQUENCE {
|
||||
* algorithm OBJECT IDENTIFIER,
|
||||
* parameters ANY DEFINED BY algorithm OPTIONAL }
|
||||
*
|
||||
* For HashAlgorithm, parameters MUST be NULL or absent.
|
||||
*/
|
||||
static int x509_get_hash_alg( const x509_buf *alg, md_type_t *md_alg )
|
||||
{
|
||||
int ret;
|
||||
unsigned char *p;
|
||||
const unsigned char *end;
|
||||
x509_buf md_oid;
|
||||
size_t len;
|
||||
|
||||
/* Make sure we got a SEQUENCE and setup bounds */
|
||||
if( alg->tag != ( ASN1_CONSTRUCTED | ASN1_SEQUENCE ) )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_UNEXPECTED_TAG );
|
||||
|
||||
p = (unsigned char *) alg->p;
|
||||
end = p + alg->len;
|
||||
|
||||
if( p >= end )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
/* Parse md_oid */
|
||||
md_oid.tag = *p;
|
||||
|
||||
if( ( ret = asn1_get_tag( &p, end, &md_oid.len, ASN1_OID ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
md_oid.p = p;
|
||||
p += md_oid.len;
|
||||
|
||||
/* Get md_alg from md_oid */
|
||||
if( ( ret = oid_get_md_alg( &md_oid, md_alg ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
/* Make sure params is absent of NULL */
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
if( ( ret = asn1_get_tag( &p, end, &len, ASN1_NULL ) ) != 0 || len != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p != end )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* RSASSA-PSS-params ::= SEQUENCE {
|
||||
* hashAlgorithm [0] HashAlgorithm DEFAULT sha1Identifier,
|
||||
* maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1Identifier,
|
||||
* saltLength [2] INTEGER DEFAULT 20,
|
||||
* trailerField [3] INTEGER DEFAULT 1 }
|
||||
* -- Note that the tags in this Sequence are explicit.
|
||||
*
|
||||
* RFC 4055 (which defines use of RSASSA-PSS in PKIX) states that the value
|
||||
* of trailerField MUST be 1, and PKCS#1 v2.2 doesn't even define any other
|
||||
* option. Enfore this at parsing time.
|
||||
*/
|
||||
int x509_get_rsassa_pss_params( const x509_buf *params,
|
||||
md_type_t *md_alg, md_type_t *mgf_md,
|
||||
int *salt_len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char *p;
|
||||
const unsigned char *end, *end2;
|
||||
size_t len;
|
||||
x509_buf alg_id, alg_params;
|
||||
|
||||
/* First set everything to defaults */
|
||||
*md_alg = POLARSSL_MD_SHA1;
|
||||
*mgf_md = POLARSSL_MD_SHA1;
|
||||
*salt_len = 20;
|
||||
|
||||
/* Make sure params is a SEQUENCE and setup bounds */
|
||||
if( params->tag != ( ASN1_CONSTRUCTED | ASN1_SEQUENCE ) )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_UNEXPECTED_TAG );
|
||||
|
||||
p = (unsigned char *) params->p;
|
||||
end = p + params->len;
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
/*
|
||||
* HashAlgorithm
|
||||
*/
|
||||
if( ( ret = asn1_get_tag( &p, end, &len,
|
||||
ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 0 ) ) == 0 )
|
||||
{
|
||||
end2 = p + len;
|
||||
|
||||
/* HashAlgorithm ::= AlgorithmIdentifier (without parameters) */
|
||||
if( ( ret = x509_get_alg_null( &p, end2, &alg_id ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( ( ret = oid_get_md_alg( &alg_id, md_alg ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p != end2 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||
}
|
||||
else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
/*
|
||||
* MaskGenAlgorithm
|
||||
*/
|
||||
if( ( ret = asn1_get_tag( &p, end, &len,
|
||||
ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 1 ) ) == 0 )
|
||||
{
|
||||
end2 = p + len;
|
||||
|
||||
/* MaskGenAlgorithm ::= AlgorithmIdentifier (params = HashAlgorithm) */
|
||||
if( ( ret = x509_get_alg( &p, end2, &alg_id, &alg_params ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
/* Only MFG1 is recognised for now */
|
||||
if( ! OID_CMP( OID_MGF1, &alg_id ) )
|
||||
return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE +
|
||||
POLARSSL_ERR_OID_NOT_FOUND );
|
||||
|
||||
/* Parse HashAlgorithm */
|
||||
if( ( ret = x509_get_hash_alg( &alg_params, mgf_md ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( p != end2 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||
}
|
||||
else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
/*
|
||||
* salt_len
|
||||
*/
|
||||
if( ( ret = asn1_get_tag( &p, end, &len,
|
||||
ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 2 ) ) == 0 )
|
||||
{
|
||||
end2 = p + len;
|
||||
|
||||
if( ( ret = asn1_get_int( &p, end2, salt_len ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p != end2 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||
}
|
||||
else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
/*
|
||||
* trailer_field (if present, must be 1)
|
||||
*/
|
||||
if( ( ret = asn1_get_tag( &p, end, &len,
|
||||
ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 3 ) ) == 0 )
|
||||
{
|
||||
int trailer_field;
|
||||
|
||||
end2 = p + len;
|
||||
|
||||
if( ( ret = asn1_get_int( &p, end2, &trailer_field ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p != end2 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
if( trailer_field != 1 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG );
|
||||
}
|
||||
else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG + ret );
|
||||
|
||||
if( p != end )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG +
|
||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_X509_RSASSA_PSS_SUPPORT */
|
||||
|
||||
/*
|
||||
* AttributeTypeAndValue ::= SEQUENCE {
|
||||
* type AttributeType,
|
||||
@ -261,7 +482,7 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
|
||||
|
||||
tag = **p;
|
||||
|
||||
if ( tag == ASN1_UTC_TIME )
|
||||
if( tag == ASN1_UTC_TIME )
|
||||
{
|
||||
(*p)++;
|
||||
ret = asn1_get_len( p, end, &len );
|
||||
@ -273,7 +494,7 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
|
||||
memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
|
||||
len : sizeof( date ) - 1 );
|
||||
|
||||
if( sscanf( date, "%2d%2d%2d%2d%2d%2d",
|
||||
if( sscanf( date, "%2d%2d%2d%2d%2d%2dZ",
|
||||
&time->year, &time->mon, &time->day,
|
||||
&time->hour, &time->min, &time->sec ) < 5 )
|
||||
return( POLARSSL_ERR_X509_INVALID_DATE );
|
||||
@ -285,7 +506,7 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
else if ( tag == ASN1_GENERALIZED_TIME )
|
||||
else if( tag == ASN1_GENERALIZED_TIME )
|
||||
{
|
||||
(*p)++;
|
||||
ret = asn1_get_len( p, end, &len );
|
||||
@ -297,7 +518,7 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
|
||||
memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
|
||||
len : sizeof( date ) - 1 );
|
||||
|
||||
if( sscanf( date, "%4d%2d%2d%2d%2d%2d",
|
||||
if( sscanf( date, "%4d%2d%2d%2d%2d%2dZ",
|
||||
&time->year, &time->mon, &time->day,
|
||||
&time->hour, &time->min, &time->sec ) < 5 )
|
||||
return( POLARSSL_ERR_X509_INVALID_DATE );
|
||||
@ -333,14 +554,51 @@ int x509_get_sig( unsigned char **p, const unsigned char *end, x509_buf *sig )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int x509_get_sig_alg( const x509_buf *sig_oid, md_type_t *md_alg,
|
||||
pk_type_t *pk_alg )
|
||||
/*
|
||||
* Get signature algorithm from alg OID and optional parameters
|
||||
*/
|
||||
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 )
|
||||
{
|
||||
int ret = oid_get_sig_alg( sig_oid, md_alg, pk_alg );
|
||||
int ret;
|
||||
|
||||
if( ret != 0 )
|
||||
if( *sig_opts != NULL )
|
||||
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ret = oid_get_sig_alg( sig_oid, md_alg, pk_alg ) ) != 0 )
|
||||
return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG + ret );
|
||||
|
||||
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
|
||||
if( *pk_alg == POLARSSL_PK_RSASSA_PSS )
|
||||
{
|
||||
pk_rsassa_pss_options *pss_opts;
|
||||
|
||||
pss_opts = polarssl_malloc( sizeof( pk_rsassa_pss_options ) );
|
||||
if( pss_opts == NULL )
|
||||
return( POLARSSL_ERR_X509_MALLOC_FAILED );
|
||||
|
||||
ret = x509_get_rsassa_pss_params( sig_params,
|
||||
md_alg,
|
||||
&pss_opts->mgf1_hash_id,
|
||||
&pss_opts->expected_salt_len );
|
||||
if( ret != 0 )
|
||||
{
|
||||
polarssl_free( pss_opts );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
*sig_opts = (void *) pss_opts;
|
||||
}
|
||||
else
|
||||
#endif /* POLARSSL_X509_RSASSA_PSS_SUPPORT */
|
||||
{
|
||||
/* Make sure parameters are absent or NULL */
|
||||
if( ( sig_params->tag != ASN1_NULL && sig_params->tag != 0 ) ||
|
||||
sig_params->len != 0 )
|
||||
return( POLARSSL_ERR_X509_INVALID_ALG );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
@ -444,7 +702,7 @@ int x509_load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
* This fuction tries to 'fix' this by at least suggesting enlarging the
|
||||
* size by 20.
|
||||
*/
|
||||
static int compat_snprintf(char *str, size_t size, const char *format, ...)
|
||||
static int compat_snprintf( char *str, size_t size, const char *format, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int res = -1;
|
||||
@ -456,29 +714,29 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
|
||||
va_end( ap );
|
||||
|
||||
// No quick fix possible
|
||||
if ( res < 0 )
|
||||
if( res < 0 )
|
||||
return( (int) size + 20 );
|
||||
|
||||
return res;
|
||||
return( res );
|
||||
}
|
||||
|
||||
#define snprintf compat_snprintf
|
||||
#endif
|
||||
#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
|
||||
|
||||
#define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL -2
|
||||
|
||||
#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; \
|
||||
#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; \
|
||||
}
|
||||
|
||||
/*
|
||||
@ -576,6 +834,51 @@ int x509_serial_gets( char *buf, size_t size, const x509_buf *serial )
|
||||
return( (int) ( size - n ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper for writing signature algorithms
|
||||
*/
|
||||
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 ret;
|
||||
char *p = buf;
|
||||
size_t n = size;
|
||||
const char *desc = NULL;
|
||||
|
||||
ret = oid_get_sig_alg_desc( sig_oid, &desc );
|
||||
if( ret != 0 )
|
||||
ret = snprintf( p, n, "???" );
|
||||
else
|
||||
ret = snprintf( p, n, "%s", desc );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
|
||||
if( pk_alg == POLARSSL_PK_RSASSA_PSS )
|
||||
{
|
||||
const pk_rsassa_pss_options *pss_opts;
|
||||
const md_info_t *md_info, *mgf_md_info;
|
||||
|
||||
pss_opts = (const pk_rsassa_pss_options *) sig_opts;
|
||||
|
||||
md_info = md_info_from_type( md_alg );
|
||||
mgf_md_info = md_info_from_type( pss_opts->mgf1_hash_id );
|
||||
|
||||
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
|
||||
md_info ? md_info->name : "???",
|
||||
mgf_md_info ? mgf_md_info->name : "???",
|
||||
pss_opts->expected_salt_len );
|
||||
SAFE_SNPRINTF();
|
||||
}
|
||||
#else
|
||||
((void) pk_alg);
|
||||
((void) md_alg);
|
||||
((void) sig_opts);
|
||||
#endif /* POLARSSL_X509_RSASSA_PSS_SUPPORT */
|
||||
|
||||
return( (int) size - n );
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper for writing "RSA key size", "EC key size", etc
|
||||
*/
|
||||
@ -586,7 +889,7 @@ int x509_key_size_helper( char *buf, size_t size, const char *name )
|
||||
int ret;
|
||||
|
||||
if( strlen( name ) + sizeof( " key size" ) > size )
|
||||
return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;
|
||||
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL );
|
||||
|
||||
ret = snprintf( p, n, "%s key size", name );
|
||||
SAFE_SNPRINTF();
|
||||
@ -620,78 +923,108 @@ int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid )
|
||||
* Return 0 if the x509_time is still valid, or 1 otherwise.
|
||||
*/
|
||||
#if defined(POLARSSL_HAVE_TIME)
|
||||
int x509_time_expired( const x509_time *to )
|
||||
{
|
||||
int year, mon, day;
|
||||
int hour, min, sec;
|
||||
|
||||
static void x509_get_current_time( x509_time *now )
|
||||
{
|
||||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
|
||||
SYSTEMTIME st;
|
||||
|
||||
GetLocalTime(&st);
|
||||
GetSystemTime( &st );
|
||||
|
||||
year = st.wYear;
|
||||
mon = st.wMonth;
|
||||
day = st.wDay;
|
||||
hour = st.wHour;
|
||||
min = st.wMinute;
|
||||
sec = st.wSecond;
|
||||
now->year = st.wYear;
|
||||
now->mon = st.wMonth;
|
||||
now->day = st.wDay;
|
||||
now->hour = st.wHour;
|
||||
now->min = st.wMinute;
|
||||
now->sec = st.wSecond;
|
||||
#else
|
||||
struct tm *lt;
|
||||
struct tm lt;
|
||||
time_t tt;
|
||||
|
||||
tt = time( NULL );
|
||||
lt = localtime( &tt );
|
||||
gmtime_r( &tt, < );
|
||||
|
||||
year = lt->tm_year + 1900;
|
||||
mon = lt->tm_mon + 1;
|
||||
day = lt->tm_mday;
|
||||
hour = lt->tm_hour;
|
||||
min = lt->tm_min;
|
||||
sec = lt->tm_sec;
|
||||
#endif
|
||||
now->year = lt.tm_year + 1900;
|
||||
now->mon = lt.tm_mon + 1;
|
||||
now->day = lt.tm_mday;
|
||||
now->hour = lt.tm_hour;
|
||||
now->min = lt.tm_min;
|
||||
now->sec = lt.tm_sec;
|
||||
#endif /* _WIN32 && !EFIX64 && !EFI32 */
|
||||
}
|
||||
|
||||
if( year > to->year )
|
||||
/*
|
||||
* Return 0 if before <= after, 1 otherwise
|
||||
*/
|
||||
static int x509_check_time( const x509_time *before, const x509_time *after )
|
||||
{
|
||||
if( before->year > after->year )
|
||||
return( 1 );
|
||||
|
||||
if( year == to->year &&
|
||||
mon > to->mon )
|
||||
if( before->year == after->year &&
|
||||
before->mon > after->mon )
|
||||
return( 1 );
|
||||
|
||||
if( year == to->year &&
|
||||
mon == to->mon &&
|
||||
day > to->day )
|
||||
if( before->year == after->year &&
|
||||
before->mon == after->mon &&
|
||||
before->day > after->day )
|
||||
return( 1 );
|
||||
|
||||
if( year == to->year &&
|
||||
mon == to->mon &&
|
||||
day == to->day &&
|
||||
hour > to->hour )
|
||||
if( before->year == after->year &&
|
||||
before->mon == after->mon &&
|
||||
before->day == after->day &&
|
||||
before->hour > after->hour )
|
||||
return( 1 );
|
||||
|
||||
if( year == to->year &&
|
||||
mon == to->mon &&
|
||||
day == to->day &&
|
||||
hour == to->hour &&
|
||||
min > to->min )
|
||||
if( before->year == after->year &&
|
||||
before->mon == after->mon &&
|
||||
before->day == after->day &&
|
||||
before->hour == after->hour &&
|
||||
before->min > after->min )
|
||||
return( 1 );
|
||||
|
||||
if( year == to->year &&
|
||||
mon == to->mon &&
|
||||
day == to->day &&
|
||||
hour == to->hour &&
|
||||
min == to->min &&
|
||||
sec > to->sec )
|
||||
if( before->year == after->year &&
|
||||
before->mon == after->mon &&
|
||||
before->day == after->day &&
|
||||
before->hour == after->hour &&
|
||||
before->min == after->min &&
|
||||
before->sec > after->sec )
|
||||
return( 1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int x509_time_expired( const x509_time *to )
|
||||
{
|
||||
x509_time now;
|
||||
|
||||
x509_get_current_time( &now );
|
||||
|
||||
return( x509_check_time( &now, to ) );
|
||||
}
|
||||
|
||||
int x509_time_future( const x509_time *from )
|
||||
{
|
||||
x509_time now;
|
||||
|
||||
x509_get_current_time( &now );
|
||||
|
||||
return( x509_check_time( from, &now ) );
|
||||
}
|
||||
|
||||
#else /* POLARSSL_HAVE_TIME */
|
||||
|
||||
int x509_time_expired( const x509_time *to )
|
||||
{
|
||||
((void) to);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int x509_time_future( const x509_time *from )
|
||||
{
|
||||
((void) from);
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_HAVE_TIME */
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST)
|
||||
@ -704,14 +1037,14 @@ int x509_time_expired( const x509_time *to )
|
||||
*/
|
||||
int x509_self_test( int verbose )
|
||||
{
|
||||
#if defined(POLARSSL_CERTS_C) && defined(POLARSSL_MD5_C)
|
||||
#if defined(POLARSSL_CERTS_C) && defined(POLARSSL_SHA1_C)
|
||||
int ret;
|
||||
int flags;
|
||||
x509_crt cacert;
|
||||
x509_crt clicert;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " X.509 certificate load: " );
|
||||
polarssl_printf( " X.509 certificate load: " );
|
||||
|
||||
x509_crt_init( &clicert );
|
||||
|
||||
@ -720,7 +1053,7 @@ int x509_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -732,27 +1065,27 @@ int x509_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n X.509 signature verify: ");
|
||||
polarssl_printf( "passed\n X.509 signature verify: ");
|
||||
|
||||
ret = x509_crt_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
printf("ret = %d, &flags = %04x\n", ret, flags);
|
||||
polarssl_printf( "ret = %d, &flags = %04x\n", ret, flags );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n\n");
|
||||
polarssl_printf( "passed\n\n");
|
||||
|
||||
x509_crt_free( &cacert );
|
||||
x509_crt_free( &clicert );
|
||||
@ -761,9 +1094,9 @@ int x509_self_test( int verbose )
|
||||
#else
|
||||
((void) verbose);
|
||||
return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE );
|
||||
#endif
|
||||
#endif /* POLARSSL_CERTS_C && POLARSSL_SHA1_C */
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* POLARSSL_SELF_TEST */
|
||||
|
||||
#endif /* POLARSSL_X509_USE_C */
|
||||
|
Reference in New Issue
Block a user