我试图使用安全地连接到端点.p12
文件,但我不断收到以下错误。
_tls_common.js:136
c.context.loadPKCS12(pfx);
^
Error: not enough data
at Error (native)
at Object.createSecureContext (_tls_common.js:136:17)
at Object.TLSSocket._init.ssl.onclienthello.ssl.oncertcb.exports.connect (_tls_wrap.js:1003:48)
at Agent.createConnection (https.js:80:22)
at Agent.createSocket (_http_agent.js:179:26)
at Agent.addRequest (_http_agent.js:141:10)
at new ClientRequest (_http_client.js:147:16)
at Object.exports.request (http.js:31:10)
at Object.exports.request (https.js:197:15)
at Request.start (D:\path_to_project\node_modules\request\request.js:747:30)
生成错误的代码是这样的:
request({
method: 'POST',
url: config.secureEndpoint.hostname + config.secureEndpoint.path,
body: XMLAPIResponse.body,
rejectUnauthorized: false,
strictSSL: false,
agentOptions: {
//pfx: pfx,
pfx: 'string_path_to_the_p12_key_file.p12',
passphrase: 'redacted_password'
}
}, function (error, response, body) {
console.log(response);
if (response.satusCode == 200) {
model.updateStatus(ID, 'done');
} else {
model.updateStatus(ID, 'error');
}
});
我尝试过使用 https.request 方法,但会产生相同的结果。我在网上搜索了解决方案,但我却空手而归。
据我所知,这是 PFX \ P12 密钥的问题,考虑到我从第三方收到密钥,这可能不是那么牵强。我唯一能想到的就是使用 openSSL 转换密钥格式并看看是否有效。任何建议或帮助将不胜感激。