/**
  * Tries to resolve a key from the given \DOMElement.
  *
  * @param \DOMElement $node      Node where to resolve the key
  * @param string      $algorithm XML security key algorithm
  *
  * @return \ass\XmlSecurity\Key|null
  */
 public function keyInfoSecurityTokenReferenceResolver(\DOMElement $node, $algorithm)
 {
     foreach ($node->childNodes as $key) {
         if (Helper::NS_WSS === $key->namespaceURI) {
             switch ($key->localName) {
                 case 'KeyIdentifier':
                     return $this->serviceSecurityKey->getPublicKey();
                 case 'Reference':
                     $uri = $key->getAttribute('URI');
                     $referencedNode = $this->getReferenceNodeForUri($node, $uri);
                     if (XmlSecurityEnc::NS_XMLENC === $referencedNode->namespaceURI && 'EncryptedKey' == $referencedNode->localName) {
                         $key = XmlSecurityEnc::decryptEncryptedKey($referencedNode, $this->userSecurityKey->getPrivateKey());
                         return XmlSecurityKey::factory($algorithm, $key, false, XmlSecurityKey::TYPE_PRIVATE);
                     } elseif (Helper::NS_WSS === $referencedNode->namespaceURI && 'BinarySecurityToken' == $referencedNode->localName) {
                         $key = XmlSecurityPem::formatKeyInPemFormat($referencedNode->textContent);
                         return XmlSecurityKey::factory(XmlSecurityKey::RSA_SHA1, $key, false, XmlSecurityKey::TYPE_PUBLIC);
                     }
             }
         }
     }
     return null;
 }
Пример #2
0
 public function testFormatKeyInPemFormat()
 {
     $cert = Pem::formatKeyInPemFormat($this->keyString, PEM::PEM_TYPE_CERTIFICATE_X509);
     $this->assertEquals($cert, $this->cert);
 }