如何在 php 中对 SOAP 消息进行签名


How to sign SOAP message in php

我正在使用phpyii2),我想实现与服务器的SOAP通信。我有以下 SOAP 指南:

客户的

系统使用客户的私钥进行签发 数字签名。两个应用程序请求(应用程序请求) 并且 SOAP 消息必须在 WSC 中单独签名。这 签名是使用私钥执行的。签名系统必须 在签名中还包括证书。此证书 包含与 签署。接收方使用公钥对 签名。

和:

下一步:数字签名(分离类型 XML 数字签名) 带有发件人证书私钥的整个 SOAP 消息并放置 将签名放入 SOAP 标头中

所以,我有自己的private.keypublic.keycertificate.cer

我的代码看起来像

    $client = new SoapClient($wdsl, ['trace' => true]);
    $arguments = ['DownloadFileListRequest' => $dflr];
    $appResponse = $client->__call('downloadFileList', $arguments);

但是我得到预期的错误:

SOAP signature error

我必须做什么以及如何签署此 SOAP?

XMLSecurityDSig帮助 (https://github.com/robrichards/xmlseclibs)

$dom = new DOMDocument('1.0', 'UTF-8');
$ar = $dom->createElementNS('http://bxd.fi/xmldata/', 'ApplicationRequest');
$dom->appendChild($ar);
$ar->appendChild($dom->createElement('CustomerId', $this->userID));
...
$ar->appendChild($dom->createElement('Content', $contentBase64));
$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$objDSig->addReference(
            $dom,
            XMLSecurityDSig::SHA256,
            ['http://www.w3.org/2000/09/xmldsig#enveloped-signature'],
            ['force_uri' => true]
        );
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type'=>'private']);
$objKey->loadKey($this->privateKeyPath, true);
$objDSig->sign($objKey);
$objDSig->add509Cert(base64_encode(file_get_contents($this->certificatePath)), false);
$objDSig->appendSignature($dom->documentElement);
$xmlRaw = $dom->saveXML();