1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-08 17:42:09 +03:00

Merge pull request #3624 from daxtens/timeless

RFC: Fix builds with MBEDTLS_HAVE_TIME disabled and test
This commit is contained in:
Dave Rodgman
2022-03-15 16:43:19 +00:00
committed by GitHub
19 changed files with 127 additions and 15 deletions

View File

@@ -5,11 +5,13 @@
#include <stdlib.h>
#include "mbedtls/ctr_drbg.h"
#if defined(MBEDTLS_PLATFORM_TIME_ALT)
mbedtls_time_t dummy_constant_time( mbedtls_time_t* time )
{
(void) time;
return 0x5af2a056;
}
#endif
void dummy_init()
{

View File

@@ -1,4 +1,9 @@
#include "mbedtls/build_info.h"
#if defined(MBEDTLS_HAVE_TIME)
#include "mbedtls/platform_time.h"
#endif
#include <stddef.h>
#include <stdint.h>
typedef struct fuzzBufferOffset
@@ -8,7 +13,9 @@ typedef struct fuzzBufferOffset
size_t Offset;
} fuzzBufferOffset_t;
#if defined(MBEDTLS_HAVE_TIME)
mbedtls_time_t dummy_constant_time( mbedtls_time_t* time );
#endif
void dummy_init();
int dummy_send( void *ctx, const unsigned char *buf, size_t len );

View File

