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)
| 294 | // ServerSignature, which verifies (to the client) that the server has proper access to the client's authentication |
| 295 | // information. |
| 296 | func 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. |
| 317 | func (si SASLInitial) Base64Header() string { |
no test coverage detected