wolfSSL — Cleartext Storage of TLS 1.2 Master Secret in Keylog Export File and Standard Output
In keylog-export builds, wolfSSL writes the master secret of every TLS 1.2 or earlier handshake to standard output and appends it to sslkeylog.log through a plain fopen call. The file gets umask-governed permissions, so other local accounts can read it and decrypt those sessions.
- Advisory
- BYTERAY-2026-0414
- 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-keylog-export (SHOW_SECRETS, HAVE_SECRET_CALLBACK and WOLFSSL_SSLKEYLOGFILE)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
In a build configured with --enable-keylog-export, wolfSSL installs tlsShowSecrets() from src/ssl.c as the secret callback on every connection object. For each handshake up to TLS 1.2 the callback receives the 48-byte master secret, formats the NSS key log line CLIENT_RANDOM <client random> <master secret>, prints it to standard output and appends it to a log file.
The file is opened with fopen in append mode. No permissions are set, so on a POSIX system a new file is created with mode 0666 masked by the process umask. With the common umask 022 every local account can read it. The default path is sslkeylog.log, relative to the working directory. One line of that file and a capture of the connection are enough to decrypt it.
Exporting the master secret is what the option is for, and wolfSSL labels it insecure in the configure help and prints a warning when it is selected. This advisory is about how the export is done: the file is not restricted to its owner, a second copy goes to standard output, and both happen for every connection without a run-time switch. Default builds do not contain this code. The TLS 1.3 writer to the same file is described in BYTERAY-2026-0413.
Affected Products and Versions
- Component: key log export for TLS 1.2 and earlier,
tlsShowSecrets()insrc/ssl.c, registered byInitSSL()insrc/internal.c. - Required build:
SHOW_SECRETSandHAVE_SECRET_CALLBACKfor the callback and the standard output copy;WOLFSSL_SSLKEYLOGFILEand a file system for the file. The configure switch--enable-keylog-export(configure.ac:2661-2671) and the CMake optionWOLFSSL_KEYLOG_EXPORTdefine all three macros. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same callback and open the file the same way. 5.9.2 has only the compile-time path; the optionalSSLKEYLOGFILEenvironment variable lookup is present from 5.9.4. - Not fixed on master.
- A default
./configurebuild does not include this code. Earlier releases were not checked.
Technical Details
tlsShowSecrets() is at src/ssl.c:2969-3035. After building the line in pmsBuf, it prints it and then appends it to the file:
/* print master secret */
puts(pmsBuf);
f = XFOPEN(keyLogFile, "a");
if (f != XBADFILE) {
XFWRITE(pmsBuf, 1, pmsPos, f);
XFCLOSE(f);
}
The first excerpt is src/ssl.c:3010-3011, the second src/ssl.c:3026-3030. keyLogFile is WOLFSSL_SSLKEYLOGFILE_OUTPUT, which defaults to "sslkeylog.log" (wolfssl/internal.h:8143-8148). With WOLFSSL_SSLKEYLOGFILE_USE_ENV, which --enable-keylog-export does not define, a non-empty SSLKEYLOGFILE environment variable replaces it (src/ssl.c:3017-3025). XFOPEN is fopen (wolfssl/wolfcrypt/wc_port.h:1463-1468). An existing file at the path is appended to with the owner and mode it already has.
Data flow:
InitSSL()callswolfSSL_set_secret_cb(ssl, tlsShowSecrets, NULL)for every new connection object (src/internal.c:9073-9075).MakeTlsMasterSecret()derivesssl->arrays->masterSecret, with or without the extended master secret, and passes it tossl->tlsSecretCb(src/tls.c:787-792). This is the derivation for TLS 1.0 to 1.2 and for DTLS up to 1.2.- The callback writes the line to
stdoutand to the file.
The tree has an owner-only open, wc_fopen_owner_only() (wolfcrypt/src/wc_port.c:6158-6182), which creates a file with mode 0600 and applies fchmod. At the tested commit it is used only for the session cache file.
SSL 3.0 handshakes do not go through this callback. In a build with SSL 3.0 enabled they print their secrets from a different function; see BYTERAY-2026-0410.
Reachability and Preconditions
- The library is built with
--enable-keylog-exportor the equivalent macros. That switch prints "Keylog export enabled -- Sensitive key data will be stored insecurely." and definesWOLFSSL_KEYLOG_EXPORT_WARNED, which silences the compile-time warning atsrc/tls.c:195-202. - The process completes handshakes at TLS 1.2 or below. No application call is needed to start the export.
- For the file: the attacker has a local account or other read access to the working directory of the process, and the umask leaves the file readable. With a restrictive umask such as 077 a new file is owner-only.
- For the standard output copy: the attacker can read wherever the operator sends the process output.
- To decrypt traffic the attacker also needs a capture of the connection.
Impact
Confirmed from source: an affected build writes the master secret of every TLS 1.2 or earlier connection to standard output and to a file whose permissions come from the umask. Where either is readable by another party, that party can decrypt captured traffic of those connections. The file persists after the process exits.
The exposure exists only in builds where an integrator has chosen an option documented as insecure. ByteRay has no information on how often such builds are deployed outside debugging.
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 fix direction is to open the key log with the existing owner-only helper so that the file is created with mode 0600 regardless of the umask, to refuse or warn when an existing file at the path is readable by group or others, and to drop the unconditional copy to standard output. A run-time opt-in would keep a debug build from exporting secrets by accident.
Until then, do not ship builds with --enable-keylog-export. Where the option is needed for debugging, run the process with umask 077 in a directory only its user can read, do not capture its standard output to shared logs, and delete the file afterwards.
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
- tlsShowSecrets at the tested commit
- Callback registration in InitSSL
- The keylog export configure switch
- The owner-only open helper
- BYTERAY-2026-0413, the TLS 1.3 traffic secrets in the same file
- BYTERAY-2026-0410, the SSL 3.0 derivation
- RFC 9850, the SSLKEYLOGFILE format
- CWE-312: Cleartext Storage of Sensitive Information