mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
rand: make it work without TLS backing
Regression introduced in commit f682156a4f
Reported-by: John Kohl
Bug: https://curl.haxx.se/mail/lib-2017-01/0055.html
This commit is contained in:
parent
a18db79262
commit
807698db02
@ -680,9 +680,9 @@ size_t Curl_axtls_version(char *buffer, size_t size)
|
||||
return snprintf(buffer, size, "axTLS/%s", ssl_version());
|
||||
}
|
||||
|
||||
int Curl_axtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
CURLcode Curl_axtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
static bool ssl_seeded = FALSE;
|
||||
(void)data;
|
||||
@ -694,7 +694,7 @@ int Curl_axtls_random(struct Curl_easy *data,
|
||||
RNG_initialize();
|
||||
}
|
||||
get_random((int)length, entropy);
|
||||
return 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#endif /* USE_AXTLS */
|
||||
|
@ -8,7 +8,7 @@
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2010, DirecTV, Contact: Eric Hu <ehu@directv.com>
|
||||
* Copyright (C) 2010 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2010 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -42,9 +42,9 @@ void Curl_axtls_session_free(void *ptr);
|
||||
size_t Curl_axtls_version(char *buffer, size_t size);
|
||||
int Curl_axtls_shutdown(struct connectdata *conn, int sockindex);
|
||||
int Curl_axtls_check_cxn(struct connectdata *conn);
|
||||
int Curl_axtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
CURLcode Curl_axtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
|
||||
/* Set the API backend definition to axTLS */
|
||||
#define CURL_SSL_BACKEND CURLSSLBACKEND_AXTLS
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -917,19 +917,19 @@ Curl_cyassl_connect(struct connectdata *conn,
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
int Curl_cyassl_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
CURLcode Curl_cyassl_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
RNG rng;
|
||||
(void)data;
|
||||
if(InitRng(&rng))
|
||||
return 1;
|
||||
return CURLE_FAILED_INIT;
|
||||
if(length > UINT_MAX)
|
||||
return 1;
|
||||
return CURLE_FAILED_INIT;
|
||||
if(RNG_GenerateBlock(&rng, entropy, (unsigned)length))
|
||||
return 1;
|
||||
return 0;
|
||||
return CURLE_FAILED_INIT;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -51,9 +51,9 @@ int Curl_cyassl_init(void);
|
||||
CURLcode Curl_cyassl_connect_nonblocking(struct connectdata *conn,
|
||||
int sockindex,
|
||||
bool *done);
|
||||
int Curl_cyassl_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
CURLcode Curl_cyassl_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *sha256sum, /* output */
|
||||
|
@ -6,7 +6,7 @@
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012 - 2014, Nick Zitzmann, <nickzman@gmail.com>.
|
||||
* Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -2427,8 +2427,8 @@ bool Curl_darwinssl_data_pending(const struct connectdata *conn,
|
||||
return false;
|
||||
}
|
||||
|
||||
int Curl_darwinssl_random(unsigned char *entropy,
|
||||
size_t length)
|
||||
CURLcode Curl_darwinssl_random(unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
/* arc4random_buf() isn't available on cats older than Lion, so let's
|
||||
do this manually for the benefit of the older cats. */
|
||||
@ -2442,7 +2442,7 @@ int Curl_darwinssl_random(unsigned char *entropy,
|
||||
random_number >>= 8;
|
||||
}
|
||||
i = random_number = 0;
|
||||
return 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_darwinssl_md5sum(unsigned char *tmp, /* input */
|
||||
|
@ -8,7 +8,7 @@
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012 - 2014, Nick Zitzmann, <nickzman@gmail.com>.
|
||||
* Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -42,8 +42,8 @@ int Curl_darwinssl_check_cxn(struct connectdata *conn);
|
||||
bool Curl_darwinssl_data_pending(const struct connectdata *conn,
|
||||
int connindex);
|
||||
|
||||
int Curl_darwinssl_random(unsigned char *entropy,
|
||||
size_t length);
|
||||
CURLcode Curl_darwinssl_random(unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_darwinssl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -1625,21 +1625,21 @@ static int Curl_gtls_seed(struct Curl_easy *data)
|
||||
#endif
|
||||
|
||||
/* data might be NULL! */
|
||||
int Curl_gtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
CURLcode Curl_gtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
#if defined(USE_GNUTLS_NETTLE)
|
||||
int rc;
|
||||
(void)data;
|
||||
rc = gnutls_rnd(GNUTLS_RND_RANDOM, entropy, length);
|
||||
return rc;
|
||||
return rc?CURLE_FAILED_INIT:CURLE_OK;
|
||||
#elif defined(USE_GNUTLS)
|
||||
if(data)
|
||||
Curl_gtls_seed(data); /* Initiate the seed if not already done */
|
||||
gcry_randomize(entropy, length, GCRY_STRONG_RANDOM);
|
||||
#endif
|
||||
return 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_gtls_md5sum(unsigned char *tmp, /* input */
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -43,9 +43,9 @@ void Curl_gtls_close(struct connectdata *conn, int sockindex);
|
||||
void Curl_gtls_session_free(void *ptr);
|
||||
size_t Curl_gtls_version(char *buffer, size_t size);
|
||||
int Curl_gtls_shutdown(struct connectdata *conn, int sockindex);
|
||||
int Curl_gtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
CURLcode Curl_gtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_gtls_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -2138,17 +2138,17 @@ int Curl_nss_seed(struct Curl_easy *data)
|
||||
}
|
||||
|
||||
/* data might be NULL */
|
||||
int Curl_nss_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
CURLcode Curl_nss_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
Curl_nss_seed(data); /* Initiate the seed if not already done */
|
||||
|
||||
if(SECSuccess != PK11_GenerateRandom(entropy, curlx_uztosi(length)))
|
||||
/* signal a failure */
|
||||
return -1;
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
return 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_nss_md5sum(unsigned char *tmp, /* input */
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -47,9 +47,9 @@ int Curl_nss_seed(struct Curl_easy *data);
|
||||
/* initialize NSS library if not already */
|
||||
CURLcode Curl_nss_force_init(struct Curl_easy *data);
|
||||
|
||||
int Curl_nss_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
CURLcode Curl_nss_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
|
||||
void Curl_nss_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -3272,21 +3272,21 @@ size_t Curl_ossl_version(char *buffer, size_t size)
|
||||
}
|
||||
|
||||
/* can be called with data == NULL */
|
||||
int Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length)
|
||||
CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
int rc;
|
||||
if(data) {
|
||||
if(Curl_ossl_seed(data)) /* Initiate the seed if not already done */
|
||||
return 1; /* couldn't seed for some reason */
|
||||
return CURLE_FAILED_INIT; /* couldn't seed for some reason */
|
||||
}
|
||||
else {
|
||||
if(!rand_enough())
|
||||
return 1;
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
/* RAND_bytes() returns 1 on success, 0 otherwise. */
|
||||
rc = RAND_bytes(entropy, curlx_uztosi(length));
|
||||
return rc^1;
|
||||
return rc?CURLE_FAILED_INIT:CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_ossl_md5sum(unsigned char *tmp, /* input */
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -66,8 +66,8 @@ bool Curl_ossl_data_pending(const struct connectdata *conn,
|
||||
int connindex);
|
||||
|
||||
/* return 0 if a find random is filled in */
|
||||
int Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length);
|
||||
CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_ossl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum /* output */,
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2016, Marc Hoersken, <info@marc-hoersken.de>
|
||||
* Copyright (C) 2012, Mark Salisbury, <mark.salisbury@hp.com>
|
||||
* Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -1516,21 +1516,21 @@ size_t Curl_schannel_version(char *buffer, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
int Curl_schannel_random(unsigned char *entropy, size_t length)
|
||||
CURLcode Curl_schannel_random(unsigned char *entropy, size_t length)
|
||||
{
|
||||
HCRYPTPROV hCryptProv = 0;
|
||||
|
||||
if(!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
||||
return 1;
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
if(!CryptGenRandom(hCryptProv, (DWORD)length, entropy)) {
|
||||
CryptReleaseContext(hCryptProv, 0UL);
|
||||
return 1;
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
|
||||
CryptReleaseContext(hCryptProv, 0UL);
|
||||
return 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
|
@ -8,7 +8,7 @@
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012, Marc Hoersken, <info@marc-hoersken.de>, et al.
|
||||
* Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -92,7 +92,7 @@ int Curl_schannel_init(void);
|
||||
void Curl_schannel_cleanup(void);
|
||||
size_t Curl_schannel_version(char *buffer, size_t size);
|
||||
|
||||
int Curl_schannel_random(unsigned char *entropy, size_t length);
|
||||
CURLcode Curl_schannel_random(unsigned char *entropy, size_t length);
|
||||
|
||||
/* Set the API backend definition to Schannel */
|
||||
#define CURL_SSL_BACKEND CURLSSLBACKEND_SCHANNEL
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -703,12 +703,7 @@ CURLcode Curl_ssl_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length)
|
||||
{
|
||||
int rc = curlssl_random(data, entropy, length);
|
||||
if(rc) {
|
||||
failf(data, "PRNG seeding failed");
|
||||
return CURLE_FAILED_INIT; /* possibly weird return code */
|
||||
}
|
||||
return CURLE_OK;
|
||||
return curlssl_random(data, entropy, length);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user