Skip to content

Commit 8b2baf6

Browse files
committed
Fix no password support for old password protocol
1 parent cadecf6 commit 8b2baf6

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ you spot any mistakes.
88

99
* Fix `connection.threadId` missing on handshake failure
1010
* Fix duplicte packet name in debug output
11+
* Fix no password support for old password protocol
1112
* Remove special case for handshake in determine packet code
1213
* Small performance improvement starting command sequence
1314

lib/protocol/Auth.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Auth.myRnd = function(r){
8686
};
8787

8888
Auth.scramble323 = function(message, password) {
89+
if (!password) {
90+
return Buffer.alloc(0);
91+
}
92+
8993
var to = Buffer.allocUnsafe(8);
9094
var hashPass = this.hashPassword(password);
9195
var hashMessage = this.hashPassword(message.slice(0, 8));

lib/protocol/packets/OldPasswordPacket.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ function OldPasswordPacket(options) {
66
}
77

88
OldPasswordPacket.prototype.parse = function(parser) {
9-
this.scrambleBuff = parser.parseNullTerminatedBuffer();
9+
this.scrambleBuff = parser.parsePacketTerminatedBuffer();
1010
};
1111

1212
OldPasswordPacket.prototype.write = function(writer) {
1313
writer.writeBuffer(this.scrambleBuff);
14-
writer.writeFiller(1);
1514
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var connection = common.createConnection({
4+
port : common.fakeServerPort,
5+
user : 'root',
6+
password : null,
7+
insecureAuth : true
8+
});
9+
10+
var server = common.createFakeServer();
11+
12+
server.listen(common.fakeServerPort, function (err) {
13+
assert.ifError(err);
14+
15+
connection.connect(function (err) {
16+
assert.ifError(err);
17+
connection.destroy();
18+
server.destroy();
19+
});
20+
});
21+
22+
server.on('connection', function(incomingConnection) {
23+
incomingConnection.on('clientAuthentication', function () {
24+
this._sendPacket(new common.Packets.UseOldPasswordPacket());
25+
});
26+
27+
incomingConnection.on('OldPasswordPacket', function (packet) {
28+
if (packet.scrambleBuff.length === 0) {
29+
this.ok();
30+
} else {
31+
this.deny();
32+
}
33+
});
34+
35+
incomingConnection.handshake();
36+
});

0 commit comments

Comments
 (0)