-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement HTTP Digest Access Authentication #2089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the comments and let me know If the observations make sense...
If you'd like, I can pick up these fixes and push the changes (along with tests) on top of this PR to help wrap it up faster.
Let me know... happy to help!!!
if (end == -1) return null; | ||
return headerLine.substring(start, end); | ||
} | ||
|
||
private void newCnonce(MessageDigest md) { | ||
byte[] b = new byte[8]; | ||
ThreadLocalRandom.current().nextBytes(b); | ||
b = md.digest(b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MD5 =16 bytes; SHA-256 = 32 bytes;
rfc7616 doesn’t forbid long nonces... but wont the headers that big can be unwieldy, especially if you’re proxying or logging??
return MessageDigestUtils.pooledMd5MessageDigest(); | ||
} else if ("SHA-256".equalsIgnoreCase(algorithm) || "SHA-256-sess".equalsIgnoreCase(algorithm)) { | ||
return MessageDigestUtils.pooledSha256MessageDigest(); | ||
} else if ("SHA-512-256".equalsIgnoreCase(algorithm) || "SHA-512-256-sess".equalsIgnoreCase(algorithm)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it handle "SHA-512/256" ??
some server might send with / 's
and even "SHA-512/256" is mentioned in standard names docs... https://docs.oracle.com/en/java/javase/12/docs/specs/security/standard-names.html
} | ||
|
||
private static byte[] md5FromRecycledStringBuilder(StringBuilder sb, MessageDigest md) { | ||
private static byte[] digestFromRecycledStringBuilder(StringBuilder sb, MessageDigest md) { | ||
md.update(StringUtils.charSequence2ByteBuffer(sb, ISO_8859_1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
md.update(StringUtils.charSequence2ByteBuffer(sb, ISO_8859_1)); | ||
sb.setLength(0); | ||
return md.digest(); | ||
} | ||
|
||
private static MessageDigest getDigestInstance(String algorithm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RFC 7616 - HTTP Digest Access Authentication
Closes #2068