Repository navigation
Harden fix when TLS 1.3 PSK callback omits cipher name - #12161
Conversation
|
There was a problem hiding this comment.
🟡 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
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
left a comment
There was a problem hiding this comment.
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

Description
A TLS 1.3 PSK callback that did not set its cipher suite name passed a NULL pointer to
GetCipherSuiteFromName(), which crashed inXSTRSTR. 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()returnsBAD_FUNC_ARGfor a NULL name, the same as the publicwolfSSL_get_cipher_suite_from_name()wrapper.TLSX_PopulateExtensions(),SetupPskKey()andFindPskSuite()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.WOLFSSL_PSK_ONE_IDand noOPENSSL_EXTRA, a zero-length client PSK is now rejected withPSK_KEY_ERRORinstead of being sent in the ClientHello.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 fulltests/unit.testpasses 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