Add option for ssl-context re-initialization flow

This commit is contained in:
Jarno Lamsa 2019-06-06 10:40:52 +03:00
parent bff4a91827
commit b5ff6a4ced
2 changed files with 53 additions and 6 deletions

View File

@ -282,7 +282,9 @@ int main( void )
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
#define USAGE_SERIALIZATION \
" serialize=%%d default: 0 (do not serialize/deserialize)\n"
" serialize=%%d default: 0 (do not serialize/deserialize)\n" \
" options: 1 (serialize)\n" \
" 2 (serialize with re-initialization)\n"
#else
#define USAGE_SERIALIZATION ""
#endif
@ -1229,7 +1231,7 @@ int main( int argc, char *argv[] )
else if( strcmp( p, "serialize") == 0 )
{
opt.serialize = atoi( q );
if( opt.serialize < 0 || opt.serialize > 1)
if( opt.serialize < 0 || opt.serialize > 2)
goto usage;
}
else
@ -2363,7 +2365,7 @@ send_request:
* 7c. Simulate serialize/deserialize and go back to data exchange
*/
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
if( opt.serialize != 0)
if( opt.serialize != 0 )
{
size_t len;
unsigned char *buf = NULL;
@ -2399,6 +2401,28 @@ send_request:
goto exit;
}
if( opt.serialize == 2 )
{
mbedtls_ssl_free( &ssl );
mbedtls_ssl_init( &ssl );
if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n",
-ret );
goto exit;
}
if( opt.nbio == 2 )
mbedtls_ssl_set_bio( &ssl, &server_fd, my_send, my_recv, NULL );
else
mbedtls_ssl_set_bio( &ssl, &server_fd,
mbedtls_net_send, mbedtls_net_recv,
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL );
}
mbedtls_printf( " Deserializing connection..." );
if( ( ret = mbedtls_ssl_context_load( &ssl, buf, len ) ) != 0 )

View File

@ -387,7 +387,9 @@ int main( void )
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
#define USAGE_SERIALIZATION \
" serialize=%%d default: 0 (do not serialize/deserialize)\n"
" serialize=%%d default: 0 (do not serialize/deserialize)\n" \
" options: 1 (serialize)\n" \
" 2 (serialize with re-initialization)\n"
#else
#define USAGE_SERIALIZATION ""
#endif
@ -1931,7 +1933,7 @@ int main( int argc, char *argv[] )
else if( strcmp( p, "serialize") == 0 )
{
opt.serialize = atoi( q );
if( opt.serialize < 0 || opt.serialize > 1)
if( opt.serialize < 0 || opt.serialize > 2)
goto usage;
}
else
@ -3348,7 +3350,7 @@ data_exchange:
* 7b. Simulate serialize/deserialize and go back to data exchange
*/
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
if( opt.serialize != 0)
if( opt.serialize != 0 )
{
size_t len;
unsigned char *buf = NULL;
@ -3384,6 +3386,27 @@ data_exchange:
goto exit;
}
if( opt.serialize == 2 )
{
mbedtls_ssl_free( &ssl );
mbedtls_ssl_init( &ssl );
if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n",
-ret );
goto exit;
}
if( opt.nbio == 2 )
mbedtls_ssl_set_bio( &ssl, &client_fd, my_send, my_recv, NULL );
else
mbedtls_ssl_set_bio( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv,
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL );
}
mbedtls_printf( " Deserializing connection..." );
if( ( ret = mbedtls_ssl_context_load( &ssl, buf, len ) ) != 0 )