从节点中的SQL Servervalidation证书

我有一个客户的SQL Server数据库我需要连接到。 该SQL Server计算机的FQDN是db.client.local ,并且已经设置了自签名证书/启用encryption。

如果我连接到这台主机(添加一个条目到我的主机文件中的远程IP)使用Navicatencryption标记为启用,它拒绝连接为不可信,由于CA不信任,这是我所期望的。

在使用node-mssqltedious node-mssql ,我能够连接和查询服务器,但是没有validation似乎发生。 我如何获得node-mssql来validation证书? 在这种情况下,我需要能够提供一个自定义的CA证书。

这是我的代码到目前为止

 var sql = require( 'mssql' ), evilDns = require( 'evil-dns' ); // Set up the mapping so that I can access via their local dns evilDns.add( 'db.client.local' , '1.2.3.4' ); // Works without erroring new sql.connect({ user: 'user', password: 'password', server: 'db.client.local', database: 'my-test-database', port: 1234, options: { encrypt: true // seems decorative, connection encrypts without this } }).then( function( connection ) { return new sql.Request( connection ) .query( `SELECT * FROM TableWithStuffIn` ) .then( function( response ) { console.log( response ); return connection.close(); } ); }, function( err ) { console.log( err ); return Promise.reject(); } ) // This also works without erroring /* new sql.connect( 'mssql://user:password@db.client.local:1234/my-test-database?Encrypt=true&TrustServerCertificate=false' ) */ 

回答问题时,此function不受支持。 单调乏味,现在在它的当前主分支中有这个function,通过不在发布的分支。

更新发布后,以下示例将启用证书validation:

 new sql.connect({ user: 'user', password: 'password', server: 'db.client.local', database: 'my-test-database', port: 1234, options: { encrypt: true, trustServerCertificate: false } }).then( ... ); 

在我们的使用情况下,由于SQL服务器的数量与内部唯一FQDN和自签名证书,我使用更类似于以下的东西,也利用evilDNS提供DNS覆盖

 require( 'evil-dns' ).add( 'db.client.local' , '11.22.33.44' ); new sql.connect({ user: 'user', password: 'password', server: 'db.client.local', database: 'my-test-database', port: 1234, options: { encrypt: true, trustServerCertificate: false, cryptoCredentialsDetails: { ca: 'PEM Encoded self-signed certificate authority certificate goes here' } } }).then( ... ); 
Interesting Posts