← ALL ADVISORIES

LOW BYTERAY-2026-0411Disclosed

wolfSSL — Cleartext Pre-Master Secret Output in Sniffer Key Setup Debug Code

In sniffer builds that define the SHOW_SECRETS debug macro, the key setup routine prints the recovered pre-master secret, or the TLS 1.3 key exchange shared secret, of every decoded session to standard output in hex. A reader of the captured output can decrypt those sessions.

Advisory
BYTERAY-2026-0411
CWE
CWE-312
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with --enable-sniffer and SHOW_SECRETS (set by --enable-keylog-export)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The wolfSSL sniffer decrypts captured TLS traffic using the server's private key or static ephemeral keys. SetupKeys() in src/sniffer.c recovers the key exchange secret for a session and derives the session keys from it. When the library is compiled with SHOW_SECRETS, SetupKeys() prints that secret to standard output as a hex string, labelled pre master secret, just before the derivation.

The printed value is the input from which all keys of the session follow. Combined with the same packet capture the sniffer is reading, it decrypts the session. A sniffer usually runs unattended with its output redirected, so in that setup the secrets end up in a log file.

SHOW_SECRETS is a debug macro. It is defined only by --enable-keylog-export or by hand, and wolfSSL warns at configure time and at compile time that it is not for production. The sniffer itself is also opt-in. Default builds contain none of this code.

Affected Products and Versions

  • Component: wolfSSL sniffer, SetupKeys() and the PrintSecret() helper in src/sniffer.c.
  • Required build: WOLFSSL_SNIFFER (--enable-sniffer) and SHOW_SECRETS. The configure switch --enable-keylog-export and the CMake option WOLFSSL_KEYLOG_EXPORT define SHOW_SECRETS.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same print in SetupKeys().
  • Not fixed on master.
  • A default ./configure build does not include this code. Earlier releases were not checked.

Technical Details

The helper at src/sniffer.c:2488-2496 writes a label and then every byte of the buffer:

static void PrintSecret(const char* desc, const byte* buf, int sz)
{
    int i;
    printf("%s: ", desc);
    for (i = 0; i < sz; i++) {
        printf("%02x", buf[i]);
    }
    printf("\n");
}

SetupKeys() (src/sniffer.c:2660) is a state machine. Its TLS_ASYNC_DO state (src/sniffer.c:3249-3308) fills session->sslServer->arrays->preMasterSecret with the result of the RSA private decryption, or of the DH, ECDH, X25519 or X448 agreement, depending on the key type. Its last state, TLS_ASYNC_FINALIZE, copies the value to the client-side session object and then prints it, at src/sniffer.c:3381-3385:

    #ifdef SHOW_SECRETS
        PrintSecret("pre master secret",
                    session->sslServer->arrays->preMasterSecret,
                    session->sslServer->arrays->preMasterSz);
    #endif

The states fall through, so this runs for every successful key setup, in synchronous and asynchronous builds alike. The value is then used:

  1. For TLS 1.3, DeriveHandshakeSecret() consumes it as the key exchange shared secret (src/sniffer.c:3406-3411).
  2. For TLS 1.2 and earlier, MakeMasterSecret() derives the master secret from it (src/sniffer.c:3428-3429).

SetupKeys() is called from ProcessClientKeyExchange() when a ClientKeyExchange message is decoded (src/sniffer.c:3523) and from ProcessServerHello() for TLS 1.3 key shares (src/sniffer.c:4287).

SHOW_SECRETS has one configure-level source, --enable-keylog-export (configure.ac:2661-2671), which prints "Keylog export enabled -- Sensitive key data will be stored insecurely." A build that defines the macro by hand gets a compile-time warning from src/tls.c:195-202.

Reachability and Preconditions

  • The library is built with the sniffer and with SHOW_SECRETS.
  • The sniffer application has been given the server private key or static ephemeral keys for the watched sessions. The printed value is the result of the key operation performed with them.
  • The attacker can read the standard output of the sniffer process, or the file the operator redirects it to. The library writes to stdout only.
  • To use the secret the attacker needs the corresponding traffic capture.
  • The party generating the watched traffic does not need to do anything unusual. Every decoded handshake is printed.

Impact

Confirmed from source: on an affected build the sniffer prints the pre-master secret (TLS 1.2 and earlier) or the key exchange shared secret (TLS 1.3) of each session it sets up keys for. With that value and the capture, the session can be decrypted.

The sniffer process already holds the private keys from which the same secret can be computed. The print therefore discloses nothing to the operator. It matters when captured output is readable by someone who cannot read those keys, for example through log shipping or a shared log directory. Whether that is the case depends on the deployment and was not examined.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03).

The direct fix is to remove the PrintSecret() call in SetupKeys(), or to print only the length or a digest of the value. The same applies to the other callers of the helper described in BYTERAY-2026-0412.

For integrators the workaround is to keep SHOW_SECRETS out of sniffer builds that process real traffic. If such a build has run with its output captured, treat the captured output as key material for the sessions it covered.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References