public function addReference($name, $node, $type) { if (!$node instanceof DOMNode) { throw new Exception('$node is not of type DOMNode'); } $curencdoc = $this->encdoc; $this->_resetTemplate(); $encdoc = $this->encdoc; $this->encdoc = $curencdoc; $refuri = DBSeller_Helper_Xml_Security_XMLSecurityDSig::generate_GUID(); $element = $encdoc->documentElement; $element->setAttribute("Id", $refuri); $this->references[$name] = array("node" => $node, "type" => $type, "encnode" => $encdoc, "refuri" => $refuri); }
private function addRefInternal($sinfoNode, $node, $algorithm, $arTransforms = NULL, $options = NULL) { $prefix = NULL; $prefix_ns = NULL; $id_name = 'Id'; $overwrite_id = TRUE; $force_uri = FALSE; if (is_array($options)) { $prefix = empty($options['prefix']) ? NULL : $options['prefix']; $prefix_ns = empty($options['prefix_ns']) ? NULL : $options['prefix_ns']; $id_name = empty($options['id_name']) ? 'Id' : $options['id_name']; $overwrite_id = !isset($options['overwrite']) ? TRUE : (bool) $options['overwrite']; $force_uri = !isset($options['force_uri']) ? FALSE : (bool) $options['force_uri']; } $attname = $id_name; if (!empty($prefix)) { $attname = $prefix . ':' . $attname; } $refNode = $this->createNewSignNode('Reference'); $sinfoNode->appendChild($refNode); if (!$node instanceof DOMDocument) { $uri = NULL; if (!$overwrite_id) { $uri = $node->getAttributeNS($prefix_ns, $id_name); } if (empty($uri)) { $uri = DBSeller_Helper_Xml_Security_XMLSecurityDSig::generate_GUID(); $node->setAttributeNS($prefix_ns, $attname, $uri); } $refNode->setAttribute("URI", '#' . $uri); } elseif ($force_uri) { $refNode->setAttribute("URI", ''); } $transNodes = $this->createNewSignNode('Transforms'); $refNode->appendChild($transNodes); if (is_array($arTransforms)) { foreach ($arTransforms as $transform) { $transNode = $this->createNewSignNode('Transform'); $transNodes->appendChild($transNode); if (is_array($transform) && !empty($transform['http://www.w3.org/TR/1999/REC-xpath-19991116']) && !empty($transform['http://www.w3.org/TR/1999/REC-xpath-19991116']['query'])) { $transNode->setAttribute('Algorithm', 'http://www.w3.org/TR/1999/REC-xpath-19991116'); $XPathNode = $this->createNewSignNode('XPath', $transform['http://www.w3.org/TR/1999/REC-xpath-19991116']['query']); $transNode->appendChild($XPathNode); if (!empty($transform['http://www.w3.org/TR/1999/REC-xpath-19991116']['namespaces'])) { foreach ($transform['http://www.w3.org/TR/1999/REC-xpath-19991116']['namespaces'] as $prefix => $namespace) { $XPathNode->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:{$prefix}", $namespace); } } } else { $transNode->setAttribute('Algorithm', $transform); } } } elseif (!empty($this->canonicalMethod)) { $transNode = $this->createNewSignNode('Transform'); $transNodes->appendChild($transNode); $transNode->setAttribute('Algorithm', $this->canonicalMethod); } $canonicalData = $this->processTransforms($refNode, $node); $digValue = $this->calculateDigest($algorithm, $canonicalData); $digestMethod = $this->createNewSignNode('DigestMethod'); $refNode->appendChild($digestMethod); $digestMethod->setAttribute('Algorithm', $algorithm); $digestValue = $this->createNewSignNode('DigestValue', $digValue); $refNode->appendChild($digestValue); }