Skip to content

Add mysql clear password auth #1552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/auth_plugins/mysql_clear_password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

module.exports = pluginOptions => ({ connection, command }) => {
const password =
command.password || pluginOptions.password || connection.config.password;

const cleartextPassword = function(password) {
return Buffer.from(`${password}\0`)
};

return cleartextPassword(password)
};
4 changes: 3 additions & 1 deletion lib/commands/auth_switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const Packets = require('../packets/index.js');
const sha256_password = require('../auth_plugins/sha256_password');
const caching_sha2_password = require('../auth_plugins/caching_sha2_password.js');
const mysql_native_password = require('../auth_plugins/mysql_native_password.js');
const mysql_clear_password = require('../auth_plugins/mysql_clear_password.js');

const standardAuthPlugins = {
sha256_password: sha256_password({}),
caching_sha2_password: caching_sha2_password({}),
mysql_native_password: mysql_native_password({})
mysql_native_password: mysql_native_password({}),
mysql_clear_password: mysql_clear_password({})
};

function warnLegacyAuthSwitch() {
Expand Down
88 changes: 60 additions & 28 deletions lib/constants/types.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,64 @@
'use strict';

module.exports = {
0x00: 'DECIMAL', // aka DECIMAL
0x01: 'TINY', // aka TINYINT, 1 byte
0x02: 'SHORT', // aka SMALLINT, 2 bytes
0x03: 'LONG', // aka INT, 4 bytes
0x04: 'FLOAT', // aka FLOAT, 4-8 bytes
0x05: 'DOUBLE', // aka DOUBLE, 8 bytes
0x06: 'NULL', // NULL (used for prepared statements, I think)
0x07: 'TIMESTAMP', // aka TIMESTAMP
0x08: 'LONGLONG', // aka BIGINT, 8 bytes
0x09: 'INT24', // aka MEDIUMINT, 3 bytes
0x0a: 'DATE', // aka DATE
0x0b: 'TIME', // aka TIME
0x0c: 'DATETIME', // aka DATETIME
0x0d: 'YEAR', // aka YEAR, 1 byte (don't ask)
0x0e: 'NEWDATE', // aka ?
0x0f: 'VARCHAR', // aka VARCHAR (?)
0x10: 'BIT', // aka BIT, 1-8 byte
0xf5: 'JSON',
0xf6: 'NEWDECIMAL', // aka DECIMAL
0xf7: 'ENUM', // aka ENUM
0xf8: 'SET', // aka SET
0xf9: 'TINY_BLOB', // aka TINYBLOB, TINYTEXT
0xfa: 'MEDIUM_BLOB', // aka MEDIUMBLOB, MEDIUMTEXT
0xfb: 'LONG_BLOB', // aka LONGBLOG, LONGTEXT
0xfc: 'BLOB', // aka BLOB, TEXT
0xfd: 'VAR_STRING', // aka VARCHAR, VARBINARY
0xfe: 'STRING', // aka CHAR, BINARY
0xff: 'GEOMETRY' // aka GEOMETRY
};


// Manually extracted from mysql-5.5.23/include/mysql_com.h
// some more info here: http://dev.mysql.com/doc/refman/5.5/en/c-api-prepared-statement-type-codes.html
exports.DECIMAL = 0x00; // aka DECIMAL (http://dev.mysql.com/doc/refman/5.0/en/precision-math-decimal-changes.html)
exports.TINY = 0x01; // aka TINYINT, 1 byte
exports.SHORT = 0x02; // aka SMALLINT, 2 bytes
exports.LONG = 0x03; // aka INT, 4 bytes
exports.FLOAT = 0x04; // aka FLOAT, 4-8 bytes
exports.DOUBLE = 0x05; // aka DOUBLE, 8 bytes
exports.NULL = 0x06; // NULL (used for prepared statements, I think)
exports.TIMESTAMP = 0x07; // aka TIMESTAMP
exports.LONGLONG = 0x08; // aka BIGINT, 8 bytes
exports.INT24 = 0x09; // aka MEDIUMINT, 3 bytes
exports.DATE = 0x0a; // aka DATE
exports.TIME = 0x0b; // aka TIME
exports.DATETIME = 0x0c; // aka DATETIME
exports.YEAR = 0x0d; // aka YEAR, 1 byte (don't ask)
exports.NEWDATE = 0x0e; // aka ?
exports.VARCHAR = 0x0f; // aka VARCHAR (?)
exports.BIT = 0x10; // aka BIT, 1-8 byte
exports.JSON = 0xf5;
exports.NEWDECIMAL = 0xf6; // aka DECIMAL
exports.ENUM = 0xf7; // aka ENUM
exports.SET = 0xf8; // aka SET
exports.TINY_BLOB = 0xf9; // aka TINYBLOB, TINYTEXT
exports.MEDIUM_BLOB = 0xfa; // aka MEDIUMBLOB, MEDIUMTEXT
exports.LONG_BLOB = 0xfb; // aka LONGBLOG, LONGTEXT
exports.BLOB = 0xfc; // aka BLOB, TEXT
exports.VAR_STRING = 0xfd; // aka VARCHAR, VARBINARY
exports.STRING = 0xfe; // aka CHAR, BINARY
exports.GEOMETRY = 0xff; // aka GEOMETRY
module.exports.DECIMAL = 0x00; // aka DECIMAL (http://dev.mysql.com/doc/refman/5.0/en/precision-math-decimal-changes.html)
module.exports.TINY = 0x01; // aka TINYINT, 1 byte
module.exports.SHORT = 0x02; // aka SMALLINT, 2 bytes
module.exports.LONG = 0x03; // aka INT, 4 bytes
module.exports.FLOAT = 0x04; // aka FLOAT, 4-8 bytes
module.exports.DOUBLE = 0x05; // aka DOUBLE, 8 bytes
module.exports.NULL = 0x06; // NULL (used for prepared statements, I think)
module.exports.TIMESTAMP = 0x07; // aka TIMESTAMP
module.exports.LONGLONG = 0x08; // aka BIGINT, 8 bytes
module.exports.INT24 = 0x09; // aka MEDIUMINT, 3 bytes
module.exports.DATE = 0x0a; // aka DATE
module.exports.TIME = 0x0b; // aka TIME
module.exports.DATETIME = 0x0c; // aka DATETIME
module.exports.YEAR = 0x0d; // aka YEAR, 1 byte (don't ask)
module.exports.NEWDATE = 0x0e; // aka ?
module.exports.VARCHAR = 0x0f; // aka VARCHAR (?)
module.exports.BIT = 0x10; // aka BIT, 1-8 byte
module.exports.JSON = 0xf5;
module.exports.NEWDECIMAL = 0xf6; // aka DECIMAL
module.exports.ENUM = 0xf7; // aka ENUM
module.exports.SET = 0xf8; // aka SET
module.exports.TINY_BLOB = 0xf9; // aka TINYBLOB, TINYTEXT
module.exports.MEDIUM_BLOB = 0xfa; // aka MEDIUMBLOB, MEDIUMTEXT
module.exports.LONG_BLOB = 0xfb; // aka LONGBLOG, LONGTEXT
module.exports.BLOB = 0xfc; // aka BLOB, TEXT
module.exports.VAR_STRING = 0xfd; // aka VARCHAR, VARBINARY
module.exports.STRING = 0xfe; // aka CHAR, BINARY
module.exports.GEOMETRY = 0xff; // aka GEOMETRY
2 changes: 2 additions & 0 deletions lib/packets/column_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ColumnDefinition {
);
this.columnLength = packet.readInt32();
this.columnType = packet.readInt8();
this.type = this.columnType;
this.flags = packet.readInt16();
this.decimals = packet.readInt8();
}
Expand All @@ -67,6 +68,7 @@ class ColumnDefinition {
characterSet: this.characterSet,
columnLength: this.columnLength,
columnType: this.columnType,
type: this.columnType,
flags: this.flags,
decimals: this.decimals
};
Expand Down
10 changes: 6 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/integration/connection/test-binary-multiple-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const fields1 = [
catalog: 'def',
characterSet: 63,
columnType: 8,
type: 8,
decimals: 0,
flags: 129,
name: '1',
Expand All @@ -53,6 +54,7 @@ const nr_fields = [
catalog: 'def',
characterSet: 63,
columnType: 3,
type: 3,
decimals: 0,
flags: 0,
name: 'test',
Expand Down
1 change: 1 addition & 0 deletions test/integration/connection/test-disconnects.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const server = common.createServer(
characterSet: 63,
columnLength: 1,
columnType: 8,
type: 8,
flags: 129,
decimals: 0
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/connection/test-execute-bind-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const assert = require('assert');
const date = new Date(2018, 2, 10, 15, 12, 34, 1234);

let rows;
connection.execute('SELECT ? AS result', [date], (err, _rows) => {
connection.execute('SELECT CAST(? AS DATETIME(6)) AS result', [date], (err, _rows) => {
if (err) {
throw err;
}
Expand Down
12 changes: 12 additions & 0 deletions test/integration/connection/test-execute-nocolumndef.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const expectedFields = [
orgTable: '',
characterSet: 63,
columnType: 8,
type: 8,
flags: 161,
decimals: 0
},
Expand All @@ -65,6 +66,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 1,
decimals: 31
},
Expand All @@ -77,6 +79,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 0,
decimals: 31
},
Expand All @@ -89,6 +92,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 250,
type: 250,
flags: 0,
decimals: 31
},
Expand All @@ -101,6 +105,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 0,
decimals: 31
},
Expand All @@ -113,6 +118,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 0,
decimals: 31
},
Expand All @@ -125,6 +131,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 0,
decimals: 31
},
Expand All @@ -137,6 +144,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 0,
decimals: 31
},
Expand All @@ -149,6 +157,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 0,
decimals: 31
},
Expand All @@ -161,6 +170,7 @@ const expectedFields = [
orgTable: '',
characterSet: 63,
columnType: 8,
type: 8,
flags: 160,
decimals: 0
},
Expand All @@ -173,6 +183,7 @@ const expectedFields = [
orgTable: '',
characterSet: 63,
columnType: 5,
type: 5,
flags: 128,
decimals: 2
},
Expand All @@ -185,6 +196,7 @@ const expectedFields = [
orgTable: '',
characterSet: 224,
columnType: 253,
type: 253,
flags: 1,
decimals: 31
}
Expand Down
2 changes: 2 additions & 0 deletions test/integration/connection/test-multiple-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const fields1 = [
catalog: 'def',
characterSet: 63,
columnType: 8,
type: 8,
decimals: 0,
flags: 129,
name: '1',
Expand All @@ -52,6 +53,7 @@ const nr_fields = [
catalog: 'def',
characterSet: 63,
columnType: 3,
type: 3,
decimals: 0,
flags: 0,
name: 'test',
Expand Down
12 changes: 11 additions & 1 deletion test/integration/connection/test-type-casting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const common = require('../../common');
const driver = require('../../../index.js'); //needed to check driver.Types
const connection = common.createConnection();
const assert = require('assert');

Expand Down Expand Up @@ -38,17 +39,26 @@ connection.query('select 1', waitConnectErr => {
connection.query(`INSERT INTO ${table} SET${inserts.join(',\n')}`);

let row;
connection.query('SELECT * FROM type_casting', (err, rows) => {
let fieldData; // to lookup field types
connection.query(`SELECT * FROM ${table}`, (err, rows, fields) => {
if (err) {
throw err;
}

row = rows[0];
// build a fieldName: fieldType lookup table
fieldData = fields.reduce((a,v) => {
a[v['name']] = v['type'];
return a;
}, {} );
connection.end();
});

process.on('exit', () => {
tests.forEach(test => {
// check that the column type matches the type name stored in driver.Types
const columnType = fieldData[test.columnName];
assert.equal(test.columnType === driver.Types[columnType], true, test.columnName);
let expected = test.expect || test.insert;
let got = row[test.columnName];
let message;
Expand Down
Loading