From 8a49376cf7a5c11f1e9b37c5abc176dec0e7bfe1 Mon Sep 17 00:00:00 2001 From: Qianqian Bu Date: Tue, 20 Oct 2020 18:43:01 +0800 Subject: [PATCH 1/4] request to turn on plugin_auth --- Readme.md | 3 +-- lib/ConnectionConfig.js | 2 +- .../packets/ClientAuthenticationPacket.js | 15 +++++++++++++++ lib/protocol/packets/ComChangeUserPacket.js | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 27886aa50..75b0d41bc 100644 --- a/Readme.md +++ b/Readme.md @@ -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 diff --git a/lib/ConnectionConfig.js b/lib/ConnectionConfig.js index 06f4399c5..6a5c7eecb 100644 --- a/lib/ConnectionConfig.js +++ b/lib/ConnectionConfig.js @@ -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 diff --git a/lib/protocol/packets/ClientAuthenticationPacket.js b/lib/protocol/packets/ClientAuthenticationPacket.js index 595db77a0..ec8831cc2 100644 --- a/lib/protocol/packets/ClientAuthenticationPacket.js +++ b/lib/protocol/packets/ClientAuthenticationPacket.js @@ -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) { @@ -12,6 +14,13 @@ function ClientAuthenticationPacket(options) { this.scrambleBuff = options.scrambleBuff; this.database = options.database; this.protocol41 = options.protocol41; + + let defaultFlags = ConnectionConfig.getDefaultFlags(); + let 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) { @@ -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); @@ -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); diff --git a/lib/protocol/packets/ComChangeUserPacket.js b/lib/protocol/packets/ComChangeUserPacket.js index 327884235..2eb56040d 100644 --- a/lib/protocol/packets/ComChangeUserPacket.js +++ b/lib/protocol/packets/ComChangeUserPacket.js @@ -1,4 +1,8 @@ module.exports = ComChangeUserPacket; + +var ConnectionConfig = require('../../ConnectionConfig'); +var Client = require('../constants/client'); + function ComChangeUserPacket(options) { options = options || {}; @@ -15,6 +19,11 @@ ComChangeUserPacket.prototype.parse = function(parser) { this.scrambleBuff = parser.parseLengthCodedBuffer(); this.database = parser.parseNullTerminatedString(); this.charsetNumber = parser.parseUnsignedNumber(1); + let defaultFlags = ConnectionConfig.getDefaultFlags(); + let mergedFlags = ConnectionConfig.mergeFlags(defaultFlags); + if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) { + this.authPluginName = parser.parseNullTerminatedString(); + } }; ComChangeUserPacket.prototype.write = function(writer) { @@ -23,4 +32,9 @@ ComChangeUserPacket.prototype.write = function(writer) { writer.writeLengthCodedBuffer(this.scrambleBuff); writer.writeNullTerminatedString(this.database); writer.writeUnsignedNumber(2, this.charsetNumber); + let defaultFlags = ConnectionConfig.getDefaultFlags(); + let mergedFlags = ConnectionConfig.mergeFlags(defaultFlags); + if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) { + writer.writeNullTerminatedString("mysql_native_password"); + } }; From 9f7108cecec6b69c341ff5c7d92904f01f5ac8b3 Mon Sep 17 00:00:00 2001 From: GuuBu <46982854+GuuBu@users.noreply.github.com> Date: Tue, 27 Oct 2020 11:35:28 +0800 Subject: [PATCH 2/4] Update ClientAuthenticationPacket.js update var --- lib/protocol/packets/ClientAuthenticationPacket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protocol/packets/ClientAuthenticationPacket.js b/lib/protocol/packets/ClientAuthenticationPacket.js index ec8831cc2..116748515 100644 --- a/lib/protocol/packets/ClientAuthenticationPacket.js +++ b/lib/protocol/packets/ClientAuthenticationPacket.js @@ -15,8 +15,8 @@ function ClientAuthenticationPacket(options) { this.database = options.database; this.protocol41 = options.protocol41; - let defaultFlags = ConnectionConfig.getDefaultFlags(); - let mergedFlags = ConnectionConfig.mergeFlags(defaultFlags, this.clientFlags); + 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"; From 08f829c2ec816137ef11d0551136a5e075f4b0dd Mon Sep 17 00:00:00 2001 From: GuuBu <46982854+GuuBu@users.noreply.github.com> Date: Tue, 27 Oct 2020 11:36:31 +0800 Subject: [PATCH 3/4] Update ComChangeUserPacket.js update var --- lib/protocol/packets/ComChangeUserPacket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protocol/packets/ComChangeUserPacket.js b/lib/protocol/packets/ComChangeUserPacket.js index 2eb56040d..8116a6ec7 100644 --- a/lib/protocol/packets/ComChangeUserPacket.js +++ b/lib/protocol/packets/ComChangeUserPacket.js @@ -19,8 +19,8 @@ ComChangeUserPacket.prototype.parse = function(parser) { this.scrambleBuff = parser.parseLengthCodedBuffer(); this.database = parser.parseNullTerminatedString(); this.charsetNumber = parser.parseUnsignedNumber(1); - let defaultFlags = ConnectionConfig.getDefaultFlags(); - let mergedFlags = ConnectionConfig.mergeFlags(defaultFlags); + var defaultFlags = ConnectionConfig.getDefaultFlags(); + var mergedFlags = ConnectionConfig.mergeFlags(defaultFlags); if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) { this.authPluginName = parser.parseNullTerminatedString(); } From e7971b007ff80c87b44c97305377594efe44ce99 Mon Sep 17 00:00:00 2001 From: Qianqian Bu Date: Wed, 11 Nov 2020 16:49:04 +0800 Subject: [PATCH 4/4] format and var --- lib/protocol/packets/ClientAuthenticationPacket.js | 4 ++-- lib/protocol/packets/ComChangeUserPacket.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protocol/packets/ClientAuthenticationPacket.js b/lib/protocol/packets/ClientAuthenticationPacket.js index 116748515..a692675ed 100644 --- a/lib/protocol/packets/ClientAuthenticationPacket.js +++ b/lib/protocol/packets/ClientAuthenticationPacket.js @@ -18,8 +18,8 @@ function ClientAuthenticationPacket(options) { 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"; + this.clientAuthPlugin = true; + this.authPluginName = "mysql_native_pasword"; } } diff --git a/lib/protocol/packets/ComChangeUserPacket.js b/lib/protocol/packets/ComChangeUserPacket.js index 8116a6ec7..a15603de2 100644 --- a/lib/protocol/packets/ComChangeUserPacket.js +++ b/lib/protocol/packets/ComChangeUserPacket.js @@ -32,8 +32,8 @@ ComChangeUserPacket.prototype.write = function(writer) { writer.writeLengthCodedBuffer(this.scrambleBuff); writer.writeNullTerminatedString(this.database); writer.writeUnsignedNumber(2, this.charsetNumber); - let defaultFlags = ConnectionConfig.getDefaultFlags(); - let mergedFlags = ConnectionConfig.mergeFlags(defaultFlags); + var defaultFlags = ConnectionConfig.getDefaultFlags(); + var mergedFlags = ConnectionConfig.mergeFlags(defaultFlags); if(mergedFlags & Client.CLIENT_PLUGIN_AUTH != 0) { writer.writeNullTerminatedString("mysql_native_password"); }