Start adding unit test for session serialisation

This initial test ensures that a load-save function is the identity. It is so
far incomplete in that it only tests sessions without tickets or certificate.
This will be improved in the next commits.
This commit is contained in:
Manuel Pégourié-Gonnard 2019-05-23 09:30:55 +02:00
parent 32ce596c35
commit dfa5a7ae76
2 changed files with 50 additions and 0 deletions

View file

@ -8713,3 +8713,6 @@ ssl_crypt_record_small:MBEDTLS_CIPHER_NULL:MBEDTLS_MD_MD5:0:1:MBEDTLS_SSL_MINOR_
Record crypt, little space, NULL cipher, SSL3, MD5, short tag, EtM
depends_on:MBEDTLS_CIPHER_NULL_CIPHER:MBEDTLS_SSL_PROTO_SSL3:MBEDTLS_MD5_C:MBEDTLS_SSL_ENCRYPT_THEN_MAC
ssl_crypt_record_small:MBEDTLS_CIPHER_NULL:MBEDTLS_MD_MD5:1:1:MBEDTLS_SSL_MINOR_VERSION_0:0:0
Session serialisation, load-save
ssl_serialise_session_load_save:

View file

@ -575,3 +575,50 @@ exit:
mbedtls_free( buf );
}
/* END_CASE */
/* BEGIN_CASE */
void ssl_serialise_session_load_save( )
{
mbedtls_ssl_session session;
unsigned char *buf1 = NULL, *buf2 = NULL;
size_t len0, len1, len2;
/*
* Test that a load-save pair is the identity
*/
mbedtls_ssl_session_init( &session );
/* Get desired buffer size for serialising */
TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &len0 )
== MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
/* Allocate first buffer */
buf1 = mbedtls_calloc( 1, len0 );
TEST_ASSERT( buf1 != NULL );
/* Serialise to buffer and free session lived session */
TEST_ASSERT( mbedtls_ssl_session_save( &session, buf1, len0, &len1 )
== 0 );
TEST_ASSERT( len0 == len1 );
mbedtls_ssl_session_free( &session );
/* Restore session from serialised data */
TEST_ASSERT( mbedtls_ssl_session_load( &session, buf1, len1) == 0 );
/* Allocate second buffer and serialise to it */
buf2 = mbedtls_calloc( 1, len0 );
TEST_ASSERT( buf1 != NULL );
TEST_ASSERT( mbedtls_ssl_session_save( &session, buf2, len0, &len2 )
== 0 );
/* Make sure both serialised versions are identical */
TEST_ASSERT( len1 == len2 );
TEST_ASSERT( memcmp( buf1, buf2, len1 ) == 0 );
exit:
mbedtls_ssl_session_free( &session );
mbedtls_free( buf1 );
mbedtls_free( buf2 );
}
/* END_CASE */