From 5cb3308e5fa16a43c52e5230f8e38017933bbfad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 6 May 2015 18:06:26 +0100 Subject: [PATCH] Merge contexts for session cache --- ChangeLog | 2 ++ include/mbedtls/ssl.h | 11 +++++------ library/ssl_srv.c | 2 +- library/ssl_tls.c | 10 +++++----- programs/ssl/dtls_server.c | 6 +++--- programs/ssl/ssl_server.c | 6 +++--- programs/ssl/ssl_server2.c | 6 +++--- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8957110c5..0b3735c42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,8 @@ API Changes mbedtls_ctr_drbg_init() -> mbedtls_ctr_drbg_init(_buf)() * mbedtls_ssl_set_ca_chain() lost its last argument (peer_cn), now set using mbedtls_ssl_set_hostname(). + * mbedtls_ssl_set_session_cached() changed prototype (only one context + pointer, parameters reordered). * mbedtls_memory_bufer_alloc_init() now returns void * In the threading layer, mbedtls_mutex_init() and mbedtls_mutex_free() now return void. diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h index 6ab2dd2e9..b72ba92e2 100644 --- a/include/mbedtls/ssl.h +++ b/include/mbedtls/ssl.h @@ -807,10 +807,9 @@ typedef struct /** Callback to retrieve a session from the cache */ int (*f_get_cache)(void *, mbedtls_ssl_session *); - void *p_get_cache; /*!< context for cache retrieval */ /** Callback to store a session into the cache */ int (*f_set_cache)(void *, const mbedtls_ssl_session *); - void *p_set_cache; /*!< context for cache store */ + void *p_cache; /*!< context for cache callbacks */ #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) /** Callback for setting cert according to SNI extension */ @@ -1482,14 +1481,14 @@ void mbedtls_ssl_set_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, * successfully cached, return 1 otherwise. * * \param conf SSL configuration + * \param p_cache parmater (context) for both callbacks * \param f_get_cache session get callback - * \param p_get_cache session get parameter * \param f_set_cache session set callback - * \param p_set_cache session set parameter */ void mbedtls_ssl_set_session_cache( mbedtls_ssl_config *conf, - int (*f_get_cache)(void *, mbedtls_ssl_session *), void *p_get_cache, - int (*f_set_cache)(void *, const mbedtls_ssl_session *), void *p_set_cache ); + void *p_cache, + int (*f_get_cache)(void *, mbedtls_ssl_session *), + int (*f_set_cache)(void *, const mbedtls_ssl_session *) ); #endif /* MBEDTLS_SSL_SRV_C */ #if defined(MBEDTLS_SSL_CLI_C) diff --git a/library/ssl_srv.c b/library/ssl_srv.c index c537fe4b2..fd2ee9364 100644 --- a/library/ssl_srv.c +++ b/library/ssl_srv.c @@ -2475,7 +2475,7 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl ) #endif ssl->session_negotiate->length != 0 && ssl->conf->f_get_cache != NULL && - ssl->conf->f_get_cache( ssl->conf->p_get_cache, ssl->session_negotiate ) == 0 ) + ssl->conf->f_get_cache( ssl->conf->p_cache, ssl->session_negotiate ) == 0 ) { MBEDTLS_SSL_DEBUG_MSG( 3, ( "session successfully restored from cache" ) ); ssl->handshake->resume = 1; diff --git a/library/ssl_tls.c b/library/ssl_tls.c index c0f52925d..85aa27614 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -4575,7 +4575,7 @@ void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl ) ssl->session->length != 0 && resume == 0 ) { - if( ssl->conf->f_set_cache( ssl->conf->p_set_cache, ssl->session ) != 0 ) + if( ssl->conf->f_set_cache( ssl->conf->p_cache, ssl->session ) != 0 ) MBEDTLS_SSL_DEBUG_MSG( 1, ( "cache did not store session" ) ); } @@ -5245,13 +5245,13 @@ void mbedtls_ssl_set_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout ) #if defined(MBEDTLS_SSL_SRV_C) void mbedtls_ssl_set_session_cache( mbedtls_ssl_config *conf, - int (*f_get_cache)(void *, mbedtls_ssl_session *), void *p_get_cache, - int (*f_set_cache)(void *, const mbedtls_ssl_session *), void *p_set_cache ) + void *p_cache, + int (*f_get_cache)(void *, mbedtls_ssl_session *), + int (*f_set_cache)(void *, const mbedtls_ssl_session *) ) { + conf->p_cache = p_cache; conf->f_get_cache = f_get_cache; - conf->p_get_cache = p_get_cache; conf->f_set_cache = f_set_cache; - conf->p_set_cache = p_set_cache; } #endif /* MBEDTLS_SSL_SRV_C */ diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c index ef899e482..6ad4e661b 100644 --- a/programs/ssl/dtls_server.c +++ b/programs/ssl/dtls_server.c @@ -210,9 +210,9 @@ int main( void ) mbedtls_ssl_set_dbg( &conf, my_debug, stdout ); #if defined(MBEDTLS_SSL_CACHE_C) - mbedtls_ssl_set_session_cache( &conf, - mbedtls_ssl_cache_get, &cache, - mbedtls_ssl_cache_set, &cache ); + mbedtls_ssl_set_session_cache( &conf, &cache, + mbedtls_ssl_cache_get, + mbedtls_ssl_cache_set ); #endif mbedtls_ssl_set_ca_chain( &conf, srvcert.next, NULL ); diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c index c11fbd5da..9313a88e0 100644 --- a/programs/ssl/ssl_server.c +++ b/programs/ssl/ssl_server.c @@ -209,9 +209,9 @@ int main( void ) mbedtls_ssl_set_dbg( &conf, my_debug, stdout ); #if defined(MBEDTLS_SSL_CACHE_C) - mbedtls_ssl_set_session_cache( &conf, - mbedtls_ssl_cache_get, &cache, - mbedtls_ssl_cache_set, &cache ); + mbedtls_ssl_set_session_cache( &conf, &cache, + mbedtls_ssl_cache_get, + mbedtls_ssl_cache_set ); #endif mbedtls_ssl_set_ca_chain( &conf, srvcert.next, NULL ); diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 68fc81eb1..9a6d7f3ff 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -1584,9 +1584,9 @@ int main( int argc, char *argv[] ) if( opt.cache_timeout != -1 ) mbedtls_ssl_cache_set_timeout( &cache, opt.cache_timeout ); - mbedtls_ssl_set_session_cache( &conf, - mbedtls_ssl_cache_get, &cache, - mbedtls_ssl_cache_set, &cache ); + mbedtls_ssl_set_session_cache( &conf, &cache, + mbedtls_ssl_cache_get, + mbedtls_ssl_cache_set ); #endif #if defined(MBEDTLS_SSL_SESSION_TICKETS)