Ktor Client Digest Auth Missing "qop" and "end" tokens in "response" parameter. Not RFC2617 Compliant
See original GitHub issueKtor Version and Engine Used (client or server and name) ktor-client-auth 1.2.5
Describe the bug
val client = HttpClient(Apache) {
install(Auth) {
digest {
username = "user"
password = "pass"
realm = "realm"
}
}
}
Using this code does not properly handle Digest authentication. The reason why is located right here. The non-null qop should include the qop and the end variable in the token.
If you take a look at the RFC 2617 here, the request-digest states the following:
If the "qop" value is "auth" or "auth-int":
request-digest = <"> < KD ( H(A1), unq(nonce-value)
":" nc-value
":" unq(cnonce-value)
":" unq(qop-value)
":" H(A2)
) <">
Notice the qop-value and H(A2) there. That’s what’s missing. Interestingly enough, it’s implemented correctly in the ktor server side code
It’s a simple enough fix and I’ve already forked and will work on a PR for this, but my VM is running out of memory trying to build the project so it may take a bit. But it really should be as simple as doing the following diff:
diff --git a/ktor-client/ktor-client-features/ktor-client-auth/common/src/io/ktor/client/features/auth/providers/DigestAuthProvider.kt b/ktor-client/ktor-client-features/ktor-client-auth/common/src/io/ktor/client/features/auth/providers/DigestAuthProvider.kt
index 6ed33248f..1a12248dc 100644
--- a/ktor-client/ktor-client-features/ktor-client-auth/common/src/io/ktor/client/features/auth/providers/DigestAuthProvider.kt
+++ b/ktor-client/ktor-client-features/ktor-client-auth/common/src/io/ktor/client/features/auth/providers/DigestAuthProvider.kt
@@ -83,7 +83,7 @@ class DigestAuthProvider(
val start = hex(credential)
val end = hex(makeDigest("$methodName:${url.encodedPath}"))
- val tokenSequence = if (actualQop == null) listOf(start, nonce, end) else listOf(start, nonce, nonceCount, clientNonce)
+ val tokenSequence = if (actualQop == null) listOf(start, nonce, end) else listOf(start, nonce, nonceCount, clientNonce, actualQop, end)
val token = makeDigest(tokenSequence.joinToString(":"))
val auth = HttpAuthHeader.Parameterized(AuthScheme.Digest, linkedMapOf<String, String>().apply {
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Authentication and authorization | Ktor
Digest - an authentication method that communicates user credentials in an encrypted form by applying a hash function to the username and ...
Read more >Digest access authentication - Wikipedia
Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials, such as username or password, with...
Read more >Create a Secure Ktor Application with Kotlin - Okta Developer
Configure Ktor's OAuth 2.0 Module · Setup a Ktor Authentication Module · Sign in with the /login endpoint · Authorization endpoint /login/ ...
Read more >DigestAuth challenge response is missing the `algorithm` value
ktor -client-auth fail a Digest auth challenge (Using version 2.0.0-eap-275). After investigation, I can say that this is not a bug per se...
Read more >ktor digest Authentication - Stack Overflow
When setting up the server, you're missing the realm: install(Authentication) { digest("myDigestAuth") { realm = myRealm // This part is ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your investigation and detailed explanation
Merged.