Skip to content

Commit b0b840a

Browse files
Rename fdOpen to seedFdOpen to avoid potential conflicts.
Gate keeping the seed FD open behind WOLFSSL_KEEP_RNG_SEED_FD_OPEN and only enable by default for HAProxy. It is causing issues on OS X and may cause issues on other OSes, and is generally a major behavior change.
1 parent 755097d commit b0b840a

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7835,7 +7835,7 @@ fi
78357835
if test "$ENABLED_HAPROXY" = "yes"
78367836
then
78377837
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_HAPROXY -DOPENSSL_COMPATIBLE_DEFAULTS"
7838-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SIGNER_DER_CERT"
7838+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SIGNER_DER_CERT -DWOLFSSL_KEEP_RNG_SEED_FD_OPEN"
78397839
# --enable-all defines its own DEFAULT_MAX_CLASSIC_ASYM_KEY_BITS
78407840
if test -z "$DEFAULT_MAX_CLASSIC_ASYM_KEY_BITS"
78417841
then

wolfcrypt/src/random.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
894894
}
895895
#endif
896896

897-
#ifndef USE_WINDOWS_API
898-
if (!rng->seed.fdOpen)
897+
#if defined(WOLFSSL_KEEP_RNG_SEED_FD_OPEN) && !defined(USE_WINDOWS_API)
898+
if (!rng->seed.seedFdOpen)
899899
rng->seed.fd = -1;
900900
#endif
901901

@@ -1378,11 +1378,12 @@ int wc_FreeRng(WC_RNG* rng)
13781378
ret = WC_HW_E;
13791379
#endif
13801380

1381-
#ifdef XCLOSE
1382-
if(rng->seed.fdOpen && rng->seed.fd != -1) {
1381+
#if defined(WOLFSSL_KEEP_RNG_SEED_FD_OPEN) && defined(XCLOSE) && \
1382+
!defined(USE_WINDOWS_API)
1383+
if(rng->seed.seedFdOpen && rng->seed.fd != -1) {
13831384
XCLOSE(rng->seed.fd);
13841385
rng->seed.fd = -1;
1385-
rng->seed.fdOpen = 0;
1386+
rng->seed.seedFdOpen = 0;
13861387
}
13871388
#endif
13881389

@@ -3566,7 +3567,10 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
35663567

35673568
#ifndef NO_FILESYSTEM
35683569
#ifndef NO_DEV_URANDOM /* way to disable use of /dev/urandom */
3569-
if (!os->fdOpen && os->fd == -1) {
3570+
#ifdef WOLFSSL_KEEP_RNG_SEED_FD_OPEN
3571+
if (os->fd == -1 && !os->seedFdOpen)
3572+
#endif
3573+
{
35703574
os->fd = open("/dev/urandom", O_RDONLY);
35713575
#if defined(DEBUG_WOLFSSL)
35723576
WOLFSSL_MSG("opened /dev/urandom.");
@@ -3581,13 +3585,11 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
35813585
#endif
35823586
if (os->fd == -1)
35833587
return OPEN_RAN_E;
3584-
else
3585-
os->fdOpen = 1;
3586-
}
3587-
else
3588-
{
3589-
os->fdOpen = 1;
35903588
}
3589+
#ifdef WOLFSSL_KEEP_RNG_SEED_FD_OPEN
3590+
if (os->fd != -1)
3591+
os->seedFdOpen = 1;
3592+
#endif
35913593
}
35923594
#if defined(DEBUG_WOLFSSL)
35933595
WOLFSSL_MSG("rnd read...");
@@ -3611,6 +3613,9 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
36113613
#endif
36123614
}
36133615
}
3616+
#ifndef WOLFSSL_KEEP_RNG_SEED_FD_OPEN
3617+
close(os->fd);
3618+
#endif
36143619
#else
36153620
(void)output;
36163621
(void)sz;

wolfssl/wolfcrypt/random.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ struct OS_Seed {
156156
ProviderHandle handle;
157157
#else
158158
int fd;
159-
byte fdOpen:1;
159+
#if defined(WOLFSSL_KEEP_RNG_SEED_FD_OPEN)
160+
byte seedFdOpen:1;
161+
#endif
160162
#endif
161163
#if defined(WOLF_CRYPTO_CB)
162164
int devId;

0 commit comments

Comments
 (0)