Skip to content
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

request to turn on plugin_auth #2425

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ The following flags are available:
- `ODBC` Special handling of ODBC behaviour. This flag has no effect on this Node.js
implementation. (Default on)
- `PLUGIN_AUTH` - Uses the plugin authentication mechanism when connecting to the
MySQL server. This feature is not currently supported by the Node.js implementation
so cannot be turned on. (Default off)
MySQL server. Support auth plugin method "mysql_native_password" (Default on)
- `PROTOCOL_41` - Uses the 4.1 protocol. (Default on)
- `PS_MULTI_RESULTS` - Can handle multiple resultsets for execute. (Default on)
- `REMEMBER_OPTIONS` - This is specific to the C client, and has no effect on this
Expand Down
2 changes: 1 addition & 1 deletion lib/ConnectionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ConnectionConfig.getDefaultFlags = function getDefaultFlags(options) {
'+LONG_PASSWORD', // Use the improved version of Old Password Authentication
'+MULTI_RESULTS', // Can handle multiple resultsets for COM_QUERY
'+ODBC', // Special handling of ODBC behaviour
'-PLUGIN_AUTH', // Does *NOT* support auth plugins
'+PLUGIN_AUTH', // Support auth plugin "mysql_native_password"
'+PROTOCOL_41', // Uses the 4.1 protocol
'+PS_MULTI_RESULTS', // Can handle multiple resultsets for COM_STMT_EXECUTE
'+RESERVED', // Unused
Expand Down
15 changes: 15 additions & 0 deletions lib/protocol/packets/ClientAuthenticationPacket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Buffer = require('safe-buffer').Buffer;
var ConnectionConfig = require('../../ConnectionConfig');
var Client = require('../constants/client');

module.exports = ClientAuthenticationPacket;
function ClientAuthenticationPacket(options) {
Expand All @@ -12,6 +14,13 @@ function ClientAuthenticationPacket(options) {
this.scrambleBuff = options.scrambleBuff;
this.database = options.database;
this.protocol41 = options.protocol41;

var defaultFlags = ConnectionConfig.getDefaultFlags();
var mergedFlags = ConnectionConfig.mergeFlags(defaultFlags, this.clientFlags);
if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) {
this.clientAuthPlugin = true;
this.authPluginName = "mysql_native_pasword";
}
}

ClientAuthenticationPacket.prototype.parse = function(parser) {
Expand All @@ -23,6 +32,9 @@ ClientAuthenticationPacket.prototype.parse = function(parser) {
this.user = parser.parseNullTerminatedString();
this.scrambleBuff = parser.parseLengthCodedBuffer();
this.database = parser.parseNullTerminatedString();
if(this.clientAuthPlugin) {
this.authPluginName = parser.parseNullTerminatedString();
}
} else {
this.clientFlags = parser.parseUnsignedNumber(2);
this.maxPacketSize = parser.parseUnsignedNumber(3);
Expand All @@ -41,6 +53,9 @@ ClientAuthenticationPacket.prototype.write = function(writer) {
writer.writeNullTerminatedString(this.user);
writer.writeLengthCodedBuffer(this.scrambleBuff);
writer.writeNullTerminatedString(this.database);
if(this.clientAuthPlugin) {
writer.writeNullTerminatedString(this.authPluginName);
}
} else {
writer.writeUnsignedNumber(2, this.clientFlags);
writer.writeUnsignedNumber(3, this.maxPacketSize);
Expand Down
14 changes: 14 additions & 0 deletions lib/protocol/packets/ComChangeUserPacket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = ComChangeUserPacket;

var ConnectionConfig = require('../../ConnectionConfig');
var Client = require('../constants/client');

function ComChangeUserPacket(options) {
options = options || {};

Expand All @@ -15,6 +19,11 @@ ComChangeUserPacket.prototype.parse = function(parser) {
this.scrambleBuff = parser.parseLengthCodedBuffer();
this.database = parser.parseNullTerminatedString();
this.charsetNumber = parser.parseUnsignedNumber(1);
var defaultFlags = ConnectionConfig.getDefaultFlags();
var mergedFlags = ConnectionConfig.mergeFlags(defaultFlags);
if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) {
this.authPluginName = parser.parseNullTerminatedString();
}
};

ComChangeUserPacket.prototype.write = function(writer) {
Expand All @@ -23,4 +32,9 @@ ComChangeUserPacket.prototype.write = function(writer) {
writer.writeLengthCodedBuffer(this.scrambleBuff);
writer.writeNullTerminatedString(this.database);
writer.writeUnsignedNumber(2, this.charsetNumber);
var defaultFlags = ConnectionConfig.getDefaultFlags();
var mergedFlags = ConnectionConfig.mergeFlags(defaultFlags);
if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) {
writer.writeNullTerminatedString("mysql_native_password");
}
};