lib: remove use of RANDOM_FILE
It could previously be set with configure/cmake and used in rare cases for reading randomness: with ancient mbedTLS or rustls without arc4random. We now get randomness in this order: 1. The TLS library's way to provide random 2. On Windows: Curl_win32_random 3. if arc4random exists, use that 4. weak non-crytographically strong pseudo-random Closes #14749
This commit is contained in:
parent
00ef607326
commit
269fdd4c6e
@ -1440,12 +1440,6 @@ if(SIZEOF_SUSECONDS_T)
|
||||
set(HAVE_SUSECONDS_T 1)
|
||||
endif()
|
||||
|
||||
if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING AND
|
||||
(NOT DEFINED RANDOM_FILE OR RANDOM_FILE))
|
||||
find_file(RANDOM_FILE "urandom" "/dev")
|
||||
mark_as_advanced(RANDOM_FILE)
|
||||
endif()
|
||||
|
||||
# Check for some functions that are used
|
||||
if(WIN32)
|
||||
set(CMAKE_REQUIRED_LIBRARIES "ws2_32")
|
||||
|
||||
@ -65,9 +65,6 @@
|
||||
/* Define this to 'int' if ssize_t is not an available typedefed type */
|
||||
#undef ssize_t
|
||||
|
||||
/* Define this as a suitable file to read random data from */
|
||||
#undef RANDOM_FILE
|
||||
|
||||
/* Define to 1 if you have the alarm function. */
|
||||
#define HAVE_ALARM 1
|
||||
|
||||
|
||||
@ -41,7 +41,6 @@
|
||||
#define PACKAGE_STRING "curl -"
|
||||
#define PACKAGE_TARNAME "curl"
|
||||
#define PACKAGE_VERSION "-"
|
||||
#define RANDOM_FILE "/dev/random"
|
||||
#define VERSION "0.0.0" /* TODO */
|
||||
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
@ -63,9 +63,6 @@
|
||||
/* Define this to 'int' if ssize_t is not an available typedefed type */
|
||||
#undef ssize_t
|
||||
|
||||
/* Define this as a suitable file to read random data from */
|
||||
#undef RANDOM_FILE
|
||||
|
||||
/* Define if you have the alarm function. */
|
||||
#define HAVE_ALARM
|
||||
|
||||
|
||||
@ -638,9 +638,6 @@
|
||||
/* Define to the version of this package. */
|
||||
#cmakedefine PACKAGE_VERSION ${PACKAGE_VERSION}
|
||||
|
||||
/* a suitable file to read random data from */
|
||||
#cmakedefine RANDOM_FILE "${RANDOM_FILE}"
|
||||
|
||||
/*
|
||||
Note: SIZEOF_* variables are fetched with CMake through check_type_size().
|
||||
As per CMake documentation on CheckTypeSize, C preprocessor code is
|
||||
|
||||
14
lib/rand.c
14
lib/rand.c
@ -154,20 +154,6 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(RANDOM_FILE) && !defined(_WIN32)
|
||||
if(!seeded) {
|
||||
/* if there is a random file to read a seed from, use it */
|
||||
int fd = open(RANDOM_FILE, O_RDONLY);
|
||||
if(fd > -1) {
|
||||
/* read random data into the randseed variable */
|
||||
ssize_t nread = read(fd, &randseed, sizeof(randseed));
|
||||
if(nread == sizeof(randseed))
|
||||
seeded = TRUE;
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!seeded) {
|
||||
struct curltime now = Curl_now();
|
||||
infof(data, "WARNING: using weak random seed");
|
||||
|
||||
@ -998,12 +998,6 @@ static CURLcode ossl_seed(struct Curl_easy *data)
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
#else
|
||||
|
||||
#ifdef RANDOM_FILE
|
||||
RAND_load_file(RANDOM_FILE, RAND_LOAD_LENGTH);
|
||||
if(rand_enough())
|
||||
return CURLE_OK;
|
||||
#endif
|
||||
|
||||
/* fallback to a custom seeding of the PRNG using a hash based on a current
|
||||
time */
|
||||
do {
|
||||
|
||||
@ -359,32 +359,6 @@ if test X"$OPT_OPENSSL" != Xno &&
|
||||
AC_MSG_ERROR([--with-openssl was given but OpenSSL could not be detected])
|
||||
fi
|
||||
|
||||
dnl **********************************************************************
|
||||
dnl Check for the random seed preferences
|
||||
dnl **********************************************************************
|
||||
|
||||
if test X"$OPENSSL_ENABLED" = X"1"; then
|
||||
dnl Check for user-specified random device
|
||||
AC_ARG_WITH(random,
|
||||
AS_HELP_STRING([--with-random=FILE],
|
||||
[read randomness from FILE (default=/dev/urandom)]),
|
||||
[ RANDOM_FILE="$withval" ],
|
||||
[
|
||||
if test x$cross_compiling != xyes; then
|
||||
dnl Check for random device
|
||||
AC_CHECK_FILE("/dev/urandom", [ RANDOM_FILE="/dev/urandom"] )
|
||||
else
|
||||
AC_MSG_WARN([skipped the /dev/urandom detection when cross-compiling])
|
||||
fi
|
||||
]
|
||||
)
|
||||
if test -n "$RANDOM_FILE" && test X"$RANDOM_FILE" != Xno; then
|
||||
AC_SUBST(RANDOM_FILE)
|
||||
AC_DEFINE_UNQUOTED(RANDOM_FILE, "$RANDOM_FILE",
|
||||
[a suitable file to read random data from])
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl ---
|
||||
dnl We require OpenSSL with SRP support.
|
||||
dnl ---
|
||||
|
||||
Loading…
Reference in New Issue
Block a user