Merge remote-tracking branch 'origin/pr/589' into baremetal

This commit is contained in:
Simon Butcher 2019-07-23 16:10:56 +01:00
commit 6fe6b437da
4 changed files with 43 additions and 17 deletions

View File

@ -250,6 +250,7 @@ int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn );
*/ */
int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *serial ); int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *serial );
#if defined(MBEDTLS_HAVE_TIME_DATE)
/** /**
* \brief Check a given mbedtls_x509_time against the system time * \brief Check a given mbedtls_x509_time against the system time
* and tell if it's in the past. * and tell if it's in the past.
@ -277,6 +278,7 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
* 0 otherwise. * 0 otherwise.
*/ */
int mbedtls_x509_time_is_future( const mbedtls_x509_time *from ); int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
#endif /* MBEDTLS_HAVE_TIME_DATE */
/** /**
* \brief Free a dynamic linked list presentation of an X.509 name * \brief Free a dynamic linked list presentation of an X.509 name
@ -301,6 +303,20 @@ static inline void mbedtls_x509_sequence_free( mbedtls_x509_sequence *seq )
mbedtls_asn1_sequence_free( (mbedtls_asn1_sequence*) seq ); mbedtls_asn1_sequence_free( (mbedtls_asn1_sequence*) seq );
} }
#if !defined(MBEDTLS_HAVE_TIME_DATE)
static inline int mbedtls_x509_time_is_past( const mbedtls_x509_time *to )
{
((void) to);
return( 0 );
}
static inline int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
{
((void) from);
return( 0 );
}
#endif /* !MBEDTLS_HAVE_TIME_DATE */
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)
/** /**

View File

@ -235,8 +235,11 @@ typedef struct
/* for find_parent_in() */ /* for find_parent_in() */
mbedtls_x509_crt *parent; /* non-null iff parent_in in progress */ mbedtls_x509_crt *parent; /* non-null iff parent_in in progress */
#if defined(MBEDTLS_HAVE_TIME_DATE)
mbedtls_x509_crt *fallback_parent; mbedtls_x509_crt *fallback_parent;
int fallback_signature_is_good; int fallback_signature_is_good;
#endif /* MBEDTLS_HAVE_TIME_DATE */
/* for find_parent() */ /* for find_parent() */
int parent_is_trusted; /* -1 if find_parent is not in progress */ int parent_is_trusted; /* -1 if find_parent is not in progress */

View File

