random: use Curl_rand() for proper random data
The SASL/Digest previously used the current time's seconds + microseconds to add randomness but it is much better to instead get more data from Curl_rand(). It will also allow us to easier "fake" that for debug builds on demand in a future.
This commit is contained in:
parent
62a26ec696
commit
bbd3dc611e
@ -423,9 +423,6 @@ CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
|
|||||||
unsigned int cnonce2 = 0;
|
unsigned int cnonce2 = 0;
|
||||||
unsigned int cnonce3 = 0;
|
unsigned int cnonce3 = 0;
|
||||||
unsigned int cnonce4 = 0;
|
unsigned int cnonce4 = 0;
|
||||||
#ifndef DEBUGBUILD
|
|
||||||
struct timeval now;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char nonceCount[] = "00000001";
|
char nonceCount[] = "00000001";
|
||||||
char method[] = "AUTHENTICATE";
|
char method[] = "AUTHENTICATE";
|
||||||
@ -457,9 +454,8 @@ CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
|
|||||||
/* Generate 16 bytes of random data */
|
/* Generate 16 bytes of random data */
|
||||||
cnonce1 = Curl_rand(data);
|
cnonce1 = Curl_rand(data);
|
||||||
cnonce2 = Curl_rand(data);
|
cnonce2 = Curl_rand(data);
|
||||||
now = Curl_tvnow();
|
cnonce3 = Curl_rand(data);
|
||||||
cnonce3 = now.tv_sec;
|
cnonce4 = Curl_rand(data);
|
||||||
cnonce4 = now.tv_usec;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Convert the random data into a 32 byte hex string */
|
/* Convert the random data into a 32 byte hex string */
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@ -367,12 +367,9 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
d->nc = 1;
|
d->nc = 1;
|
||||||
|
|
||||||
if(!d->cnonce) {
|
if(!d->cnonce) {
|
||||||
struct timeval now = Curl_tvnow();
|
|
||||||
snprintf(cnoncebuf, sizeof(cnoncebuf), "%08x%08x%08x%08x",
|
snprintf(cnoncebuf, sizeof(cnoncebuf), "%08x%08x%08x%08x",
|
||||||
Curl_rand(data), Curl_rand(data),
|
Curl_rand(data), Curl_rand(data),
|
||||||
(unsigned int)now.tv_sec,
|
Curl_rand(data), Curl_rand(data));
|
||||||
(unsigned int)now.tv_usec);
|
|
||||||
|
|
||||||
rc = Curl_base64_encode(data, cnoncebuf, strlen(cnoncebuf),
|
rc = Curl_base64_encode(data, cnoncebuf, strlen(cnoncebuf),
|
||||||
&cnonce, &cnonce_sz);
|
&cnonce, &cnonce_sz);
|
||||||
if(rc)
|
if(rc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user