Skip to content

Commit 154d69c

Browse files
committed
Extract password hashing from AuthenticationPacket
Inversion of control folks, inversion of control.
1 parent 97ef16f commit 154d69c

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lib/protocol/Handshake.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var EventEmitter = require('events').EventEmitter;
33
var Parser = require('../Parser');
44
var AuthenticationPacket = require('./packets/client/AuthenticationPacket');
55
var LegacyAuthenticationPacket = require('./packets/client/LegacyAuthenticationPacket');
6+
var Auth = require('../Auth');
67

78
module.exports = Handshake;
89
Util.inherits(Handshake, EventEmitter);
@@ -23,8 +24,7 @@ Handshake.prototype.handlePacket = function(packet) {
2324
if (packet.type == Parser.GREETING_PACKET) {
2425
this.emit('packet', new AuthenticationPacket({
2526
number : packet.number + 1,
26-
scrambleBuffer : packet.scrambleBuffer,
27-
password : this._password,
27+
token : Auth.token(this._password, packet.scrambleBuffer),
2828
user : this._user,
2929
database : this._database,
3030
flags : this._flags,

lib/protocol/packets/client/AuthenticationPacket.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
var _ = require('underscore');
2-
var Auth = require('../../../Auth');
32
var OutgoingPacket = require('../../../OutgoingPacket');
43

54
// Client_Authentication_Packet (MySql >= 4.1)
65
// http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Client_Authentication_Packet
76
module.exports = AuthenticationPacket;
87
function AuthenticationPacket(properties) {
9-
this.number = null;
10-
this.scrambleBuffer = null;
11-
this.password = null;
12-
this.user = null;
13-
this.database = null;
14-
this.flags = null;
15-
this.maxPacketSize = null;
16-
this.charsetNumber = null;
8+
this.number = null;
9+
this.token = null;
10+
this.user = null;
11+
this.database = null;
12+
this.flags = null;
13+
this.maxPacketSize = null;
14+
this.charsetNumber = null;
1715

1816
_.extend(this, properties);
1917
}
2018

2119
AuthenticationPacket.prototype.toBuffer = function() {
22-
var token = Auth.token(this.password, this.scrambleBuffer);
2320
var packetSize = (
2421
4 + 4 + 1 + 23 +
2522
this.user.length + 1 +
26-
token.length + 1 +
23+
this.token.length + 1 +
2724
this.database.length + 1
2825
);
2926
var packet = new OutgoingPacket(packetSize, this.number);
@@ -33,7 +30,7 @@ AuthenticationPacket.prototype.toBuffer = function() {
3330
packet.writeNumber(1, this.charsetNumber);
3431
packet.writeFiller(23);
3532
packet.writeNullTerminated(this.user);
36-
packet.writeLengthCoded(token);
33+
packet.writeLengthCoded(this.token);
3734
packet.writeNullTerminated(this.database);
3835

3936
return packet.buffer;

0 commit comments

Comments
 (0)