1
0
mirror of https://github.com/wolfSSL/wolfssl.git synced 2026-10-28 17:15:09 +03:00
Commit Graph

12 Commits

Author SHA1 Message Date
philljj
6a14dcde8b Merge pull request #11538 from gasbytes/wolfssl_session_dup-fix
Make session copy fail when the peer cert copy fails, and always copy the ticket
2026-10-13 08:45:48 -05:00
Yosuke Shimizu
016e6ee311 session: initialize the external cache copy flag to 1
- GetSessionFromCache(), GetSesionFromCacheOrExt() and
  TlsSessionIdIsValid() initialize to 1 the copy flag passed to
  ctx->get_sess_cb().
- GetSesionFromCacheOrExt() takes a reference with
  wolfSSL_SESSION_up_ref() when the callback leaves copy set and
  treats a session it cannot reference as a lookup miss. It sets
  freeCtx->extCache and freeCtx->freeSess together, so
  FreeSessionFromCacheOrExt() releases one reference.
- Comments restating the copy flag's contract are removed, or
  replaced with one naming the reference released.
- ssl.h dox comments, English and Japanese, document
  wolfSSL_CTX_sess_set_get_cb() and both values of its copy flag.
- tests/api/test_session.c and test_session.h add
  test_wolfSSL_CTX_sess_get_cb_default_copy(): a TLS 1.2 resume
  with copy left alone checks the reference count is unchanged, a
  second with copy cleared checks wolfSSL releases exactly one.

Issue: F-14055
2026-10-07 19:30:09 +09:00
Tobias Frauenschläger
70090dcb38 Make the deprecated wolfSSL_get_session() cache reference opt-in
Without NO_SESSION_CACHE_REF, wolfSSL_get_session() returns a reference into
the process-global client cache rather than a session object. That reference
is valid only while the slot it names still holds the session it was issued
for, which the caller cannot observe, so the safe use of the API is the one
the macro selects. Only the integration recipes defined it, and none of them
for that reason: --enable-opensslextra and --enable-opensslall, which is what
an application written against SSL_get_session() reaches for, left it unset.

settings.h now defines NO_SESSION_CACHE_REF unless WOLFSSL_SESSION_CACHE_REF
is defined, so every build selects it, including the user_settings.h, IDE and
bare-metal builds that have no configure step. Putting the rule in the header
rather than only in configure and CMake means no project has to add a macro to
keep the safe behaviour, and the ones that want the deprecated reference ask
for it instead. --enable-session-cache-ref and -DWOLFSSL_SESSION_CACHE_REF=yes
define that opt-in macro, and options.h records it alongside the negative one
so an application cannot disagree with the library it links.

A build that opts in warns at compile time and the warning names
WOLFSSL_SESSION_CACHE_REF_WARNED, which silences it while keeping the path. It
sits inside the NO_SESSION_CACHE region, so a build without a session cache
and a wolfCrypt-only build stay quiet, and it takes the #warning / #pragma
message form already used for WOLFSSL_KEYLOG_EXPORT_WARNED.

The recipes that define NO_SESSION_CACHE_REF on their own keep doing so and
still win over the option. Both build systems say so rather than leaving a
reported option disagreeing with the build: configure warns and clears its
summary line, CMake warns and syncs the cached option. configure also treats
TITAN_SESSION_CACHE as a conflict, because settings.h derives the macro from
it and that never reaches the compile line for a flag scan to find.

The os-check session-cache-ref entry existed because --enable-opensslextra
left the macro unset. It now asks for the reference path explicitly, or
test_wolfSSL_client_cache_id_overwrite would skip and the generation check
added with it would be covered nowhere.

Anything migrating has one lifetime difference to mind: the deprecated
reference stayed valid after wolfSSL_free(), the session object does not, so
code holding the result of wolfSSL_get_session() past the WOLFSSL it came from
has to move to wolfSSL_get1_session() and wolfSSL_SESSION_free().
2026-09-30 08:33:30 +02:00
Tobias Frauenschläger
13987d6107 Populate the client session cache regardless of NO_SESSION_CACHE_REF
NO_SESSION_CACHE_REF is documented as choosing what wolfSSL_get_session()
returns, but it also stopped AddSession() from writing the ClientCache. One
field, ssl->clientSession, is both the handle handed back and the
out-parameter whose presence makes AddSessionToCache() call
AddSessionToClientCache(), so suppressing the handle suppressed the write.

Nothing then populated that cache while wolfSSL_GetSessionClient() went on
searching it, and it is the only consumer, reached from wolfSSL_SetServerID()
with newSession 0. Resumption by server ID therefore never resumed in a build
defining the macro: no error, no log, just a full handshake every time. That
covers --enable-curl, --enable-nginx, --enable-all and the other
OpenSSL-compatibility recipes, all of which have defined it for years.

