【发布时间】:2020-02-29 12:49:45
【问题描述】:
我想使用 java 代码进行相互 SSL 身份验证,但没有成功我有 key.pem 和 cert.pem 文件来进行身份验证我已经用 Curl 尝试过
curl -X POST -d '{ "Channel": "....}' -H "Content-Type: application/json" -H "Auth1: ***" -H "Auth2: ***" -k https://******/webservices/JSON/Default.aspx --cert "cert.pem" --key "Key.pem"
它工作正常,然后我尝试创建 java 程序引用 Send https request in java using .pem file 但服务器返回“CERT_MISSING”。我还尝试使用此https://www.naschenweng.info/2018/02/01/java-mutual-ssl-authentication-2-way-ssl-authentication/ 此代码创建 p12、crt 和 jks 文件,如上链接所述,但仍然收到相同的错误“CERT_MISSING”。 这是工作的 NodeJS 示例:
var https = require("https");
var fs = require("fs");
var jsonData = {
"Channel": ....
}
var options = {
hostname: "****",
port: 443,
path: '/webservices/JSON/Default.aspx',
method: 'POST',
timeout: this.TimeOut,
headers: {'Content-Type':'application/json',"Auth1": "****","Auth2": "*****"},
json: true,
key: fs.readFileSync('Key.pem'),
cert: fs.readFileSync('cert.pem')
}
var req = https.request(options, function(res) {
res.on('data', function(data) {
var response = JSON.parse(data)
console.log(response)
req.end();
});
});
req.on('error', function(e) {
console.log("ERROR:");
})
req.write(JSON.stringify(jsonData));
req.end();
请帮帮我。
【问题讨论】:
标签: java ssl mutual-authentication