Connecting to MariaDB with nodejs over ssl with clear text password

好久不见. 提交于 2019-12-24 03:27:59

问题


I am trying to connect to mariadb instance over ssl,

var mysql = require('mysql');
var conn = mysql.createConnection({
    user: 'user',
    password: 'password',
    debug: true,
    port: '3306',
    host: "host",
    ssl: {
        "ca": ca
    }
});

conn.connect();

the ca is an array of cerificates. I am getting the following error.

Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MariaDB client

I am able to connect to the db using python with mysql.connector.

After setting it on debug mode, I can see the client is trying to use mysql_native_password authentication. I need to use mysql_clear_password.


回答1:


if your server supports plugin based auth and auth switch request, you can try following code:

var mysql = require('mysql2');
var conn = mysql.createConnection({
  user: 'user',
    password: 'password',
    debug: true,
    port: '3306',
    host: "host",
    ssl: {
        "ca": ca
    },
    authSwitchHandler = (data, cb) => {
      if (data.pluginName === 'mysql_clear_password') {
      // https://dev.mysql.com/doc/internals/en/clear-text-authentication.html
      var password = 'password\0';
      var buffer = Buffer.from(password);
      cb(null, buffer);
    }
  });

unfortunately initial auth type is always mysql_native with node-mysql2 ( I hope to fix this soon ), so you need both auth_plugin and auth_switch support enabled on server



来源:https://stackoverflow.com/questions/43448563/connecting-to-mariadb-with-nodejs-over-ssl-with-clear-text-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!