Skip to content

Harden fix when TLS 1.3 PSK callback omits cipher name - #12161

Merged
JacobBarthelmeh merged 2 commits into
wolfSSL:masterfrom
embhorn:gh12153
Nov 20, 2026
Merged

JacobBarthelmeh merged 2 commits into
wolfSSL:masterfrom
embhorn:gh12153

Conversation

@embhorn

@embhorn embhorn commented Nov 17, 2026

Copy link
Copy Markdown
Member

Description

A TLS 1.3 PSK callback that did not set its cipher suite name passed a NULL pointer to GetCipherSuiteFromName(), which crashed in XSTRSTR. On the client this happened even when the callback returned 0 to say it had no PSK, because the length check came after the name lookup. On the server, a callback that returned a key without a name crashed while handling a ClientHello.

  • GetCipherSuiteFromName() returns BAD_FUNC_ARG for a NULL name, the same as the public wolfSSL_get_cipher_suite_from_name() wrapper.
  • TLSX_PopulateExtensions(), SetupPskKey() and FindPskSuite() use the default suite (WOLFSSL_DEF_PSK_CIPHER) when the callback gives no name. SetupPskKey() now initializes its suite bytes so it never reads uninitialized stack.
  • With WOLFSSL_PSK_ONE_ID and no OPENSSL_EXTRA, a zero-length client PSK is now rejected with PSK_KEY_ERROR instead of being sent in the ClientHello.
  • The doc comments for the four TLS 1.3 PSK callback setters now say the cipher name is optional and that a key length of 0 means no PSK.

Fixes #12153

Testing

Added test_tls13_psk_cb_no_cipher_name. It covers client and server callbacks that leave the name unset (the handshake uses the default suite) and a client callback that returns 0. The full tests/unit.test passes under ASan with --enable-psk, --enable-psk --enable-opensslextra, --enable-psk --enable-psk-one-id, and --enable-psk --enable-psk-one-id --enable-opensslextra.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Nov 17, 2026
Copilot AI balanced review requested due to automatic review settings November 17, 2026 18:51
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m3

  • FLASH: .text +12 B (+0.0%, 132,885 B / 262,144 B, total: 51% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +104 B, text +13,192 B (+4.7%, 295,768 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

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.

🟡 Changes recommended

The unreleased changelog lacks an entry documenting the TLS 1.3 PSK callback’s NULL cipher default and zero-length key behavior, including the WOLFSSL_PSK_ONE_ID/non-OPENSSL_EXTRA case.

1 open issue
What changed in this PR

This PR hardens TLS 1.3 PSK callback handling to address the NULL cipher-name crash reported in #12153 while preserving the default PSK suite.

Changes:

  • Reject NULL names in cipher lookup and retain the default suite when PSK callbacks omit a name.
  • Reject zero-length client PSKs in single-identity builds without OpenSSL compatibility.
  • Add regression coverage and update English and Japanese callback documentation.
File Description
tests/​api/​test_tls13.h Registers the new PSK callback regression test.
tests/​api/​test_tls13.c Tests omitted cipher names and a callback returning no PSK.
src/​tls13.c Initializes default suite bytes and handles unnamed client/server PSKs.
src/​tls.c Preserves the default suite and checks zero-length single-identity PSKs.
src/​internal.c Guards cipher-name lookup against NULL input.
doc/​dox_comments/​header_files/​ssl.h Documents optional cipher names and zero-length callback results.
doc/​dox_comments/​header_files-ja/​ssl.h Adds equivalent Japanese callback documentation.

Review effort: Balanced

Comment thread doc/dox_comments/header_files/ssl.h Resolved
Document in the four TLS 1.3 PSK callback setters that the callback may
leave the cipher name NULL, in which case WOLFSSL_DEF_PSK_CIPHER is used,
and that a key length of 0 means no PSK. On the server, a non-zero key
with no name is accepted and the non-TLS 1.3 server callback is skipped.

In test_tls13_psk_cb_no_cipher_name, compare the negotiated suite with
WOLFSSL_DEF_PSK_CIPHER and drop the cipher list restriction so the test
follows an overridden default. Pin the zero length key case to
PSK_KEY_ERROR, or to WOLFSSL_ERROR_WANT_READ when OPENSSL_EXTRA or
WOLFSSL_PSK_ONE_ID lets the ClientHello go out.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12161

Scan targets checked: wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files-ja/ssl.h, doc/dox_comments/header_files/ssl.h, tests/api/test_tls13.h
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@embhorn embhorn assigned wolfSSL-Bot and unassigned embhorn Nov 18, 2026
@JacobBarthelmeh
JacobBarthelmeh merged commit 795bcac into wolfSSL:master Nov 20, 2026
437 checks passed
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.

TLS 1.3 client: GetCipherSuiteFromName(NULL) crash when the PSK callback leaves *cipherName unset

5 participants