我尝试连接到具有特定证书的https服务器。出于某种原因,它似乎在Node 6.0.0中成功,但在Node 4.4.7中失败。
码
var fs = require('fs');
var host = process.argv[2]; // host of the site
var certFile = process.argv[3]; // certificate from server
var ca = fs.readFileSync(certFile, 'ascii');
var https = require('https');
https.request({ host: host, ca: ca }, function (res) {
if (res.client.authorized) {
console.log("node test: OK")
} else {
throw new Error(res.client.authorizationError)
}
}).end()
节点6.0.0输出
node test: OK
节点4.4.7输出
events.js:141
throw er; // Unhandled 'error' event
^
Error: unable to verify the first certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1017:38)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:582:8)
at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:424:38)
系统
$ lsb_release -d
Description: Ubuntu 16.04 LTS