vtls/rustls: support strong CSRNG data
Now that the curl rustls vtls backend is using rustls 0.14 we can address the weak random situation by using `rustls_default_crypto_provider_random()` to provide a `Curl_ssl` `random` callback that fills the provided buffer with cryptographically secure random data. The mentions in `docs/` about weak RNG when using rustls are removed as they are no longer applicable. Closes #14889
This commit is contained in:
parent
6d9b40d6a4
commit
8972845123
@ -56,7 +56,6 @@ Graduation requirements:
|
||||
Graduation requirements:
|
||||
|
||||
- a reasonable expectation of a stable API going forward.
|
||||
- a sufficient approach to avoid using weak random numbers
|
||||
|
||||
### WebSocket
|
||||
|
||||
|
||||
@ -34,18 +34,3 @@ See the [rustls-ffi README] for more information on cryptography providers and
|
||||
their build/platform requirements.
|
||||
|
||||
[rustls-ffi README]: https://github.com/rustls/rustls-ffi/blob/main/README.md#cryptography-provide
|
||||
|
||||
## Randomness
|
||||
|
||||
Every TLS libcurl curl supports - *except* Rustls - provides a function for
|
||||
curl to extract cryptographically safe random numbers with.
|
||||
|
||||
When you build curl with Rustls, curl uses its own internal attempts to get a
|
||||
decent random value:
|
||||
|
||||
1. Windows specific APIs
|
||||
2. arc4random
|
||||
|
||||
If neither of those are present, then curl using Rustls falls back to **weak
|
||||
pseudo-random values**, and thus weakening several curl authentication
|
||||
implementations.
|
||||
|
||||
@ -100,9 +100,9 @@ CURLcode Curl_win32_random(unsigned char *entropy, size_t length)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(USE_SSL) || defined(USE_RUSTLS)
|
||||
#if !defined(USE_SSL)
|
||||
/* ---- possibly non-cryptographic version following ---- */
|
||||
CURLcode Curl_weak_random(struct Curl_easy *data,
|
||||
static CURLcode weak_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length) /* always 4, size of int */
|
||||
{
|
||||
@ -151,7 +151,7 @@ CURLcode Curl_weak_random(struct Curl_easy *data,
|
||||
#ifdef USE_SSL
|
||||
#define _random(x,y,z) Curl_ssl_random(x,y,z)
|
||||
#else
|
||||
#define _random(x,y,z) Curl_weak_random(x,y,z)
|
||||
#define _random(x,y,z) weak_random(x,y,z)
|
||||
#endif
|
||||
|
||||
static CURLcode randit(struct Curl_easy *data, unsigned int *rnd,
|
||||
|
||||
@ -36,11 +36,6 @@ CURLcode Curl_rand_bytes(struct Curl_easy *data,
|
||||
#define Curl_rand(a,b,c) Curl_rand_bytes((a), (b), (c))
|
||||
#endif
|
||||
|
||||
/* ---- non-cryptographic version following ---- */
|
||||
CURLcode Curl_weak_random(struct Curl_easy *data,
|
||||
unsigned char *rnd,
|
||||
size_t length);
|
||||
|
||||
/*
|
||||
* Curl_rand_hex() fills the 'rnd' buffer with a given 'num' size with random
|
||||
* hexadecimal digits PLUS a null-terminating byte. It must be an odd number
|
||||
|
||||
@ -1056,6 +1056,16 @@ static size_t cr_version(char *buffer, size_t size)
|
||||
return msnprintf(buffer, size, "%.*s", (int)ver.len, ver.data);
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
cr_random(struct Curl_easy *data, unsigned char *entropy, size_t length)
|
||||
{
|
||||
rustls_result rresult = 0;
|
||||
(void)data;
|
||||
rresult =
|
||||
rustls_default_crypto_provider_random(entropy, length);
|
||||
return map_error(rresult);
|
||||
}
|
||||
|
||||
const struct Curl_ssl Curl_ssl_rustls = {
|
||||
{ CURLSSLBACKEND_RUSTLS, "rustls" },
|
||||
SSLSUPP_CAINFO_BLOB | /* supports */
|
||||
@ -1070,7 +1080,7 @@ const struct Curl_ssl Curl_ssl_rustls = {
|
||||
Curl_none_check_cxn, /* check_cxn */
|
||||
cr_shutdown, /* shutdown */
|
||||
cr_data_pending, /* data_pending */
|
||||
Curl_weak_random, /* random */
|
||||
cr_random, /* random */
|
||||
Curl_none_cert_status_request, /* cert_status_request */
|
||||
cr_connect_blocking, /* connect */
|
||||
cr_connect_nonblocking, /* connect_nonblocking */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user