Skip to content

ssl_sess: sanity test session cache save and restore. - #11070

Open
philljj wants to merge 1 commit into
wolfSSL:masterfrom
philljj:sanity_session
Open

ssl_sess: sanity test session cache save and restore.#11070
philljj wants to merge 1 commit into
wolfSSL:masterfrom
philljj:sanity_session

Conversation

@philljj

@philljj philljj commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

  • Add unit tests for mem[save, restore]_session_cache(), and file [save, restore]_session_cache.
  • Correct save/restore functions to save the entire cache, instead of just the first SessionRow member.
  • Add more sanitization of imported sessions.
  • Comment and indent #endifs better.

Fixes zd#22196.

Fixes F-7286, F-7287, F-7288, F-7292.

Testing

  • added unit test test_wolfSSL_session_cache_restore
  • multitest all-c89-clang-tidy
./autogen.sh || exit 1
./configure --enable-savesession --enable-opensslextra \
  --enable-context-extra-user-data --enable-session-ticket --enable-debug \ 
  --enable-sessioncerts \ 
  CFLAGS="-DHAVE_EX_DATA_CLEANUP_HOOKS -DENABLE_SESSION_CACHE_ROW_LOCK" \
  || exit 1                
make && make test || exit 1

@philljj philljj self-assigned this Aug 6, 2026
Copilot AI lite review requested due to automatic review settings August 6, 2026 05:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes persistent session-cache save/restore to serialize the full cache (not just a partial SessionRow), adds additional sanitization on restore, and adds API tests to validate both memory- and file-based cache persistence paths.

Changes:

  • Introduces wolfssl/ssl_sess.h to centralize session-cache layout constants/types and persistence sizing macros.
  • Updates src/ssl_sess.c persistence code to save full SessionRow data and restore without clobbering active row locks; expands restore-time sanitization.
  • Adds a new unit test test_wolfSSL_session_cache_restore covering memsave/memrestore and save/restore session-cache APIs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
wolfssl/ssl_sess.h New internal header consolidating session-cache sizing/layout and persistence helpers.
wolfssl/internal.h Improves #endif comments around session/ticket-related conditionals.
wolfssl/include.am Adds the new internal header to noinst_HEADERS.
tests/api/test_session.h Registers the new session-cache restore unit test.
tests/api/test_session.c Adds the new session-cache restore unit test implementation.
src/ssl_sess.c Fixes persistence to copy full rows, avoid clobbering locks, and sanitize restored sessions.
CMakeLists.txt Ensures ssl_sess.h remains excluded from installed public headers.
Suppressed comments (3)

tests/api/test_session.c:1970

  • test_read_file() logs the wrong variable on read failure (it prints ret instead of the read count) and uses "%d" with a size_t, which is undefined behavior on LP64 platforms.
    read = XFREAD(cache_mem, sizeof(struct sess_cache_t), 1, file);
    if (read != 1) {
        WOLFSSL_MSG_EX("error: read %s: %d", fname, ret);
        goto read_file_cleanup;
    }

tests/api/test_session.c:2102

  • In the remove() failure path, the fprintf prints ret instead of the remove() return code rc, which makes the diagnostic misleading.
        int rc = remove(fname);
        if (rc) {
            fprintf(stderr, "remove(%s) failed: %d\n", fname, ret);
        }

wolfssl/internal.h:4977

  • This #endif closes a "#ifndef NO_SESSION_CACHE" block, but the comment currently says "NO_SESSION_CACHE" (missing the negation), which is confusing when scanning the struct layout.
#ifndef NO_SESSION_CACHE
    int                cacheRow;          /* row in session cache     */
#endif /* NO_SESSION_CACHE */

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/api/test_session.c
Comment on lines +1932 to +1936
n_write = (int)XFWRITE(cache_mem, sizeof(struct sess_cache_t), 1, file);
if (n_write != 1) {
WOLFSSL_MSG_EX("error: write %s: %d", fname, n_write);
goto write_file_cleanup;
}
Comment thread wolfssl/internal.h
#endif /* WOLFSSL_TICKET_NONCE_MALLOC && FIPS_VERSION_GE(5,3) */
} TicketNonce;
#endif
#endif /* WOLFSSL_TLS13 && HAVE_SESSION_TICKET || !NO_PSK*/
Comment thread src/ssl_sess.c
Comment on lines +385 to +387
#if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
s->peer = NULL;
#endif
#endif /* SESSION_CERTS || OPENSSL_EXTRA */
Comment thread wolfssl/ssl_sess.h
Comment on lines +48 to +50
SMALL_SESSION_CACHE only stores 6 sessions, good for embedded clients
or systems where the default of is too much RAM.
SessionCache takes about 2K, ClientCache takes about 3Kbytes
Comment thread tests/api/test_session.c
Comment on lines +1664 to +1665
/* set type, ticketLen, rem_ess_cb, heap, peer, etc to test
* canary values. These should be sanitized on session restore. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants