fix: allow session cache to be enabled before setting cache callbacks - #5985
fix: allow session cache to be enabled before setting cache callbacks#5985abidedavana wants to merge 4 commits into
Conversation
s2n_config_set_session_cache_onoff() previously only set use_session_cache when all three cache callbacks were already registered, and gave no feedback otherwise. Callbacks set after the call could never take effect, making the call order a silent sharp edge. Set use_session_cache unconditionally when enabling, and enforce the requirement that all three callbacks be present in s2n_allowed_to_cache_connection(), which already gates every use of the cache. This makes the callbacks and the on/off toggle order-independent while preserving NULL-callback safety.
|
Thanks for the contribution, this is a well-scoped fix! One request: could you add an end-to-end self-talk test that a session gets cached and resumed when the callbacks are set after s2n_config_set_session_cache_onoff()? s2n_self_talk_session_id_test.c is a good example to build on, with the correct ordering to exercise your fix. |
…e callbacks Requested in review: an end-to-end test that a session is cached and resumed when the cache callbacks are set after s2n_config_set_session_cache_onoff(). The new block mirrors the existing full-handshake and resumption blocks with a config that enables caching first. The block fails without the fix: the server never performs the cache lookup, so the expected S2N_ERR_ASYNC_BLOCKED never occurs.
Added the test ,new block at the end of s2n_self_talk_session_id_test.c. It sets the config up the other way round (cache on first, callbacks after), does a full handshake, then reconnects and resumes off the cached session. Checks the resumption handshake, that the session id matches, and that data still goes through. It fails without the fix, since the server never hits the cache. |
kaukabrizvi
left a comment
There was a problem hiding this comment.
I added a release summary note to the description as this changes behavior on the wire. Feel free to tweak as needed.
|
|
||
| /* Caching is not possible unless all three cache callbacks are set. | ||
| * The callbacks can be set before or after s2n_config_set_session_cache_onoff(). */ | ||
| if (!config->cache_store || !config->cache_retrieve || !config->cache_delete) { |
There was a problem hiding this comment.
After this change, the check here is the only thing keeping s2n_resume_from_cache and s2n_store_to_cache from callin a NULL callbakc (since neither null-checks the callback). For added defense, you might also consider adding POSIX_ENSURE_REF in those two functions as a backstop.
s2n_config_set_session_cache_onoff() previously only set use_session_cache when all three cache callbacks were already registered, and gave no feedback otherwise. Callbacks set after the call could never take effect, making the call order a silent sharp edge.
Set use_session_cache unconditionally when enabling, and enforce the requirement that all three callbacks be present in s2n_allowed_to_cache_connection(), which already gates every use of the cache. This makes the callbacks and the on/off toggle order-independent while preserving NULL-callback safety.
Goal
Make
s2n_config_set_session_cache_onoff()behave the same no matter when you set the cache callbacks.Why
Fixes the sharp edge from #3463 — if you call
s2n_config_set_session_cache_onoff()before setting the three cache callbacks, caching just silently stays off. The call still returns success, and setting the callbacks afterwards doesn't help, so there's no way to tell anything went wrong.How
s2n_config_set_session_cache_onoff()now setsuse_session_cacheunconditionally when enabling.s2n_allowed_to_cache_connection(), which already guards every path that actually calls the callbacks. So a config with caching on but no callbacks never hits a NULL callback, and behaves exactly like it did before this change.s2n.hand the usage guide, since both described the old ordering rule.Callouts
s2n_allowed_to_cache_connectionunit test was settingconfig->use_session_cache = 1directly to get around this exact issue; it goes through the public API now.Testing
s2n_resume_test.c: enable caching before any callbacks, register the callbacks one at a time (caching only kicks in once all three are there), then disable it again. The test fails without the fix.Related
resolves #3463
release summary: Session cache callbacks can now be set after s2n_config_set_session_cache_onoff(). Configs that previously enabled caching before setting callbacks will now cache sessions.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.