Browse files

New AuthenticationFallbackPacket

  • Loading branch information...
1 parent 3f3564c commit 2d7386057474c0111c43dd3d4e52e83cee59e012 @felixge felixge committed Dec 30, 2011
View
22 lib/protocol/Handshake.js
@@ -1,9 +1,9 @@
-var Util = require('util');
-var EventEmitter = require('events').EventEmitter;
-var Parser = require('../Parser');
-var AuthenticationPacket = require('./packets/client/AuthenticationPacket');
-var LegacyAuthenticationPacket = require('./packets/client/LegacyAuthenticationPacket');
-var Auth = require('../Auth');
+var Util = require('util');
+var EventEmitter = require('events').EventEmitter;
+var Parser = require('../Parser');
+var AuthenticationPacket = require('./packets/client/AuthenticationPacket');
+var AuthenticationFallbackPacket = require('./packets/client/AuthenticationFallbackPacket');
+var Auth = require('../Auth');
module.exports = Handshake;
Util.inherits(Handshake, EventEmitter);
@@ -17,7 +17,7 @@ function Handshake(properties) {
this._maxPacketSize = properties.maxPacketSize;
this._charsetNumber = properties.charsetNumber;
- this._scrambleBuffer = null;
+ this._scrambleBuff = null;
}
Handshake.prototype.handlePacket = function(packet) {
@@ -35,14 +35,14 @@ Handshake.prototype.handlePacket = function(packet) {
// Keep a reference to the greeting packet. We might receive a
// USE_OLD_PASSWORD_PROTOCOL_PACKET as a response, in which case we will need
// the greeting packet again. See _sendOldAuth()
- this._scrambleBuffer = packet.scrambleBuffer;
+ this._scrambleBuff = packet.scrambleBuffer;
return;
}
if (packet.type == Parser.USE_OLD_PASSWORD_PROTOCOL_PACKET) {
- this.emit('packet', new LegacyAuthenticationPacket({
- number : packet.number + 1,
- scrambleBuffer : this._scrambleBuffer,
+ this.emit('packet', new AuthenticationFallbackPacket({
+ number : packet.number + 1,
+ scrambleBuff : Auth.scramble323(this._scrambleBuff, this._password),
}));
return;
}
View
16 lib/protocol/packets/client/AuthenticationFallbackPacket.js
@@ -0,0 +1,16 @@
+var Packet = require('../Packet');
+var Util = require('util');
+var Elements = require('../../elements');
+
+// This is the follow-up packet we send to a server that wants to use the old
+// authentication mechanism after we initially replied to his greeting with
+// an AuthenticationPacket.
+//
+// This seems to currently be undocumented in the MySql protocol, I found it
+// by sniffing the mysql command line client.
+
+module.exports = AuthenticationFallbackPacket;
+Util.inherits(AuthenticationFallbackPacket, Packet);
+function AuthenticationFallbackPacket(properties) {
+ this.scrambleBuff = new Elements.LengthCodedString(properties.scrambleBuff);
+}
View
9 lib/protocol/packets/client/AuthenticationPacket.js
@@ -1,8 +1,9 @@
-var _ = require('underscore');
var Packet = require('../Packet');
var Util = require('util');
var Elements = require('../../elements');
+// From client to server during initial handshake.
+//
// VERSION 4.1
// Bytes Name
// ----- ----
@@ -38,6 +39,12 @@ var Elements = require('../../elements');
//
// databasename: name of schema to use initially
//
+// The scramble_buff and databasename fields are optional. The length-coding
+// byte for the scramble_buff will always be given, even if it's zero.
+// Alternative terms: "Client authentication packet" is sometimes called
+// "client auth response" or "client auth packet" or "login packet".
+// "Scramble_buff" is sometimes called "crypted password".
+//
// http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Client_Authentication_Packeto
module.exports = AuthenticationPacket;
View
30 lib/protocol/packets/client/LegacyAuthenticationPacket.js
@@ -1,30 +0,0 @@
-var Auth = require('../../../Auth');
-var OutgoingPacket = require('../../../OutgoingPacket');
-
-// Client_Authentication_Packet (MySql < 4.1)
-// http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Client_Authentication_Packet
-//
-// This is the follow-up packet we send to a server that wants to use the old
-// authentication mechanism after we initially replied to his greeting with
-// an AuthenticationPacket.
-module.exports = LegacyAuthenticationPacket;
-function LegacyAuthenticationPacket(properties) {
- this._number = properties.number;
- this._scrambleBuffer = properties.scrambleBuffer;
-}
-
-LegacyAuthenticationPacket.prototype.toBuffer = function() {
- var token = Auth.scramble323(this._scrambleBuffer, this._password);
- var packetSize = (
- token.length + 1
- );
- var packet = new OutgoingPacket(packetSize, this._number);
-
- // I could not find any official documentation for this, but from sniffing
- // the mysql command line client, I think this is the right way to send the
- // scrambled token after receiving the USE_OLD_PASSWORD_PROTOCOL_PACKET.
- packet.write(token);
- packet.writeFiller(1);
-
- return packet.buffer;
-};

0 comments on commit 2d73860

Please sign in to comment.