Skip to content

Commit 0efd2a0

Browse files
committed
Error should be decided against client data, not server password
1 parent dd26f97 commit 0efd2a0

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

server/auth.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ func (c *Conn) acquirePassword() error {
4545
return nil
4646
}
4747

48-
func errAccessDenied(credential Credential) error {
49-
if credential.Password == "" {
50-
return ErrAccessDeniedNoPassword
51-
}
52-
53-
return ErrAccessDenied
54-
}
55-
5648
func scrambleValidation(cached, nonce, scramble []byte) bool {
5749
// SHA256(SHA256(SHA256(STORED_PASSWORD)), NONCE)
5850
crypt := sha256.New()
@@ -74,14 +66,21 @@ func scrambleValidation(cached, nonce, scramble []byte) bool {
7466
}
7567

7668
func (c *Conn) compareNativePasswordAuthData(clientAuthData []byte, credential Credential) error {
69+
if len(clientAuthData) == 0 {
70+
if credential.Password == "" {
71+
return nil
72+
}
73+
return ErrAccessDeniedNoPassword
74+
}
75+
7776
password, err := mysql.DecodePasswordHex(c.credential.Password)
7877
if err != nil {
79-
return errAccessDenied(credential)
78+
return ErrAccessDenied
8079
}
8180
if mysql.CompareNativePassword(clientAuthData, password, c.salt) {
8281
return nil
8382
}
84-
return errAccessDenied(credential)
83+
return ErrAccessDenied
8584
}
8685

8786
func (c *Conn) compareSha256PasswordAuthData(clientAuthData []byte, credential Credential) error {
@@ -141,7 +140,7 @@ func (c *Conn) compareCacheSha2PasswordAuthData(clientAuthData []byte) error {
141140
return c.writeAuthMoreDataFastAuth()
142141
}
143142

144-
return errAccessDenied(c.credential)
143+
return ErrAccessDenied
145144
}
146145
// cache miss, do full auth
147146
if err := c.writeAuthMoreDataFullAuth(); err != nil {

server/auth_switch_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (c *Conn) checkSha2CacheCredentials(clientAuthData []byte, credential Crede
7575
if match && err == nil {
7676
return nil
7777
}
78-
return errAccessDenied(credential)
78+
return ErrAccessDenied
7979
}
8080

8181
func (c *Conn) writeCachingSha2Cache(authData []byte) {

0 commit comments

Comments
 (0)