/**
  * Set the assertion.
  *
  * @param SAML2_Assertion $assertion The assertion.
  * @param XMLSecurityKey  $key       The key we should use to encrypt the assertion.
  * @throws Exception
  */
 public function setAssertion(SAML2_Assertion $assertion, XMLSecurityKey $key)
 {
     $xml = $assertion->toXML();
     SAML2_Utils::getContainer()->debugMessage($xml, 'encrypt');
     $enc = new XMLSecEnc();
     $enc->setNode($xml);
     $enc->type = XMLSecEnc::Element;
     switch ($key->type) {
         case XMLSecurityKey::TRIPLEDES_CBC:
         case XMLSecurityKey::AES128_CBC:
         case XMLSecurityKey::AES192_CBC:
         case XMLSecurityKey::AES256_CBC:
             $symmetricKey = $key;
             break;
         case XMLSecurityKey::RSA_1_5:
         case XMLSecurityKey::RSA_OAEP_MGF1P:
             $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
             $symmetricKey->generateSessionKey();
             $enc->encryptKey($key, $symmetricKey);
             break;
         default:
             throw new Exception('Unknown key type for encryption: ' . $key->type);
     }
     $this->encryptedData = $enc->encryptNode($symmetricKey);
 }
Exemple #2
0
 public function testMarshalling()
 {
     // Create an assertion
     $assertion = new \SAML2_Assertion();
     $assertion->setIssuer('testIssuer');
     $assertion->setValidAudiences(array('audience1', 'audience2'));
     $assertion->setAuthnContext('someAuthnContext');
     // Marshall it to a DOMElement
     $assertionElement = $assertion->toXML();
     // Test for an Issuer
     $issuerElements = \SAML2_Utils::xpQuery($assertionElement, './saml_assertion:Issuer');
     $this->assertCount(1, $issuerElements);
     $this->assertEquals('testIssuer', $issuerElements[0]->textContent);
     // Test for an AudienceRestriction
     $audienceElements = \SAML2_Utils::xpQuery($assertionElement, './saml_assertion:Conditions/saml_assertion:AudienceRestriction/saml_assertion:Audience');
     $this->assertCount(2, $audienceElements);
     $this->assertEquals('audience1', $audienceElements[0]->textContent);
     $this->assertEquals('audience2', $audienceElements[1]->textContent);
     // Test for an Authentication Context
     $authnContextElements = \SAML2_Utils::xpQuery($assertionElement, './saml_assertion:AuthnStatement/saml_assertion:AuthnContext/saml_assertion:AuthnContextClassRef');
     $this->assertCount(1, $authnContextElements);
     $this->assertEquals('someAuthnContext', $authnContextElements[0]->textContent);
 }