scoop:scoop.http.client:0.1.0
src/authentication/digest/credentials.scoop
Selected production source · src/authentication/digest/credentials.scoop
1
package scoop.http.client3
import scoop.charset.*5
internal suspend fun clientDigestSecret(call: ClientCall, selection: ClientDigestSession,6
provider: ClientDigestAuthentication): ClientDigestSecret {7
val scope = selection.entry.scope8
val challenge = selection.nonce.challenge9
val credentials = provider.credentials(scope.request(call, Some(challenge.original)))10
requireClientCall(call)11
val username = if (challenge.utf8) normalizeNfc(credentials.username) else credentials.username12
val password = if (challenge.utf8) normalizeNfc(credentials.password) else credentials.password13
for (character in username) {14
if (character.code < 32 || character.code == 127 || character == ':')15
throw HttpAuthenticationException(HttpAuthenticationFailure.InvalidCredentials, scope.url(call))16
}17
for (character in password) if (character.code < 32 || character.code == 127)18
throw HttpAuthenticationException(HttpAuthenticationFailure.InvalidCredentials, scope.url(call))19
val charset = if (challenge.utf8) Charset.Utf8 else Charset.Iso8859_120
try {21
val ha1 = clientDigestHash(challenge.algorithm,22
[charset.encode(username), ":".toByteArray(), challenge.realm, ":".toByteArray(), charset.encode(password)])23
return ClientDigestSecret(username, ha1)24
} catch (error: CharsetException) {25
throw HttpAuthenticationException(HttpAuthenticationFailure.InvalidCredentials, scope.url(call), cause = Some(error))26
}27
}