@@ -173,7 +173,7 @@ private void handleAuthentication(ByteBuf payload) {
173
173
handleErrorPacketPayload (payload );
174
174
break ;
175
175
case AUTH_SWITCH_REQUEST_STATUS_FLAG :
176
- handleAuthSwitchRequest (cmd .password (). getBytes ( StandardCharsets . UTF_8 ) , payload );
176
+ handleAuthSwitchRequest (cmd .password (), payload );
177
177
break ;
178
178
case AUTH_MORE_DATA_STATUS_FLAG :
179
179
handleAuthMoreData (cmd .password ().getBytes (StandardCharsets .UTF_8 ), payload );
@@ -183,28 +183,28 @@ private void handleAuthentication(ByteBuf payload) {
183
183
}
184
184
}
185
185
186
- private void handleAuthSwitchRequest (byte [] password , ByteBuf payload ) {
186
+ private void handleAuthSwitchRequest (String password , ByteBuf payload ) {
187
187
// Protocol::AuthSwitchRequest
188
188
payload .skipBytes (1 ); // status flag, always 0xFE
189
189
String pluginName = BufferUtils .readNullTerminatedString (payload , StandardCharsets .UTF_8 );
190
190
byte [] nonce = new byte [NONCE_LENGTH ];
191
191
payload .readBytes (nonce );
192
- byte [] authResponse ;
193
192
switch (pluginName ) {
194
193
case "mysql_native_password" :
195
- authResponse = Native41Authenticator .encode (password , nonce );
194
+ sendBytesAsPacket ( Native41Authenticator .encode (password . getBytes ( StandardCharsets . UTF_8 ) , nonce ) );
196
195
break ;
197
196
case "caching_sha2_password" :
198
- authResponse = CachingSha2Authenticator .encode (password , nonce );
197
+ sendBytesAsPacket ( CachingSha2Authenticator .encode (password . getBytes ( StandardCharsets . UTF_8 ) , nonce ) );
199
198
break ;
200
199
case "mysql_clear_password" :
201
- authResponse = password ;
200
+ ByteBuf buffer = encoder .chctx .alloc ().buffer ();
201
+ BufferUtils .writeNullTerminatedString (buffer , password , StandardCharsets .UTF_8 );
202
+ sendNonSplitPacket (buffer );
202
203
break ;
203
204
default :
204
205
encoder .handleCommandResponse (CommandResponse .failure (new UnsupportedOperationException ("Unsupported authentication method: " + pluginName )));
205
206
return ;
206
207
}
207
- sendBytesAsPacket (authResponse );
208
208
}
209
209
210
210
private void sendSslRequest () {
@@ -249,7 +249,10 @@ private void sendHandshakeResponseMessage(String username, String password, Stri
249
249
authResponse = CachingSha2Authenticator .encode (password .getBytes (StandardCharsets .UTF_8 ), nonce );
250
250
break ;
251
251
case "mysql_clear_password" :
252
- authResponse = password .getBytes (StandardCharsets .UTF_8 );
252
+ ByteBuf buffer = encoder .chctx .alloc ().heapBuffer ();
253
+ BufferUtils .writeNullTerminatedString (buffer , password , StandardCharsets .UTF_8 );
254
+ authResponse = new byte [buffer .readableBytes ()];
255
+ buffer .readBytes (authResponse );
253
256
break ;
254
257
default :
255
258
LOGGER .warn ("Unknown authentication method: " + authMethod + ", the client will try to use mysql_native_password instead." );
0 commit comments