Improve load-save test with tickets and certs
This commit is contained in:
parent
6eac11b007
commit
3caa6caf4a
2 changed files with 83 additions and 3 deletions
|
@ -8753,5 +8753,25 @@ SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 SHA-256 not enabled
|
|||
depends_on:!MBEDTLS_SHA256_C
|
||||
ssl_tls_prf:MBEDTLS_SSL_TLS_PRF_SHA256:"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef":"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef":"test tls_prf label":"7f9998393198a02c8d731ccc2ef90b2c":MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
|
||||
|
||||
Session serialisation, load-save
|
||||
ssl_serialise_session_load_save:
|
||||
Session serialisation, load-save: no ticket, no cert
|
||||
ssl_serialise_session_load_save:0:""
|
||||
|
||||
Session serialisation, load-save: small ticket, no cert
|
||||
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C
|
||||
ssl_serialise_session_load_save:42:""
|
||||
|
||||
Session serialisation, load-save: large ticket, no cert
|
||||
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C
|
||||
ssl_serialise_session_load_save:1023:""
|
||||
|
||||
Session serialisation, load-save: no ticket, cert
|
||||
depends_on:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
|
||||
ssl_serialise_session_load_save:0:"data_files/server5.crt"
|
||||
|
||||
Session serialisation, load-save: small ticket, cert
|
||||
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
|
||||
ssl_serialise_session_load_save:42:"data_files/server5.crt"
|
||||
|
||||
Session serialisation, load-save: large ticket, cert
|
||||
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
|
||||
ssl_serialise_session_load_save:1023:"data_files/server5.crt"
|
||||
|
|
|
@ -267,6 +267,63 @@ cleanup:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
/*
|
||||
* Populate a session structure for serialisation tests.
|
||||
* Choose dummy values, mostly non-0 to distinguish from the init default.
|
||||
*/
|
||||
static int ssl_populate_session( mbedtls_ssl_session *session,
|
||||
int ticket_len,
|
||||
const char *crt_file )
|
||||
{
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
session->start = mbedtls_time( NULL ) - 42;
|
||||
#endif
|
||||
session->ciphersuite = 0xabcd;
|
||||
session->compression = 1;
|
||||
session->id_len = sizeof( session->id );
|
||||
memset( session->id, 66, session->id_len );
|
||||
memset( session->master, 17, sizeof( session-> master ) );
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
if( strlen( crt_file ) != 0 )
|
||||
{
|
||||
int ret;
|
||||
ret = mbedtls_x509_crt_parse_file( session->peer_cert, crt_file );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
}
|
||||
#else
|
||||
(void) crt_file;
|
||||
#endif
|
||||
session->verify_result = 0xdeadbeef;
|
||||
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
|
||||
if( ticket_len != 0 )
|
||||
{
|
||||
session->ticket = mbedtls_calloc( 1, ticket_len );
|
||||
if( session-> ticket == NULL )
|
||||
return( -1 );
|
||||
memset( session->ticket, 33, ticket_len );
|
||||
}
|
||||
session->ticket_len = ticket_len;
|
||||
session->ticket_lifetime = 86401;
|
||||
#else
|
||||
(void) ticket_len;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||
session->mfl_code = 1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
||||
session->trunc_hmac = 1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
||||
session->encrypt_then_mac = 1;
|
||||
#endif
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
|
@ -607,7 +664,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ssl_serialise_session_load_save( )
|
||||
void ssl_serialise_session_load_save( int ticket_len, char *crt_file )
|
||||
{
|
||||
mbedtls_ssl_session session;
|
||||
unsigned char *buf1 = NULL, *buf2 = NULL;
|
||||
|
@ -619,6 +676,9 @@ void ssl_serialise_session_load_save( )
|
|||
|
||||
mbedtls_ssl_session_init( &session );
|
||||
|
||||
/* Prepare a dummy session to work on */
|
||||
ssl_populate_session( &session, ticket_len, crt_file );
|
||||
|
||||
/* Get desired buffer size for serialising */
|
||||
TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &len0 )
|
||||
== MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||
|
|
Loading…
Reference in a new issue