wolfSSL — Cleartext Storage of Random Seed File Without Owner-Only Permissions in RAND_write_file
wolfSSL_RAND_write_file writes 1024 bytes of DRBG output to an application-named seed file through a plain fopen call, so the file gets umask-governed permissions. The contents are generator output, not generator state; reading them does not by itself make later output predictable.
- Advisory
- BYTERAY-2026-0416
- CWE
- CWE-312
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, OpenSSL compatibility builds (OPENSSL_EXTRA) with a file system, when the application calls RAND_write_file
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_RAND_write_file() is the OpenSSL compatibility function RAND_write_file. An application calls it to save random bytes to a seed file, usually $HOME/.rnd, and later calls RAND_load_file to mix them back into the generator. wolfSSL draws 1024 bytes from its global DRBG and writes them to the named file.
The file is opened with fopen(fname, "wb"). No permissions are set. On a POSIX system a new file is created with mode 0666 masked by the process umask, which with the common umask 022 leaves it readable by every local account. wolfSSL has a helper that creates a file with mode 0600 and uses it for the persisted session cache, but not here.
The consequence is limited. The bytes in the file are output of the generator, produced for the file and used for nothing else. When they are loaded back, they are hashed together with the generator's existing state, which was seeded from the platform entropy source. A local reader of the file does not learn the generator state from it. This is a hardening gap in an optional compatibility function, not a disclosure of key material. A default build does not include the function.
Affected Products and Versions
- Component: OpenSSL compatibility layer,
wolfSSL_RAND_write_file()insrc/ssl_crypto.c. - Required build:
OPENSSL_EXTRA(for example--enable-opensslextra) and a file system (NO_FILESYSTEMnot defined). No debug macro is involved. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.4-stabletag has the same code in the same file. Inv5.9.2-stablethe function, with the samefopencall, is insrc/ssl.c. - Not fixed on master.
- A default
./configurebuild does not include this function. Earlier releases were not checked.
Technical Details
The function is at src/ssl_crypto.c:3764-3837. It fills a 1024-byte buffer with wc_RNG_GenerateBlock(&globalRNG, buf, (word32)bytes) at src/ssl_crypto.c:3800 and then writes it, at src/ssl_crypto.c:3814-3823:
f = XFOPEN(fname, "wb");
if (f == XBADFILE) {
WOLFSSL_MSG("Error opening the file");
bytes = 0;
}
else {
size_t bytes_written = XFWRITE(buf, 1, (size_t)bytes, f);
bytes = (int)bytes_written;
XFCLOSE(f);
}
XFOPEN is fopen (wolfssl/wolfcrypt/wc_port.h:1463-1468). A new file takes its mode from the umask. An existing file is truncated and keeps the mode it had. The file name is whatever the application passes; wolfSSL_RAND_file_name() returns $RANDFILE or $HOME/.rnd (src/ssl_crypto.c:3684-3751).
The owner-only alternative exists in the same tree. wc_fopen_owner_only() (wolfcrypt/src/wc_port.c:6158-6182) opens with O_CREAT | O_TRUNC and mode S_IRUSR | S_IWUSR, then applies fchmod. Its only caller at the tested commit is the session cache writer (src/ssl_sess.c:610).
What a reader of the file obtains follows from how the bytes are produced and consumed:
- They are DRBG output. The Hash-DRBG state is not written.
wolfSSL_RAND_load_file()first makes sure the global generator exists (src/ssl_crypto.c:4432); on first usewc_InitRng()seeds it from the platform entropy source (src/ssl_crypto.c:3622-3649).- It then passes the file contents to
wc_RNG_DRBG_Reseed()(src/ssl_crypto.c:4449). - The reseed computes the new state from the previous state
Vand the supplied bytes together (wolfcrypt/src/random.c:835-837).
The state after a reload therefore depends on V, which is not in the file.
Reachability and Preconditions
- The library is built with the OpenSSL compatibility layer and a file system.
- The application calls
wolfSSL_RAND_write_file()orRAND_write_file(). Nothing in the library calls it on its own. - The process umask and the directory permissions leave the new file readable to the attacker, who has a local account. With umask 077, or with a pre-existing owner-only file, the contents are not readable by others.
- No network peer is involved.
Impact
Confirmed from source: the seed file is created with umask-governed permissions and holds 1024 bytes of raw generator output.
Also confirmed from source: those bytes do not determine the generator state, before or after they are loaded back. Predicting later output would additionally require the state that wc_InitRng() established from the platform entropy source. That would matter only on a platform whose entropy source is weak enough to guess, which was not examined and is not claimed here.
The practical effect is that an application relying on this compatibility function gets a seed file that is less protected than the session cache file written by the same library.
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 seed file with the existing owner-only helper instead of XFOPEN(fname, "wb"), so the mode does not depend on the caller's umask.
Applications can protect themselves now by setting umask 077 before the call, or by creating the file with mode 0600 beforehand, and by keeping it in a directory that only the owning user can read. Applications that do not need a seed file can drop the call; the global generator is seeded by wc_InitRng() without it.
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.