SQL Server NW.js / Node.js throws "SSL routines:ssl_choose_client_version:unsupported protocol" error when using node-mssql / tedious

gojuced7  于 11个月前  发布在  Node.js
关注(0)|答案(2)|浏览(79)

I found the answer to this problem already and just want to document my finding.

When using recent versions of NW.js (and Node.js), I was having problems with the node-mssql / tedious module. Even a task as simple as connecting to a SQL Server server would throw a SSL routines:ssl_choose_client_version:unsupported protocol error.

tnkciper

tnkciper1#

The reason why the error is thrown has to do with a change in Node.js 12. Since version 12, the TLS settings were tightened, and TLS 1.2 is required by default. The SSL routines:ssl_choose_client_version:unsupported protocol error would be thrown if the SQL Server server does not support TLS 1.2.

In Node, it is possible to change the default setting by using the command line flag --tls-min-v1.0 when starting node. Since NW does not have a way to pass a command line flag to the Node context, the solution is to set a custom cryptoCredentialsDetails option in the connection configuration that specifies minVersion: 'TLSv1' , like the following:

mssql.connect({
    user: "this.user",
    password: "this.password",
    server: "this.server",
    database: "this.database",
    options: {
        cryptoCredentialsDetails: {
            minVersion: 'TLSv1'
        }
    }
});
oyt4ldly

oyt4ldly2#

The warning you're seeing (Deprecation Warning: Setting the TLS Server Name to an IP address is not permitted by RFC 6066) is related to using an IP address instead of a hostname in the TLS handshake, and it's usually more of a warning than a critical error. However, the Connection Error you're facing is more crucial, and it indicates a problem connecting to the SQL Server with SSL/TLS.

Try adjusting the connection configuration by explicitly specifying the options and disabling SSL. For example:

const config = {
  user: 'your_username',
  password: 'your_password',
  server: 'your_sql_server',
  database: 'your_database',
  options: {
    encrypt: false, // Disable SSL/TLS
  },
};

相关问题