@@ -42,7 +42,9 @@ int main( void )
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#if defined(MBEDTLS_HAVE_TIME)
#include <time.h>
#endif
#include "mbedtls/ssl.h"
#include "mbedtls/error.h"
#include "mbedtls/base64.h"
@@ -307,10 +309,11 @@ void print_hex( const uint8_t *b, size_t len,
/*
* Print the value of time_t in format e.g. 2020-01-23 13:05:59
*/
void print_time( const time_t *time )
void print_time( const uint64_t *time )
{
#if defined(MBEDTLS_HAVE_TIME)
char buf[20];
struct tm *t = gmtime( time );
struct tm *t = gmtime( (time_t*) time );
static const char format[] = "%Y-%m-%d %H:%M:%S";
if( NULL != t )
{
@@ -321,6 +324,10 @@ void print_time( const time_t *time )
{
printf( "unknown\n" );
}
#else
(void) time;
printf( "not supported\n" );
#endif
}
/*
@@ -608,7 +615,7 @@ void print_deserialized_ssl_session( const uint8_t *ssl, uint32_t len,
( (uint64_t) ssl[7] );
ssl += 8;
printf( "\tstart time : " );
print_time( (time_t*) &start );
print_time( &start );
}
CHECK_SSL_END( 2 );

View File

@@ -317,10 +317,16 @@ int main( void )
#if defined(MBEDTLS_SSL_CACHE_C)
#define USAGE_CACHE \
" cache_max=%%d default: cache default (50)\n" \
" cache_max=%%d default: cache default (50)\n"
#if defined(MBEDTLS_HAVE_TIME)
#define USAGE_CACHE_TIME \
" cache_timeout=%%d default: cache default (1d)\n"
#else
#define USAGE_CACHE_TIME ""
#endif
#else
#define USAGE_CACHE ""
#define USAGE_CACHE_TIME ""
#endif /* MBEDTLS_SSL_CACHE_C */
#if defined(SNI_OPTION)
@@ -509,6 +515,7 @@ int main( void )
USAGE_NSS_KEYLOG \
USAGE_NSS_KEYLOG_FILE \
USAGE_CACHE \
USAGE_CACHE_TIME \
USAGE_MAX_FRAG_LEN \
USAGE_ALPN \
USAGE_EMS \
@@ -619,7 +626,9 @@ struct options
int ticket_timeout; /* session ticket lifetime */
int ticket_aead; /* session ticket protection */
int cache_max; /* max number of session cache entries */
int cache_timeout; /* expiration delay of session cache entries */
#if defined(MBEDTLS_HAVE_TIME)
int cache_timeout; /* expiration delay of session cache entries*/
#endif
char *sni; /* string describing sni information */
const char *curves; /* list of supported elliptic curves */
const char *sig_algs; /* supported TLS 1.3 signature algorithms */
@@ -1581,7 +1590,9 @@ int main( int argc, char *argv[] )
opt.ticket_timeout = DFL_TICKET_TIMEOUT;
opt.ticket_aead = DFL_TICKET_AEAD;
opt.cache_max = DFL_CACHE_MAX;
#if defined(MBEDTLS_HAVE_TIME)
opt.cache_timeout = DFL_CACHE_TIMEOUT;
#endif
opt.sni = DFL_SNI;
opt.alpn_string = DFL_ALPN_STRING;
opt.curves = DFL_CURVES;
@@ -1977,12 +1988,14 @@ int main( int argc, char *argv[] )
if( opt.cache_max < 0 )
goto usage;
}
#if defined(MBEDTLS_HAVE_TIME)
else if( strcmp( p, "cache_timeout" ) == 0 )
{
opt.cache_timeout = atoi( q );
if( opt.cache_timeout < 0 )
goto usage;
}
#endif
else if( strcmp( p, "cookies" ) == 0 )
{
opt.cookies = atoi( q );
@@ -2755,8 +2768,10 @@ int main( int argc, char *argv[] )
if( opt.cache_max != -1 )
mbedtls_ssl_cache_set_max_entries( &cache, opt.cache_max );
#if defined(MBEDTLS_HAVE_TIME)
if( opt.cache_timeout != -1 )
mbedtls_ssl_cache_set_timeout( &cache, opt.cache_timeout );
#endif
mbedtls_ssl_conf_session_cache( &conf, &cache,
mbedtls_ssl_cache_get,

View File

@@ -46,11 +46,13 @@ void my_debug( void *ctx, int level,
fflush( (FILE *) ctx );
}
#if defined(MBEDTLS_HAVE_TIME)
mbedtls_time_t dummy_constant_time( mbedtls_time_t* time )
{
(void) time;
return 0x5af2a056;
}
#endif
#if !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
static int dummy_entropy( void *data, unsigned char *output, size_t len )

View File

@@ -129,7 +129,9 @@ void my_debug( void *ctx, int level,
const char *file, int line,
const char *str );
#if defined(MBEDTLS_HAVE_TIME)
mbedtls_time_t dummy_constant_time( mbedtls_time_t* time );
#endif
#if defined(MBEDTLS_USE_PSA_CRYPTO)
/* If MBEDTLS_TEST_USE_PSA_CRYPTO_RNG is defined, the SSL test programs will use

View File

@@ -30,10 +30,10 @@
#define mbedtls_free free
#endif
#if !defined(MBEDTLS_TIMING_C)
#if !defined(MBEDTLS_HAVE_TIME)
int main( void )
{
mbedtls_printf("MBEDTLS_TIMING_C not defined.\n");
mbedtls_printf("MBEDTLS_HAVE_TIME not defined.\n");
mbedtls_exit( 0 );
}
#else
@@ -41,8 +41,6 @@ int main( void )
#include <string.h>
#include <stdlib.h>
#include "mbedtls/timing.h"
#include "mbedtls/md5.h"
#include "mbedtls/ripemd160.h"
#include "mbedtls/sha1.h"
@@ -1304,4 +1302,4 @@ int main( int argc, char *argv[] )
mbedtls_exit( 0 );
}
#endif /* MBEDTLS_TIMING_C */
#endif /* MBEDTLS_HAVE_TIME */

View File

@@ -32,9 +32,11 @@
#else
#include <stdio.h>
#include <stdlib.h>
#if defined(MBEDTLS_HAVE_TIME)
#include <time.h>
#define mbedtls_time time
#define mbedtls_time_t time_t
#endif
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
@@ -71,7 +73,9 @@ int main( void )
#endif
#endif /* _MSC_VER */
#else /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
#if defined(MBEDTLS_HAVE_TIME)
#include <sys/time.h>
#endif
#include <sys/types.h>
#include <unistd.h>
#endif /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
@@ -821,6 +825,7 @@ int main( int argc, char *argv[] )
get_options( argc, argv );
#if defined(MBEDTLS_HAVE_TIME)
/*
* Decisions to drop/delay/duplicate packets are pseudo-random: dropping
* exactly 1 in N packets would lead to problems when a flight has exactly
@@ -831,11 +836,12 @@ int main( int argc, char *argv[] )
*/
if( opt.seed == 0 )
{
opt.seed = (unsigned int) time( NULL );
opt.seed = (unsigned int) mbedtls_time( NULL );
mbedtls_printf( " . Pseudo-random seed: %u\n", opt.seed );
}
srand( opt.seed );
#endif /* MBEDTLS_HAVE_TIME */
/*
* 0. "Connect" to the server