Skip to content

[Bug]: Client capped at TLS 1.2 with wolfSSL_set_max_proto_version() still takes TLS 1.3 paths: wolfSSL_connect() does not return #12202

Open

Description

@GeekQAQ

Version

master 511ea63 (2026-11-19); also 5.9.4-stable

Description

wolfSSL_set_max_proto_version(ssl, TLS1_2_VERSION) on a wolfSSLv23_client_method() object only adds WOLFSSL_OP_NO_TLSv1_3 to options.mask; ssl->version stays TLS 1.3. Two client setups then run TLS 1.3 code for a connection that can only negotiate TLS 1.2:

  1. TLS 1.3 session set on the capped object. wolfSSL_set_session() adopts the session's version (wolfSSL_SetSession(), src/ssl_sess.c), sets options.tls1_3, and only rejects sessions below the minimum version. wolfSSL_connect() goes to wolfSSL_connect_TLSv13(), which hands back to wolfSSL_connect(), and the call does not return (with groups set via wolfSSL_set_groups(), client offering only TLS 1.2 suites). Without groups set, the server answers handshake_failure. Both orders of wolfSSL_set_session() and wolfSSL_set_max_proto_version() behave the same. Without the session, the same objects complete a TLS 1.2 handshake.
  2. External PSK callback on the capped object. With wolfSSL_set_psk_client_callback() or wolfSSL_set_psk_client_tls13_callback() set, TLSX_PopulateExtensions() (src/tls.c) sets TLS 1.3 PSK cipher specs and adds a pre_shared_key extension regardless of the mask, and wolfSSL_connect() does not return. The same client without the PSK callback completes TLS 1.2 with the certificate.

Builds: CMake with -DWOLFSSL_OPENSSLEXTRA=yes -DWOLFSSL_SESSION_TICKET=yes -DWOLFSSL_DTLS=yes -DWOLFSSL_DTLS13=yes (plus -DWOLFSSL_PSK=yes for case 2), clang 21, x86_64. Without WOLFSSL_DTLS13 case 1 does not loop; the client fails with OUT_OF_ORDER_E (-373) instead. With --enable-all --enable-dtls13, the first test below fails instead of hanging.

This looks like the TLS side of what #11857 changes for DTLS (moving an SSL that may downgrade to the newest version the mask allows, and checking the mask again when the handshake starts).

Reproduction steps

Two memio tests in the style of tests/api/test_session.c (repro_tests.c in https://gist.github.com/GeekQAQ/3c1f6fe68b4a03822f6e032bd8b03cab, add the declarations to test_session.h). On master the first hangs in a WOLFSSL_DTLS13 build and fails in --enable-all --enable-dtls13; the second hangs.

A reference patch is in the same gist (tls13-mask.patch), for reference only: at the start of wolfSSL_connect(), drop the session's TLS 1.3 state (options.tls1_3, resuming) when the mask excludes TLS 1.3, and skip the TLS 1.3 PSK in TLSX_PopulateExtensions() under the same condition. It makes both cases complete a full TLS 1.2 handshake in the build above, and the second test passes with --enable-all --enable-dtls13. It is not complete: with --enable-all --enable-dtls13 the first test still fails (set the session first: the handshake does not complete; set the maximum version first: the client still offers the session and the server fails with MATCH_SUITE_ERROR). Declining the session in wolfSSL_set_session() when TLS 1.3 is masked handles only one call order, so the right place for the check is probably where #11857 puts it for DTLS.

Relevant log output

case 1 (session set, max TLS 1.2, groups set):  wolfSSL_connect() did not return within 10 s
case 1 (no groups):                             server sends handshake_failure; client -313
case 2 (TLS 1.2 or TLS 1.3 PSK callback):       wolfSSL_connect() did not return within 10 s
same objects without the session / PSK callback: TLS 1.2 handshake completes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions