MTLS:在 nodejs soap 中发送客户端证书 - 并检查服务器证书

问题描述

我正在尝试使用 node-soap

从 nodejs 应用程序发送客户端证书
const clientURL = 'prod.wsdl';
const wsdl_options = {
           wsdl_options: {
               "cert": fs.readFileSync('/etc/ssl/certs/client.crt'),"key": fs.readFileSync('/etc/ssl/certs/client.key'),}
};
soap.createClient(clientURL,wsdl_options,function (err,client) {
  if (!err) {
    client[my-method](args,function (error,result) {
    if (error) console.log(JSON.stringify(error))
  
  }
})

但我收到一个错误{"errno":"EPROTO","code":"EPROTO","syscall":"write"}

当我发送 curl 时,服务器使用正确的证书获取我的请求:

curl -X POST https://host:4431/func --cert /etc/ssl/certs/client.crt --key /etc/ssl/certs/client.key

这里有什么问题?我在 wsdlOptions 上遗漏了什么吗?

另外,我的客户给了我肥皂服务器的证书(而不是 ca 本身),我需要对照他给我的那个来检查这个响应的 ssl 证书。

我该怎么做?

对于请求库,我们可以这样做:res.connection.getPeerCertificate() / res.connection.getPeerX509Certificate()this

更新

我找到了客户端证书和密钥的第一个问题的解决方案。

我失踪了:

client.setSecurity

创建代理后!

对于createClient,不需要放cert和key。 所以代码现在看起来像这样:

const clientURL = 'prod.wsdl';

soap.createClient(clientURL,{},client) {
  if (!err) {
    client.setSecurity(new soap.ClientSSLSecurity('/path/to/key','path/to/cert'));
    client[my-method](args,result) {
        ...
  }
})

现在如何从响应中获取服务器的证书并将其与我拥有的证书进行比较?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)