Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf3e161

Browse files
committed
minor clean up
1 parent633c3c5 commitaf3e161

File tree

1 file changed

+22
-11
lines changed
  • client/src/main/java/org/asynchttpclient

1 file changed

+22
-11
lines changed

‎client/src/main/java/org/asynchttpclient/Realm.java‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
publicclassRealm {
3838

3939
privatestaticfinalStringDEFAULT_NC ="00000001";
40+
// MD5("")
4041
privatestaticfinalStringEMPTY_ENTITY_MD5 ="d41d8cd98f00b204e9800998ecf8427e";
4142

4243
privatefinalStringprincipal;
@@ -412,26 +413,35 @@ private byte[] md5FromRecycledStringBuilder(StringBuilder sb, MessageDigest md)
412413
returnmd.digest();
413414
}
414415

415-
privatebyte[]secretDigest(StringBuildersb,MessageDigestmd) {
416+
privatebyte[]ha1(StringBuildersb,MessageDigestmd) {
417+
// if algorithm is "MD5" or is unspecified => A1 = username ":" realm-value ":" passwd
418+
// if algorithm is "MD5-sess" => A1 = MD5( username-value ":" realm-value ":" passwd ) ":" nonce-value ":" cnonce-value
416419

417420
sb.append(principal).append(':').append(realmName).append(':').append(password);
418-
byte[]ha1 =md5FromRecycledStringBuilder(sb,md);
421+
byte[]core =md5FromRecycledStringBuilder(sb,md);
419422

420423
if (algorithm ==null ||algorithm.equals("MD5")) {
421-
returnha1;
424+
// A1 = username ":" realm-value ":" passwd
425+
returncore;
422426
}elseif ("MD5-sess".equals(algorithm)) {
423-
appendBase16(sb,ha1);
427+
// A1 = MD5(username ":" realm-value ":" passwd ) ":" nonce ":" cnonce
428+
appendBase16(sb,core);
424429
sb.append(':').append(nonce).append(':').append(cnonce);
425430
returnmd5FromRecycledStringBuilder(sb,md);
426431
}
427432

428433
thrownewUnsupportedOperationException("Digest algorithm not supported: " +algorithm);
429434
}
430435

431-
privatebyte[]dataDigest(StringBuildersb,StringdigestUri,MessageDigestmd) {
436+
privatebyte[]ha2(StringBuildersb,StringdigestUri,MessageDigestmd) {
432437

438+
// if qop is "auth" or is unspecified => A2 = Method ":" digest-uri-value
439+
// if qop is "auth-int" => A2 = Method ":" digest-uri-value ":" H(entity-body)
433440
sb.append(methodName).append(':').append(digestUri);
434441
if ("auth-int".equals(qop)) {
442+
// when qop == "auth-int", A2 = Method ":" digest-uri-value ":" H(entity-body)
443+
// but we don't have the request body here
444+
// we would need a new API
435445
sb.append(':').append(EMPTY_ENTITY_MD5);
436446

437447
}elseif (qop !=null && !qop.equals("auth")) {
@@ -441,7 +451,8 @@ private byte[] dataDigest(StringBuilder sb, String digestUri, MessageDigest md)
441451
returnmd5FromRecycledStringBuilder(sb,md);
442452
}
443453

444-
privatevoidappendDataBase(StringBuildersb) {
454+
privatevoidappendMiddlePart(StringBuildersb) {
455+
// request-digest = MD5(H(A1) ":" nonce ":" nc ":" cnonce ":" qop ":" H(A2))
445456
sb.append(':').append(nonce).append(':');
446457
if ("auth".equals(qop) ||"auth-int".equals(qop)) {
447458
sb.append(nc).append(':').append(cnonce).append(':').append(qop).append(':');
@@ -457,12 +468,12 @@ private void newResponse(MessageDigest md) {
457468
StringBuildersb =StringBuilderPool.DEFAULT.stringBuilder();
458469

459470
// WARNING: DON'T MOVE, BUFFER IS RECYCLED!!!!
460-
byte[]secretDigest =secretDigest(sb,md);
461-
byte[]dataDigest =dataDigest(sb,digestUri,md);
471+
byte[]ha1 =ha1(sb,md);
472+
byte[]ha2 =ha2(sb,digestUri,md);
462473

463-
appendBase16(sb,secretDigest);
464-
appendDataBase(sb);
465-
appendBase16(sb,dataDigest);
474+
appendBase16(sb,ha1);
475+
appendMiddlePart(sb);
476+
appendBase16(sb,ha2);
466477

467478
byte[]responseDigest =md5FromRecycledStringBuilder(sb,md);
468479
response =toHexString(responseDigest);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp