Skip to content

Commit dc28bce

Browse files
committed
Add clear text password authentication
1 parent dec4081 commit dc28bce

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

client/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
const defaultAuthPluginName = mysql.AUTH_NATIVE_PASSWORD
1616

1717
// defines the supported auth plugins
18-
var supportedAuthPlugins = []string{mysql.AUTH_NATIVE_PASSWORD, mysql.AUTH_SHA256_PASSWORD, mysql.AUTH_CACHING_SHA2_PASSWORD, mysql.AUTH_MARIADB_ED25519}
18+
var supportedAuthPlugins = []string{mysql.AUTH_CLEAR_PASSWORD, mysql.AUTH_NATIVE_PASSWORD, mysql.AUTH_SHA256_PASSWORD, mysql.AUTH_CACHING_SHA2_PASSWORD, mysql.AUTH_MARIADB_ED25519}
1919

2020
// helper function to determine what auth methods are allowed by this client
2121
func authPluginAllowed(pluginName string) bool {

server/auth.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package server
22

33
import (
4+
"bytes"
45
"crypto/rand"
56
"crypto/rsa"
67
"crypto/sha1"
@@ -28,6 +29,9 @@ func (c *Conn) compareAuthData(authPluginName string, clientAuthData []byte) err
2829
}
2930

3031
switch authPluginName {
32+
case mysql.AUTH_CLEAR_PASSWORD:
33+
return c.compareClearPasswordAuthData(clientAuthData, c.credential)
34+
3135
case mysql.AUTH_NATIVE_PASSWORD:
3236
return c.compareNativePasswordAuthData(clientAuthData, c.credential)
3337

@@ -102,6 +106,16 @@ func scrambleValidation(cached, nonce, scramble []byte) bool {
102106
return subtle.ConstantTimeCompare(m, cached) == 1
103107
}
104108

109+
func (c *Conn) compareClearPasswordAuthData(clientAuthData []byte, credential Credential) error {
110+
clearText := bytes.TrimRight(clientAuthData, "\x00")
111+
112+
if bytes.Equal([]byte(credential.Password), clearText) {
113+
return nil
114+
}
115+
116+
return errAccessDenied(credential)
117+
}
118+
105119
func (c *Conn) compareNativePasswordAuthData(clientAuthData []byte, credential Credential) error {
106120
password, err := mysql.DecodePasswordHex(c.credential.Password)
107121
if err != nil {

server/server_conf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func NewServer(serverVersion string, collationId uint8, defaultAuthMethod string
9595
}
9696

9797
func isAuthMethodSupported(authMethod string) bool {
98-
return authMethod == mysql.AUTH_NATIVE_PASSWORD || authMethod == mysql.AUTH_CACHING_SHA2_PASSWORD || authMethod == mysql.AUTH_SHA256_PASSWORD
98+
return authMethod == mysql.AUTH_CLEAR_PASSWORD || authMethod == mysql.AUTH_NATIVE_PASSWORD || authMethod == mysql.AUTH_CACHING_SHA2_PASSWORD || authMethod == mysql.AUTH_SHA256_PASSWORD
9999
}
100100

101101
func (s *Server) InvalidateCache(username string, host string) {

0 commit comments

Comments
 (0)