Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions client/src/main/java/org/asynchttpclient/Realm.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,10 @@ private byte[] ha2(StringBuilder sb, String digestUri, MessageDigest md) {
if (entityBodyHash != null) {
sb.append(entityBodyHash);
} else {
// Hash of empty body using the current algorithm
sb.append(toHexString(md.digest()));
// Hash of empty body using the current algorithm. Must append in place:
// toHexString() would take the same recycled builder and reset it, dropping
// the method and digest-uri already written above.
appendBase16(sb, md.digest());
}
} else if (qop != null && !"auth".equals(qop)) {
throw new UnsupportedOperationException("Digest qop not supported: " + qop);
Expand Down
26 changes: 26 additions & 0 deletions client/src/test/java/org/asynchttpclient/RealmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ public void testStrongDigest() throws Exception {
assertEquals(orig.getResponse(), expectedResponse);
}

@RepeatedIfExceptionsTest(repeats = 5)
public void testAuthIntDigestKeepsMethodAndUriInA2() throws Exception {
String user = "user";
String pass = "pass";
String realm = "realm";
String nonce = "nonce";
String method = "POST";
Uri uri = Uri.create("http://ahc.io/foo");
String qop = "auth-int";
Realm orig = digestAuthRealm(user, pass)
.setNonce(nonce)
.setUri(uri)
.setMethodName(method)
.setRealmName(realm)
.setQop(qop)
.build();

String nc = orig.getNc();
String cnonce = orig.getCnonce();
String ha1 = getMd5(user + ':' + realm + ':' + pass);
String ha2 = getMd5(method + ':' + uri.getPath() + ':' + getMd5(""));
String expectedResponse = getMd5(ha1 + ':' + nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2);

assertEquals(expectedResponse, orig.getResponse());
}

// Phase 1: matchParam tests
@Test
public void testMatchParamUnquotedAlgorithm() {
Expand Down
Loading