question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ktor Client Digest Auth Missing "qop" and "end" tokens in "response" parameter. Not RFC2617 Compliant

See original GitHub issue

Ktor 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cy6erGn0mcommented, Oct 5, 2019

Thank you for your investigation and detailed explanation

0reactions
e5lcommented, Dec 12, 2019

Merged.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found