Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions client/src/main/java/org/asynchttpclient/Realm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -283,6 +283,9 @@ public enum AuthScheme {
*/
public static class Builder {

// cnonce must be unpredictable (RFC 7616 section 3.3), like the NTLM and SCRAM nonces
private static final SecureRandom CNONCE_RANDOM = new SecureRandom();

private final @Nullable String principal;
private final @Nullable String password;
private @Nullable AuthScheme scheme;
Expand Down Expand Up @@ -610,7 +613,7 @@ public Builder parseProxyAuthenticateHeader(String headerLine) {

private void newCnonce(MessageDigest md) {
byte[] b = new byte[8];
ThreadLocalRandom.current().nextBytes(b);
CNONCE_RANDOM.nextBytes(b);
byte[] full = md.digest(b);
// trim to first 8 bytes → 16 hex chars
byte[] small = Arrays.copyOf(full, Math.min(8, full.length));
Expand Down
Loading