Scoop API

scoop:scoop.http.client:0.1.0

src/authentication/digest/credentials.scoop

Selected production source · src/authentication/digest/credentials.scoop

1package scoop.http.client
3import scoop.charset.*
5internal suspend fun clientDigestSecret(call: ClientCall, selection: ClientDigestSession,
6 provider: ClientDigestAuthentication): ClientDigestSecret {
7 val scope = selection.entry.scope
8 val challenge = selection.nonce.challenge
9 val credentials = provider.credentials(scope.request(call, Some(challenge.original)))
10 requireClientCall(call)
11 val username = if (challenge.utf8) normalizeNfc(credentials.username) else credentials.username
12 val password = if (challenge.utf8) normalizeNfc(credentials.password) else credentials.password
13 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_1
20 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 }