Gate the write on NO_CLIENT_CACHE, which is what declares the field, and leave
only the wolfSSL_get_session() return value behind NO_SESSION_CACHE_REF. No
code reads ssl->clientSession when the macro is defined, so filling it in is
invisible to callers. CLIENT_SESSIONS_MULTIPLIER stays at 1 under the macro:
its value of 8 exists to make a stale handle less likely to resolve, which
cannot happen when no handle is issued, so the footprint does not change.

The test drives the documented flow rather than the cache API, since the
existing client-cache tests call AddSessionToCache() themselves with a
non-NULL entry and so pass either way. It records a server ID before the
handshake, then asks a second connection on the same contexts to resume by
that ID, and checks the master secret and wolfSSL_session_reused(). An
uncached ID is the negative control. It is not gated on NO_SESSION_CACHE_REF
and runs in both configurations.
2026-09-30 08:33:18 +02:00
JacobBarthelmeh
dc2e9f1383 Merge pull request #11403 from yosuke-wolfssl/fix/f_13440
ssl_api_ext: lock ticket key context in the public key APIs
2026-09-29 22:20:52 -06:00
Reda Chouk
d948c4404d - fix wolfSSL_SESSION_dup reporting success when copying the peer cert fails
- fix wolfSSL_DupSessionEx leaving stale bytes when a short ticket reuses a cached buffer
2026-09-29 14:48:10 +02:00
jordan
5e8c85b489 ssl_sess: sanitize session cache save and restore, copy full session row, and add unit tests. 2026-09-21 15:16:48 -05:00
Tobias Frauenschläger
2067a14924 Bind a client session cache reference to the entry contents it was issued for
Without NO_SESSION_CACHE_REF, wolfSSL_get_session() hands back a ClientSession
reference into the process-global cache rather than a session object, and
ClientSessionToSession() resolves it against nothing but a hash of the entry's
session ID. That ID does not change when the entry is overwritten, so a
reference kept across an overwrite still resolved, to contents it was never
issued for.

Give every cache write a generation number and record it in the ClientSession,
so a reference resolves only while the entry still holds the contents it was
issued for. The numbers come from a counter on the SessionRow rather than from
the entry, so that under SESSION_CACHE_DYNAMIC_MEM a freed and reallocated
entry cannot restart at a value an outstanding reference still holds.

The generation is not advanced when an overwrite carries the same master
secret, the benign re-add of an unchanged session; without that an older
reference would silently fall back to a full handshake. The comparison runs
through ConstantCompare so its timing says nothing about the cached secret.

WOLFSSL_CACHE_VERSION goes to 3: the ClientCache, the SessionRow prefix and
the WOLFSSL_SESSION layouts written by the session-cache save functions all
change.

The test builds the sequence out of two real handshakes on separate contexts,
behind two controls so it cannot pass by refusing everything. Every profile in
the os-check matrix that builds the unit tests defines NO_SESSION_CACHE_REF,
which compiles the reference path out, so a session-cache-ref entry configures
one that does not.
2026-09-19 16:37:57 +02:00
Juliusz Sosinowicz
c1982d36ed Match the full server ID length in the client session cache
wolfSSL_GetSessionClient() compared only the requested number of bytes, so a
short server ID could match a cached entry that merely started with the same
bytes and landed in the same cache row. Applications partitioning the cache
with wolfSSL_SetServerID() could then offer a ticket across partitions,
against RFC 9846 Appendix C.4.

Fixes https://github.com/wolfSSL/wolfssl/issues/11132
2026-09-10 05:43:26 +00:00
Yosuke Shimizu
0458577b33 ssl_api_ext: lock ticket key context in the public key APIs
- wolfSSL_CTX_get_tlsext_ticket_keys() and
  wolfSSL_CTX_set_tlsext_ticket_keys() hold ticketKeyCtx.mutex across
  the name, key and expirary copy and return WOLFSSL_FAILURE when the
  lock fails, under !SINGLE_THREADED. The @return line of each names
  that failure.
- The #if around both functions in src/ssl_api_ext.c and around their
  prototypes in wolfssl/ssl.h adds !defined(NO_TLS).
- tests/api/test_session.c gains test_wolfSSL_ticket_keys_threaded(),
  a writer thread rotating two key blobs against a reader asserting
  each get returns one blob whole and that both blobs were seen.
  Declared and registered in tests/api/test_session.h.

Issue: F-13440
2026-09-09 09:45:23 +09:00
Kareem
4544e3bacd Avoid aliasing the ticket in wolfSSL_GetSessionAtIndex.
Thanks to Clouditera Security; Z.ai Security; NSFOCUS for the report.
2026-08-03 13:30:43 -07:00
Sean Parkinson
c674cec4ac api.c: move out tests into other files
Move out DTLS 1.3 specific tests into test_dtls13.c. (Also move out from
test_dtls.c)
Move out DTLS tests into test_dtls.c.
Move out LMS and XMSS tests into test_lms_xmss.c.
Move out SSL session tests into test_session.c.
Move out remaining ML-DSA/Dilithium tests in api.c into test_mldsa.c.
2026-05-28 19:34:09 +10:00