带有节点肥皂模块的SOAP XML加密和签名

问题描述

我正在尝试使用ws-security向WSDL服务发出SOAP请求。 代码很简单:

var fs = require('fs');
var soap = require('soap');
var url = '<WSDL-URL>';
var args = { 
    "param1": '1',"param2": '2',"param3": '3',"param4": '4',};
const options = {
    envelopeKey: 'soapenv',forceSoapVersion: '1.1',};


var privateKey = fs.readFileSync('<PRIVATE-KEY>');
var publicKey = fs.readFileSync('<PUBLIC-KEY>');
var password = ''; // NO PASSWORD
var wsOptions = { hasTimeStamp: true };
soap.WSSecurityCert(privateKey,publicKey,password,wsOptions)

soap.createClient(url,options,function(err,client) {
    //console.log(err);
    client.setEndpoint('<SERVICE-ENDPOINT>');
    
    client.setSecurity(new soap.ClientSSLSecurity('<SSL-KEY>','<SSL-CERT>',{}));
    client.METHOD(args,result,envelope,soapHeader) {
        console.log(err);
        //console.log(client.lastRequest);
        
        //console.log('Response Envelope: \n' + envelope);
        // 'result' is the response body
        //console.log('Result invoke: \n' + JSON.stringify(result));
    });
});

但是当我尝试运行脚本时,出现此错误

Error: soap:Server: These policy alternatives can not be satisfied: 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}asymmetricBinding: Received Timestamp does not match the requirements
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}X509Token: The received token does not match the token inclusion requirement
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}InitiatorToken
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}RecipientToken
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}IncludeTimestamp: Received Timestamp does not match the requirements
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SignedParts: {http://schemas.xmlsoap.org/soap/envelope/}Body not SIGNED
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}EncryptedParts: {http://schemas.xmlsoap.org/soap/envelope/}Body not ENCRYPTED

我认为我没有正确设置标题的ws-security,而且我仍然缺少如何加密我的身体的信息。

有人可以帮我弄清楚如何解决此问题吗?

解决方法

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

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

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