wolfSSL — DH Prime Check Skipped for Server Parameters Received During Secure Renegotiation
A wolfSSL TLS 1.2 client tests the server's Diffie-Hellman prime for primality once per connection object and remembers the result in a flag that renegotiation does not reset. A server that sends different DH parameters in a renegotiation has them accepted without the primality test, so the renegotiated key exchange can run over a composite modulus.
- Advisory
- BYTERAY-2026-0343
- CWE
- CWE-1271
- CVSS
- 5.9 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, TLS 1.2 clients built with --enable-secure-renegotiation that enable renegotiation and negotiate DHE or DHE-PSK cipher suites
- Fixed in
- Master commit 5aa793e52e901e412f1ececb8b2029349ece5e8f (PR 11606, merged 2026-10-19). Not in a wolfSSL stable release as of 2026-12-03.
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
When a wolfSSL client receives finite-field Diffie-Hellman parameters in a ServerKeyExchange, it checks that the modulus is prime before using it. The check is controlled by two option flags. One says the check is wanted; the other says it has been done. Both are set up when the WOLFSSL object is created, and nothing clears the "done" flag afterwards.
Secure renegotiation runs a second handshake on the same object. The server sends a new ServerKeyExchange, possibly with a different prime, and the client installs it. Because the "done" flag is still set from the first handshake, the client loads the new prime through the path that skips the primality test. A modulus that is composite, or otherwise chosen to make discrete logarithms easy, is accepted, and the new session keys are derived from it. Secure renegotiation is disabled in a default build and must also be enabled by the application at run time.
Affected Products and Versions
- Component:
src/internal.c,DhSetKey(),GetDhPublicKey(), and the renegotiation reset code inSendClientHello()andResetHandshakeStateForReneg(). - Required build:
HAVE_SECURE_RENEGOTIATION(--enable-secure-renegotiation, default disabled,configure.ac:9336-9340) with DH enabled, and not a FIPS, self-test orWOLFSSL_OLD_PRIME_CHECKbuild (src/internal.c:34649-34650). - Required use: client side, TLS 1.2 or earlier, a DHE or DHE-PSK cipher suite, and renegotiation enabled on the connection with
wolfSSL_UseSecureRenegotiation(). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same flag logic and the same renegotiation reset code. - Fixed on master. No wolfSSL release contains the fix.
- A default
./configurebuild does not include secure renegotiation. Earlier releases were not checked.
Technical Details
DhSetKey() loads the server's parameters into the client's DH key (src/internal.c:34651-34667):
if (ssl->options.dhDoKeyTest &&
!ssl->options.dhKeyTested)
{
ret = wc_DhSetCheckKey(ssl->buffers.serverDH_Key,
After a successful wc_DhSetCheckKey() it sets dhKeyTested to 1 (src/internal.c:34662). On every later call the condition is false and the else branch calls wc_DhSetKey() (src/internal.c:34667). That function marks the parameters as trusted (wolfcrypt/src/dh.c:2821-2826), and the primality test runs only for untrusted parameters (wolfcrypt/src/dh.c:2690).
The path through a renegotiation:
- First handshake. The server sends a prime that is not one of the built-in FFDHE groups.
DhSetKey()tests it and setsdhKeyTested. - The server sends a HelloRequest.
DoHelloRequest()schedules the renegotiation (src/internal.c:19883). The client can also start one itself. - The handshake state is reset for the new handshake (
src/internal.c:34759-34763,src/internal.c:20620-20634). Neither place touchesdhDoKeyTestordhKeyTested. - The server sends a ServerKeyExchange with a different modulus.
GetDhPublicKey()checks only its length against the configured minimum and maximum (src/internal.c:36056-36065) and stores it. SendClientKeyExchange()callsDhSetKey()(src/internal.c:37567).dhKeyTestedis 1, so the modulus is loaded withwc_DhSetKey()and never tested.
A second way into the same state exists for DHE-PSK suites. When the first handshake uses a built-in FFDHE group, GetDhPublicKey() turns the test off for the object by clearing dhDoKeyTest (src/internal.c:36248-36251). The DHE-PSK branch always calls DhSetKey() (src/internal.c:37648), so a non-FFDHE prime sent in the renegotiation is not tested either. For certificate-authenticated DHE this second way is closed in ordinary builds: the client keeps using the named group remembered from the first handshake (src/internal.c:37555-37567), so the prime sent in the renegotiation is not used for the key exchange.
Reachability and Preconditions
- The client was built with secure renegotiation and the application enabled it on the connection.
- The connection uses TLS 1.2 or earlier with a finite-field DHE suite. TLS 1.3 has no renegotiation.
- The first handshake used a custom (non-FFDHE) prime, or the suite is DHE-PSK.
- The bad parameters come from the server. They are covered by the server's ServerKeyExchange signature, or the handshake is authenticated by the pre-shared key, so a network attacker without the server's credentials cannot substitute them. The relevant attacker is one who controls or has tampered with the server's DH parameters: a compromised or misconfigured server, or a parameter set with a hidden weakness. The primality test exists for that case, and it is applied on the first handshake.
Impact
Confirmed from source: on a renegotiation, the client accepts a DH modulus that was never tested for primality and derives the new master secret from it. If the modulus is composite with small factors, or built so that discrete logarithms are cheap, an observer who knows the structure can recover the shared secret of the renegotiated session from the public values and decrypt the traffic that follows. The minimum and maximum length limits still apply.
Not verified: ByteRay did not construct such a modulus or measure the cost of the attack against the length limits.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Fixed on master by commit 5aa793e52e901e412f1ececb8b2029349ece5e8f, part of PR 11606, merged 2026-10-19. The commit ties the "tested" state to the parameters instead of the object: GetDhPublicKey() clears dhKeyTested each time it installs parameters from a ServerKeyExchange, and a match with a built-in FFDHE group now marks the parameters as tested instead of disabling the test for the rest of the object's life. The fix is on master only. No wolfSSL release contains it as of 2026-12-03.
Until a release is available:
- Do not enable secure renegotiation on clients that negotiate DHE suites, or disable finite-field DHE suites on those clients and use ECDHE.
- Build with
--enable-ffdhe-only(WOLFSSL_REQUIRE_FFDHE), which rejects any server prime that is not a built-in FFDHE group (src/internal.c:36242-36245). This breaks interoperability with servers that use custom groups.
The same flags also survive wolfSSL_clear(); that case is BYTERAY-2026-0306 and is closed by the same commit.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-09-30 — Pull request 11606 opened upstream.
- 2026-10-19 — Pull request 11606 merged to master.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd. wolfSSL credits ByteRay Ltd. for the reports in pull request 11606.
References
DhSetKeyat the tested commit- FFDHE match handling in
GetDhPublicKeyat the tested commit - Renegotiation reset in
SendClientHelloat the tested commit - wolfSSL pull request 11606
- Fix commit 5aa793e52e90
- BYTERAY-2026-0306, DH prime check skipped on reused connections
- CWE-1271: Uninitialized Value on Reset for Registers Holding Security Settings