digest: produce a shorter cnonce in Digest headers

Other programs (Postman, Chrome, Python request) use a 16 byte cnonce
and there are instances of server-side implementations that don't
support the larger lengths curl used previously.

Fixes #15653
Reported-by: Florian Eckert
Closes #15670
This commit is contained in:
Daniel Stenberg 2024-12-03 07:52:48 +01:00
parent 509f50e58d
commit c948971e83
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -709,13 +709,17 @@ static CURLcode auth_create_digest_http_message(
digest->nc = 1;
if(!digest->cnonce) {
char cnoncebuf[33];
result = Curl_rand_hex(data, (unsigned char *)cnoncebuf,
sizeof(cnoncebuf));
char cnoncebuf[12];
result = Curl_rand_bytes(data,
#ifdef DEBUGBUILD
TRUE,
#endif
(unsigned char *)cnoncebuf,
sizeof(cnoncebuf));
if(result)
return result;
result = Curl_base64_encode(cnoncebuf, strlen(cnoncebuf),
result = Curl_base64_encode(cnoncebuf, sizeof(cnoncebuf),
&cnonce, &cnonce_sz);
if(result)
return result;