tls: Refactor session storage for server mode
PATCH 1/3 tls: Refactor session storage for server mode
In TLS server mode we will need to store multiple session states in the session cache instead of only one like on the client. While the l_tls_set_session_cache() method is new use to opportunity to make incompatible changes: add the cache size limit parameter and strip "TLS" prefix from the setting names in the cache's l_settings object since the group name can include this part of the context without duplicating it across settings. Rename the group_name parameter to group_prefix since in server mode there will be a settings group per session cached so that we can use identical keys for each session. When removing a session remove the whole group rather than individual settings potentially leaving an empty group. Factor out the session loading code common to client and server into a function. When saving a server side session state skip the SessionID setting since the session ID is in the group name as the primary index. Add a boolean parameter to tls_forget_cached_session() to suppress the update_cb callback if needed, to allow the caller to make a single callback after multiple changes are made in the session cache instead of calling back after each individual change.
--- ell/tls-private.h | 3 +- ell/tls.c | 228 ++++++++++++++++++++++++++-------------------- ell/tls.h | 3 +- 3 files changed, 133 insertions(+), 101 deletions(-)
ell/tls-private.h +2 -1
@@ -219,8 +219,9 @@ struct l_tls {struct tls_cipher_suite **cipher_suite_pref_list;struct l_settings *session_settings; -char *session_group; +char *session_prefix;uint64_t session_lifetime; +unsigned int session_count_max;l_tls_session_update_cb_t session_update_cb;void *session_update_user_data;
ell/tls.c +129 -99
352 lines not on this page · raw message
ell/tls.h +2 -1
@@ -130,7 +130,8 @@ void l_tls_set_version_range(struct l_tls *tls,void l_tls_set_domain_mask (struct l_tls *tls,char **mask);void l_tls_set_session_cache (struct l_tls *tls,struct l_settings *settings, -const char *group_name,uint64_t lifetime, +const char *group_prefix,uint64_t lifetime, +unsigned int max_sessions,l_tls_session_update_cb_t update_cb,void *user_data);
Signature · 1 line
2.34.1
PATCH 2/3 tls: Server mode session caching
Cache session states when they're established, load them when parsing the ClientHello. When loading first expire old sessions, look up the requested session among those left and enforce the cache size limit by dropping the oldest session if cache is over limit.
--- ell/tls-private.h | 2 + ell/tls.c | 343 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 305 insertions(+), 40 deletions(-)
ell/tls-private.h +2 -0
@@ -260,6 +260,8 @@ struct l_tls {uint8_t session_id[32 ];size_t session_id_size; +uint8_t session_id_replaced[32 ]; +size_t session_id_size_replaced;bool session_id_new;uint8_t session_cipher_suite_id[2 ];uint8_t session_compression_method_id;
ell/tls.c +303 -40
488 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/3 examples: Update https example code
In reply to Andrew ZaborowskiUpdate the l_tls_set_session_cache call signature in https-client-test and add similar session caching support in https-server-test.
--- examples/https-client-test.c | 2 +- examples/https-server-test.c | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-)
examples/https-client-test.c +1 -1
@@ -238,7 +238,7 @@ int main(int argc, char *argv[])l_settings_load_from_file (session_cache, session_cache_path);l_tls_set_session_cache (tls, session_cache, hostname, -24 *3600 *L_USEC_PER_SEC , +24 *3600 *L_USEC_PER_SEC ,0 , https_tls_session_cache_update_cb,NULL ); }
examples/https-server-test.c +43 -0
67 lines not on this page · raw message
Signature · 1 line
2.34.1
Hi Andrew,
Quoted 18 lines · Andrew Zaborowski
In TLS server mode we will need to store multiple session states in the session cache instead of only one like on the client. While the
l_tls_set_session_cache()method is new use to opportunity to make incompatible changes: add the cache size limit parameter and strip "TLS" prefix from the setting names in the cache'sl_settingsobject since the group name can include this part of the context without duplicating it across settings. Rename thegroup_nameparameter togroup_prefixsince in server mode there will be a settings group per session cached so that we can use identical keys for each session. When removing a session remove the whole group rather than individual settings potentially leaving an empty group. Factor out the session loading code common to client and server into a function. When saving a server side session state skip the SessionID setting since the session ID is in the group name as the primary index. Add a boolean parameter totls_forget_cached_session()to suppress theupdate_cbcallback if needed, to allow the caller to make a single callback after multiple changes are made in the session cache instead of calling back after each individual change.
Quoted 6 lines
--- ell/tls-private.h | 3 +- ell/tls.c | 228 ++++++++++++++++++++++++++-------------------- ell/tls.h | 3 +- 3 files changed, 133 insertions(+), 101 deletions(-)
All applied, thanks.
Regards,
-Denis