@@ -13,7 +13,10 @@ import (
13
13
"github.com/pingcap/errors"
14
14
)
15
15
16
- var ErrAccessDenied = errors .New ("access denied" )
16
+ var (
17
+ ErrAccessDenied = errors .New ("access denied" )
18
+ ErrAccessDeniedNoPassword = fmt .Errorf ("%w without password" , ErrAccessDenied )
19
+ )
17
20
18
21
func (c * Conn ) compareAuthData (authPluginName string , clientAuthData []byte ) error {
19
22
switch authPluginName {
@@ -62,6 +65,14 @@ func (c *Conn) acquirePassword() error {
62
65
return nil
63
66
}
64
67
68
+ func errAccessDenied (password string ) error {
69
+ if password == "" {
70
+ return ErrAccessDeniedNoPassword
71
+ }
72
+
73
+ return ErrAccessDenied
74
+ }
75
+
65
76
func scrambleValidation (cached , nonce , scramble []byte ) bool {
66
77
// SHA256(SHA256(SHA256(STORED_PASSWORD)), NONCE)
67
78
crypt := sha256 .New ()
@@ -83,10 +94,10 @@ func scrambleValidation(cached, nonce, scramble []byte) bool {
83
94
}
84
95
85
96
func (c * Conn ) compareNativePasswordAuthData (clientAuthData []byte , password string ) error {
86
- if bytes .Equal (CalcPassword (c .salt , []byte (c . password )), clientAuthData ) {
97
+ if bytes .Equal (CalcPassword (c .salt , []byte (password )), clientAuthData ) {
87
98
return nil
88
99
}
89
- return ErrAccessDenied
100
+ return errAccessDenied ( password )
90
101
}
91
102
92
103
func (c * Conn ) compareSha256PasswordAuthData (clientAuthData []byte , password string ) error {
@@ -109,7 +120,7 @@ func (c *Conn) compareSha256PasswordAuthData(clientAuthData []byte, password str
109
120
if bytes .Equal (clientAuthData , []byte (password )) {
110
121
return nil
111
122
}
112
- return ErrAccessDenied
123
+ return errAccessDenied ( password )
113
124
} else {
114
125
// client should send encrypted password
115
126
// decrypt
@@ -126,7 +137,7 @@ func (c *Conn) compareSha256PasswordAuthData(clientAuthData []byte, password str
126
137
if bytes .Equal (plain , dbytes ) {
127
138
return nil
128
139
}
129
- return ErrAccessDenied
140
+ return errAccessDenied ( password )
130
141
}
131
142
}
132
143
@@ -153,7 +164,8 @@ func (c *Conn) compareCacheSha2PasswordAuthData(clientAuthData []byte) error {
153
164
// 'fast' auth: write "More data" packet (first byte == 0x01) with the second byte = 0x03
154
165
return c .writeAuthMoreDataFastAuth ()
155
166
}
156
- return ErrAccessDenied
167
+
168
+ return errAccessDenied (c .password )
157
169
}
158
170
// other type of credential provider, we use the cache
159
171
cached , ok := c .serverConf .cacheShaPassword .Load (fmt .Sprintf ("%s@%s" , c .user , c .Conn .LocalAddr ()))
@@ -163,7 +175,8 @@ func (c *Conn) compareCacheSha2PasswordAuthData(clientAuthData []byte) error {
163
175
// 'fast' auth: write "More data" packet (first byte == 0x01) with the second byte = 0x03
164
176
return c .writeAuthMoreDataFastAuth ()
165
177
}
166
- return ErrAccessDenied
178
+
179
+ return errAccessDenied (c .password )
167
180
}
168
181
// cache miss, do full auth
169
182
if err := c .writeAuthMoreDataFullAuth (); err != nil {
0 commit comments