You are here

public function XMLSecurityDSig::sign in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8

Parameters

XMLSecurityKey $objKey:

null|DOMNode $appendToNode:

File

src/XMLSecurityKey.php, line 1496

Class

XMLSecurityDSig

Namespace

Drupal\miniorange_saml

Code

public function sign($objKey, $appendToNode = null) {

  // If we have a parent node append it now so C14N properly works
  if ($appendToNode != null) {
    $this
      ->resetXPathObj();
    $this
      ->appendSignature($appendToNode);
    $this->sigNode = $appendToNode->lastChild;
  }
  if ($xpath = $this
    ->getXPathObj()) {
    $query = "./secdsig:SignedInfo";
    $nodeset = $xpath
      ->query($query, $this->sigNode);
    if ($sInfo = $nodeset
      ->item(0)) {
      $query = "./secdsig:SignatureMethod";
      $nodeset = $xpath
        ->query($query, $sInfo);
      $sMethod = $nodeset
        ->item(0);
      $sMethod
        ->setAttribute('Algorithm', $objKey->type);
      $data = $this
        ->canonicalizeData($sInfo, $this->canonicalMethod);
      $sigValue = base64_encode($this
        ->signData($objKey, $data));
      $sigValueNode = $this
        ->createNewSignNode('SignatureValue', $sigValue);
      if ($infoSibling = $sInfo->nextSibling) {
        $infoSibling->parentNode
          ->insertBefore($sigValueNode, $infoSibling);
      }
      else {
        $this->sigNode
          ->appendChild($sigValueNode);
      }
    }
  }
}