Fix and document corner-cases of time checking

This commit is contained in:
Manuel Pégourié-Gonnard 2015-06-22 19:15:32 +02:00
parent 57e10d71be
commit e7e89844d6
2 changed files with 16 additions and 10 deletions

View file

@ -238,24 +238,30 @@ 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 );
/** /**
* \brief Check a given mbedtls_x509_time against the system time and check * \brief Check a given mbedtls_x509_time against the system time
* if it is not expired. * and tell if it's in the past.
*
* \note Intended usage is "if( is_past( valid_to ) ) ERROR".
* Hence the return value of 1 if on internal errors.
* *
* \param time mbedtls_x509_time to check * \param time mbedtls_x509_time to check
* *
* \return 0 if the mbedtls_x509_time is still valid, * \return 1 if the given time is in the past or an error occured,
* 1 otherwise. * 0 otherwise.
*/ */
int mbedtls_x509_time_is_past( const mbedtls_x509_time *time ); int mbedtls_x509_time_is_past( const mbedtls_x509_time *time );
/** /**
* \brief Check a given mbedtls_x509_time against the system time and check * \brief Check a given mbedtls_x509_time against the system time
* if it is not from the future. * and tell if it's in the future.
*
* \note Intended usage is "if( is_future( valid_from ) ) ERROR".
* Hence the return value of 1 if on internal errors.
* *
* \param time mbedtls_x509_time to check * \param time mbedtls_x509_time to check
* *
* \return 0 if the mbedtls_x509_time is already valid, * \return 1 if the given time is in the future or an error occured,
* 1 otherwise. * 0 otherwise.
*/ */
int mbedtls_x509_time_is_future( const mbedtls_x509_time *time ); int mbedtls_x509_time_is_future( const mbedtls_x509_time *time );

View file

@ -922,7 +922,7 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to )
mbedtls_x509_time now; mbedtls_x509_time now;
if( x509_get_current_time( &now ) != 0 ) if( x509_get_current_time( &now ) != 0 )
return( -1 ); return( 1 );
return( x509_check_time( &now, to ) ); return( x509_check_time( &now, to ) );
} }
@ -932,7 +932,7 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
mbedtls_x509_time now; mbedtls_x509_time now;
if( x509_get_current_time( &now ) != 0 ) if( x509_get_current_time( &now ) != 0 )
return( -1 ); return( 1 );
return( x509_check_time( from, &now ) ); return( x509_check_time( from, &now ) );
} }