我想构建一个连接到需要相互身份验证的HTTPS服务器的HTTPS客户端。此外,客户端密钥是椭圆曲线密钥而不是RSA密钥。为了支持Elliptic Curve键,我使用OpenSSL 1.0.2a重新编译了Node.js.
在我的node.js程序中,我设置选项以指定密钥和证书,
var options = {
// These are necessary only if using the client certificate authentication
key: fs.readFileSync('client-key.pem'),
cert: fs.readFileSync('client-cert.pem'),
当我运行它时,我收到此错误:
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Error (native)
at Object.createSecureContext (_tls_common.js:110:19)
at Object.exports.connect (_tls_wrap.js:854:21)
at Agent.createConnection (https.js:84:14)
at Agent.createSocket (_http_agent.js:196:16)
at Agent.addRequest (_http_agent.js:168:23)
at new ClientRequest (_http_client.js:156:16)
at Object.exports.request (http.js:51:10)
at exports.request (https.js:138:15)
...
这表明Node.js无法读取EC密钥。 此错误消息类似于openssl尝试将密钥作为X509证书读取时:
openssl x509 -text -in sample.key
unable to load certificate
140735234208608:error:0906D06C:PEM routines:PEM_read_bio:no start
line:pem_lib.c:701:Expecting: TRUSTED CERTIFICATE
如何强制Node.js将此密钥加载为EC密钥?
答案 0 :(得分:0)
在正确配置openssl 1.0.2a后加载EC密钥。确保Node.js' openssl版本是正确的。