mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-11 05:15:34 +00:00
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:
parent
26f982f50e
commit
6eac11b007
|
@ -8752,3 +8752,6 @@ ssl_tls_prf:MBEDTLS_SSL_TLS_PRF_SHA384:"1234567890abcdef1234567890abcdef12345678
|
|||
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:
|
||||
|
|
|
@ -605,3 +605,50 @@ exit:
|
|||
mbedtls_free( output );
|
||||
}
|
||||
/* 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 */
|
||||
|
|
Loading…
Reference in a new issue