XMLSecurityDSig::locateKey PHP Method

locateKey() public method

public locateKey ( $node = null )
    public function locateKey($node = null)
    {
        if (empty($node)) {
            $node = $this->sigNode;
        }
        if (!$node instanceof DOMNode) {
            return null;
        }
        if ($doc = $node->ownerDocument) {
            $xpath = new DOMXPath($doc);
            $xpath->registerNamespace('secdsig', XMLSecurityDSig::XMLDSIGNS);
            $query = "string(./secdsig:SignedInfo/secdsig:SignatureMethod/@Algorithm)";
            $algorithm = $xpath->evaluate($query, $node);
            if ($algorithm) {
                try {
                    $objKey = new XMLSecurityKey($algorithm, array('type' => 'public'));
                } catch (Exception $e) {
                    return null;
                }
                return $objKey;
            }
        }
        return null;
    }

Usage Example

示例#1
0
 /**
  * @return bool
  * @throws Exception
  */
 public function isValid()
 {
     $singleAssertion = $this->validateNumAssertions();
     if (!$singleAssertion) {
         throw new Exception('Multiple assertions are not supported');
     }
     $validTimestamps = $this->validateTimestamps();
     if (!$validTimestamps) {
         throw new Exception('Timing issues (please check your clock settings)');
     }
     $objXMLSecDSig = new XMLSecurityDSig();
     $objDSig = $objXMLSecDSig->locateSignature($this->_document);
     if (!$objDSig) {
         throw new Exception('Cannot locate Signature Node');
     }
     $objXMLSecDSig->canonicalizeSignedInfo();
     $objXMLSecDSig->idKeys = array('ID');
     $objKey = $objXMLSecDSig->locateKey();
     if (!$objKey) {
         throw new Exception('We have no idea about the key');
     }
     try {
         $retVal = $objXMLSecDSig->validateReference();
     } catch (Exception $e) {
         throw new Exception('Reference Validation Failed');
     }
     XMLSecEnc::staticLocateKeyInfo($objKey, $objDSig);
     $objKey->loadKey($this->_settings->idpPublicCertificate, false, true);
     return $objXMLSecDSig->verify($objKey) === 1;
 }
All Usage Examples Of XMLSecurityDSig::locateKey