MCPcopy Create free account
hub / github.com/dolthub/doltgresql / verifySASLClientProof

Function verifySASLClientProof

server/authentication_scram.go:296–314  ·  view source on GitHub ↗

verifySASLClientProof verifies that the proof given by the client in valid. Returns the base64-encoded ServerSignature, which verifies (to the client) that the server has proper access to the client's authentication information.

(user auth.Role, saslInitial SASLInitial, saslContinue SASLContinue, saslResponse SASLResponse)

Source from the content-addressed store, hash-verified

294// ServerSignature, which verifies (to the client) that the server has proper access to the client's authentication
295// information.
296func verifySASLClientProof(user auth.Role, saslInitial SASLInitial, saslContinue SASLContinue, saslResponse SASLResponse) (string, error) {
297 if !user.CanLogin || user.Password == nil {
298 return "", errors.Errorf(`password authentication failed for user "%s"`, user.Name)
299 }
300 // TODO: check the "valid until" time
301 clientProof := rfc5802.Base64ToOctetString(saslResponse.ClientProof)
302 authMessage := fmt.Sprintf("%s,%s,%s", saslInitial.MessageBare(), saslContinue.Encode().Data, saslResponse.MessageWithoutProof())
303 clientSignature := rfc5802.ClientSignature(user.Password.StoredKey, authMessage)
304 if len(clientProof) != len(clientSignature) {
305 return "", errors.Errorf(`password authentication failed for user "%s"`, user.Name)
306 }
307 clientKey := clientSignature.Xor(clientProof)
308 storedKey := rfc5802.StoredKey(clientKey)
309 if !storedKey.Equals(user.Password.StoredKey) {
310 return "", errors.Errorf(`password authentication failed for user "%s"`, user.Name)
311 }
312 serverSignature := rfc5802.ServerSignature(user.Password.ServerKey, authMessage)
313 return serverSignature.ToBase64(), nil
314}
315
316// Base64Header returns the base64-encoded GS2 header and channel binding data.
317func (si SASLInitial) Base64Header() string {

Callers 1

handleAuthenticationMethod · 0.85

Calls 11

Base64ToOctetStringFunction · 0.92
ClientSignatureFunction · 0.92
StoredKeyFunction · 0.92
ServerSignatureFunction · 0.92
MessageBareMethod · 0.80
MessageWithoutProofMethod · 0.80
ToBase64Method · 0.80
ErrorfMethod · 0.65
EncodeMethod · 0.45
XorMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected