/** * @param \DOMNode $node * @param DeserializationContext $context */ public function deserialize(\DOMNode $node, DeserializationContext $context) { $list = $context->getXpath()->query('xenc:EncryptedData', $node); if (0 == $list->length) { throw new LightSamlXmlException('Missing encrypted data in <saml:EncryptedAssertion>'); } if (1 != $list->length) { throw new LightSamlXmlException('More than one encrypted data element in <saml:EncryptedAssertion>'); } /** @var \DOMElement $encryptedData */ $encryptedData = $list->item(0); $this->xmlEnc = new XMLSecEnc(); $this->xmlEnc->setNode($encryptedData); $this->xmlEnc->type = $encryptedData->getAttribute('Type'); $this->symmetricKey = $this->loadSymmetricKey(); $this->symmetricKeyInfo = $this->loadSymmetricKeyInfo($this->symmetricKey); }
/** * @param \DOMElement $node * @param DeserializationContext $context * * @throws \LightSaml\Error\LightSamlSecurityException */ public function deserialize(\DOMElement $node, DeserializationContext $context) { $this->checkXmlNodeName($node, 'Signature', SamlConstants::NS_XMLDSIG); $this->signature = new XMLSecurityDSig(); $this->signature->idKeys[] = $this->getIDName(); $this->signature->sigNode = $node; $this->signature->canonicalizeSignedInfo(); $this->key = null; $key = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'public')); XMLSecEnc::staticLocateKeyInfo($key, $node); if ($key->name || $key->key) { $this->key = $key; } $this->certificates = array(); $list = $context->getXpath()->query('./ds:KeyInfo/ds:X509Data/ds:X509Certificate', $node); foreach ($list as $certNode) { $certData = trim($certNode->textContent); $certData = str_replace(array("\r", "\n", "\t", ' '), '', $certData); $this->certificates[] = $certData; } }
/** * @param \DOMElement $node * @param DeserializationContext $context * * @throws LightSamlXmlException * * @return void */ public function deserialize(\DOMElement $node, DeserializationContext $context) { $this->checkXmlNodeName($node, 'KeyDescriptor', SamlConstants::NS_METADATA); $this->attributesFromXml($node, array('use')); $list = $context->getXpath()->query('./ds:KeyInfo/ds:X509Data/ds:X509Certificate', $node); if (1 != $list->length) { throw new LightSamlXmlException('Missing X509Certificate node'); } /** @var $x509CertificateNode \DOMElement */ $x509CertificateNode = $list->item(0); $certificateData = trim($x509CertificateNode->textContent); if (false == $certificateData) { throw new LightSamlXmlException('Missing certificate data'); } $this->certificate = new X509Certificate(); $this->certificate->setData($certificateData); }
/** * @param \DOMElement $node * @param DeserializationContext $context * @param string $elementName * @param string $class * @param string $namespacePrefix * * @throws \LogicException */ protected function oneElementFromXml(\DOMElement $node, DeserializationContext $context, $elementName, $class, $namespacePrefix) { if ($namespacePrefix) { $query = sprintf('./%s:%s', $namespacePrefix, $elementName); } else { $query = sprintf('./%s', $elementName); } $arr = $context->getXpath()->query($query, $node); $value = $arr->length > 0 ? $arr->item(0) : null; if ($value) { $setter = 'set' . $elementName; if (false == method_exists($this, $setter)) { throw new \LogicException(sprintf("Unable to find setter for element '%s' in class '%s'", $elementName, get_class($this))); } if ($class) { /** @var AbstractSamlModel $object */ $object = new $class(); if (false == $object instanceof \LightSaml\Model\SamlElementInterface) { throw new \LogicException(sprintf("Specified class '%s' for element '%s' must implement SamlElementInterface", $class, $elementName)); } $object->deserialize($value, $context); } else { $object = $value->textContent; } $this->{$setter}($object); } }