我需要签署传出的 soap 请求

I need to sign outgoing soap requests

我正在尝试发送已签名的肥皂请求,但似乎遗漏了一些东西。

我尝试了 wso2 库,但它在 ubuntu 14.04 和 php7.0

上不起作用

然后我尝试了这个:https://github.com/LinioIT/wse-php但不断得到 ERR_025: Verification failure: No signature in the WS-Security message for the configured soap actor/role ""! in SoapClient->__call()

我在 soapUI 中对此进行了测试并使其正常工作,但无法将其转换为 PHP

这是我的代码:

<?php
$wsdl = "/***/GeefOnderneming.wsdl";
$cafile = "/var/www/src/cert/CA_cat_inv.pem";
$location = "https://***.be/GeefOndernemingDienst-02.00";
$uri = "http://***.be";
$local_cert = "/var/www/src/cert/cert_priv_pub.pem";
$soap = new SoapWsController($wsdl, [
  'local_cert' => $local_cert,
  'cafile' => $cafile,
  'location' => $location,
  'uri' => $uri,
  'connection_timeout' => 10,
]);
$theResponse = $soap->geefOnderneming(
  $payload
);

SoapWsController 是从默认的 SoapClient 扩展而来的: 我不确定定义是否正确,我尝试了很多选择

namespace Drupal\vlaio_dossiers\Controller;

use DOMDocument;
use SoapClient;
use XMLSecurity\WSSESoap;
use XMLSecurity\XMLSecurityKey;

define('PRIVATE_KEY', '/***/key_ecc_private.pem');
define('SERVICE_CERT', '/***/cert_priv_pub.pem'); 
define('CERT_FILE', '/***/certificate.pem');

class SoapWsController extends SoapClient {
  public function __doRequest($request, $location, $saction, $version,$one_way = NULL)
  {
  $doc = new DOMDocument('1.0');
  $doc->loadXML($request);

  $objWSSE = new WSSESoap($doc);

  /* add Timestamp with no expiration timestamp */
  $objWSSE->addTimestamp();

  /* create new XMLSec Key using AES256_CBC and type is private key */
  $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'private'));

  /* load the private key from file - last arg is bool if key in file (true) or is string (false) */
  $objKey->loadKey(PRIVATE_KEY, true);

  /* Sign the message - also signs appropiate WS-Security items */
  $options = array("insertBefore" => false);
  $objWSSE->signSoapDoc($objKey, $options);

  /* Add certificate (BinarySecurityToken) to the message */
  $token = $objWSSE->addBinaryToken(file_get_contents(CERT_FILE));

  /* Attach pointer to Signature */
  $objWSSE->attachTokentoSig($token);

  $objKey = new XMLSecurityKey(XMLSecurityKey::AES256_CBC);
  $objKey->generateSessionKey();

  $siteKey = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP_MGF1P, array('type' => 'public'));
  $siteKey->loadKey(SERVICE_CERT, true, true);

  $options = array("KeyInfo" => array("X509SubjectKeyIdentifier" => true));
  $objWSSE->encryptSoapDoc($siteKey, $objKey, $options);

  $retVal = parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version);

  $doc = new DOMDocument();
  $doc->loadXML($retVal);

  $options = array("keys" => array("private" => array("key" => PRIVATE_KEY, "isFile" => true, "isCert" => false)));
  $objWSSE->decryptSoapDoc($doc, $options);

  return $doc->saveXML();
  }
}

我遇到了和你类似的问题。 我终于用https://github.com/robrichards/xmlseclibs解决了。 请确保您使用的是最新版本的 xmlseclibs。