@@ -64,6 +64,7 @@ function FakeConnection(socket) {
64
64
this . _handshakeInitializationPacket = null ;
65
65
this . _clientAuthenticationPacket = null ;
66
66
this . _oldPasswordPacket = null ;
67
+ this . _authSwitchResponse = null ;
67
68
this . _handshakeOptions = { } ;
68
69
69
70
socket . on ( 'data' , this . _handleData . bind ( this ) ) ;
@@ -91,9 +92,7 @@ FakeConnection.prototype.deny = function(message, errno) {
91
92
} ) ) ;
92
93
} ;
93
94
94
- FakeConnection . prototype . _sendAuthResponse = function ( packet , expected ) {
95
- var got = packet . scrambleBuff ;
96
-
95
+ FakeConnection . prototype . _sendAuthResponse = function _sendAuthResponse ( got , expected ) {
97
96
if ( expected . toString ( 'hex' ) === got . toString ( 'hex' ) ) {
98
97
this . _sendPacket ( new Packets . OkPacket ( ) ) ;
99
98
} else {
@@ -269,9 +268,11 @@ FakeConnection.prototype._parsePacket = function(header) {
269
268
this . _clientAuthenticationPacket = packet ;
270
269
if ( this . _handshakeOptions . oldPassword ) {
271
270
this . _sendPacket ( new Packets . UseOldPasswordPacket ( ) ) ;
271
+ } else if ( this . _handshakeOptions . authMethodName ) {
272
+ this . _sendPacket ( new Packets . AuthSwitchRequestPacket ( this . _handshakeOptions ) ) ;
272
273
} else if ( this . _handshakeOptions . password === 'passwd' ) {
273
274
var expected = Buffer . from ( '3DA0ADA7C9E1BB3A110575DF53306F9D2DE7FD09' , 'hex' ) ;
274
- this . _sendAuthResponse ( packet , expected ) ;
275
+ this . _sendAuthResponse ( packet . scrambleBuff , expected ) ;
275
276
} else if ( this . _handshakeOptions . user || this . _handshakeOptions . password ) {
276
277
throw new Error ( 'not implemented' ) ;
277
278
} else {
@@ -287,7 +288,14 @@ FakeConnection.prototype._parsePacket = function(header) {
287
288
288
289
var expected = Auth . scramble323 ( this . _handshakeInitializationPacket . scrambleBuff ( ) , this . _handshakeOptions . password ) ;
289
290
290
- this . _sendAuthResponse ( packet , expected ) ;
291
+ this . _sendAuthResponse ( packet . scrambleBuff , expected ) ;
292
+ break ;
293
+ case Packets . AuthSwitchResponsePacket :
294
+ this . _authSwitchResponse = packet ;
295
+
296
+ var expected = Auth . token ( this . _handshakeOptions . password , Buffer . from ( '00112233445566778899AABBCCDDEEFF01020304' , 'hex' ) ) ;
297
+
298
+ this . _sendAuthResponse ( packet . data , expected ) ;
291
299
break ;
292
300
case Packets . ComQueryPacket :
293
301
if ( ! this . emit ( 'query' , packet ) ) {
@@ -355,6 +363,10 @@ FakeConnection.prototype._determinePacket = function(header) {
355
363
return Packets . OldPasswordPacket ;
356
364
}
357
365
366
+ if ( this . _handshakeOptions . authMethodName && ! this . _authSwitchResponse ) {
367
+ return Packets . AuthSwitchResponsePacket ;
368
+ }
369
+
358
370
var firstByte = this . _parser . peak ( ) ;
359
371
switch ( firstByte ) {
360
372
case 0x01 : return Packets . ComQuitPacket ;
0 commit comments