@ -1192,21 +1192,7 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
return( x509_check_time( from, &now ) ); return( x509_check_time( from, &now ) );
} }
#endif /* MBEDTLS_HAVE_TIME_DATE */
#else /* MBEDTLS_HAVE_TIME_DATE */
int mbedtls_x509_time_is_past( const mbedtls_x509_time *to )
{
((void) to);
return( 0 );
}
int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
{
((void) from);
return( 0 );
}
#endif /* MBEDTLS_HAVE_TIME_DATE */
void mbedtls_x509_name_free( mbedtls_x509_name *name ) void mbedtls_x509_name_free( mbedtls_x509_name *name )
{ {

View File

@ -2844,8 +2844,13 @@ static int x509_crt_find_parent_in(
mbedtls_x509_crt_restart_ctx *rs_ctx ) mbedtls_x509_crt_restart_ctx *rs_ctx )
{ {
int ret; int ret;
mbedtls_x509_crt *parent_crt, *fallback_parent; mbedtls_x509_crt *parent_crt;
int signature_is_good, fallback_signature_is_good; int signature_is_good;
#if defined(MBEDTLS_HAVE_TIME_DATE)
mbedtls_x509_crt *fallback_parent;
int fallback_signature_is_good;
#endif /* MBEDTLS_HAVE_TIME_DATE */
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
/* did we have something in progress? */ /* did we have something in progress? */
@ -2853,21 +2858,27 @@ static int x509_crt_find_parent_in(
{ {
/* restore saved state */ /* restore saved state */
parent_crt = rs_ctx->parent; parent_crt = rs_ctx->parent;
#if defined(MBEDTLS_HAVE_TIME_DATE)
fallback_parent = rs_ctx->fallback_parent; fallback_parent = rs_ctx->fallback_parent;
fallback_signature_is_good = rs_ctx->fallback_signature_is_good; fallback_signature_is_good = rs_ctx->fallback_signature_is_good;
#endif /* MBEDTLS_HAVE_TIME_DATE */
/* clear saved state */ /* clear saved state */
rs_ctx->parent = NULL; rs_ctx->parent = NULL;
#if defined(MBEDTLS_HAVE_TIME_DATE)
rs_ctx->fallback_parent = NULL; rs_ctx->fallback_parent = NULL;
rs_ctx->fallback_signature_is_good = 0; rs_ctx->fallback_signature_is_good = 0;
#endif /* MBEDTLS_HAVE_TIME_DATE */
/* resume where we left */ /* resume where we left */
goto check_signature; goto check_signature;
} }
#endif #endif
#if defined(MBEDTLS_HAVE_TIME_DATE)
fallback_parent = NULL; fallback_parent = NULL;
fallback_signature_is_good = 0; fallback_signature_is_good = 0;
#endif /* MBEDTLS_HAVE_TIME_DATE */
for( parent_crt = candidates; parent_crt != NULL; for( parent_crt = candidates; parent_crt != NULL;
parent_crt = parent_crt->next ) parent_crt = parent_crt->next )
@ -2918,8 +2929,10 @@ check_signature:
{ {
/* save state */ /* save state */
rs_ctx->parent = parent_crt; rs_ctx->parent = parent_crt;
#if defined(MBEDTLS_HAVE_TIME_DATE)
rs_ctx->fallback_parent = fallback_parent; rs_ctx->fallback_parent = fallback_parent;
rs_ctx->fallback_signature_is_good = fallback_signature_is_good; rs_ctx->fallback_signature_is_good = fallback_signature_is_good;
#endif /* MBEDTLS_HAVE_TIME_DATE */
return( ret ); return( ret );
} }
@ -2934,11 +2947,13 @@ check_signature:
/* optional time check */ /* optional time check */
if( !parent_valid ) if( !parent_valid )
{ {
#if defined(MBEDTLS_HAVE_TIME_DATE)
if( fallback_parent == NULL ) if( fallback_parent == NULL )
{ {
fallback_parent = parent_crt; fallback_parent = parent_crt;
fallback_signature_is_good = signature_is_good; fallback_signature_is_good = signature_is_good;
} }
#endif /* MBEDTLS_HAVE_TIME_DATE */
continue; continue;
} }
@ -2953,8 +2968,12 @@ check_signature:
} }
else else
{ {
#if defined(MBEDTLS_HAVE_TIME_DATE)
*r_parent = fallback_parent; *r_parent = fallback_parent;
*r_signature_is_good = fallback_signature_is_good; *r_signature_is_good = fallback_signature_is_good;
#else /* MBEDTLS_HAVE_TIME_DATE */
*r_parent = NULL;
#endif /* !MBEDTLS_HAVE_TIME_DATE */
} }
return( 0 ); return( 0 );
@ -3643,8 +3662,10 @@ void mbedtls_x509_crt_restart_init( mbedtls_x509_crt_restart_ctx *ctx )
mbedtls_pk_restart_init( &ctx->pk ); mbedtls_pk_restart_init( &ctx->pk );
ctx->parent = NULL; ctx->parent = NULL;
#if defined(MBEDTLS_HAVE_TIME_DATE)
ctx->fallback_parent = NULL; ctx->fallback_parent = NULL;
ctx->fallback_signature_is_good = 0; ctx->fallback_signature_is_good = 0;
#endif /* MBEDTLS_HAVE_TIME_DATE */
ctx->parent_is_trusted = -1; ctx->parent_is_trusted = -1;