[network] Make http digest auth cnonce length configurable.

This commit is contained in:
Moonchild 2024-05-21 12:30:47 +02:00 committed by roytam1
commit f3413e94b9
2 changed files with 18 additions and 3 deletions

View file

@ -1646,6 +1646,12 @@ pref("network.http.keep_empty_response_headers_as_empty_string", true);
// Max size, in bytes, for received HTTP response header.
pref("network.http.max_response_header_size", 393216);
// This sets the nonce length to verify the server response (via a
// server-returned Authentication-Info header). Also used for session info.
// Note: Range-checked to 4..256, if OOB defaults to 16.
// Note: Chrome uses 16. Larger values may break sites. See Bug 1892449.
pref("network.http.digest_auth_cnonce_length", 16);
// default values for FTP
// in a DSCP environment this should be 40 (0x28, or AF11), per RFC-4594,
// Section 4.8 "High-Throughput Data Service Class", and 80 (0x50, or AF22)

View file

@ -7,6 +7,7 @@
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "mozilla/Preferences.h"
#include "mozilla/Sprintf.h"
#include "nsHttp.h"
@ -20,6 +21,7 @@
#include "nsCRT.h"
#include "nsICryptoHash.h"
#include "nsComponentManagerUtils.h"
#include "pk11pub.h"
namespace mozilla {
namespace net {
@ -302,9 +304,16 @@ nsHttpDigestAuth::GenerateCredentials(nsIHttpAuthenticableChannel *authChannel,
// returned Authentication-Info header). also used for session info.
//
nsAutoCString cnonce;
static const char hexChar[] = "0123456789abcdef";
for (int i=0; i<16; ++i) {
cnonce.Append(hexChar[(int)(15.0 * rand()/(RAND_MAX + 1.0))]);
nsTArray<uint8_t> cnonceBuf;
int cnonceLength = Preferences::GetInt("network.http.digest_auth_cnonce_length", 16);
if (cnonceLength < 4 || cnonceLength > 256) {
cnonceLength = 16;
}
cnonceBuf.SetLength(cnonceLength / 2);
PK11_GenerateRandom(reinterpret_cast<unsigned char*>(cnonceBuf.Elements()),
cnonceBuf.Length());
for (auto byte : cnonceBuf) {
cnonce.AppendPrintf("%02x", byte);
}
LOG((" cnonce=%s\n", cnonce.get()));