Revision: 1810
Author: olavmrk
Date: Thu Oct 1 04:45:18 2009
Log: saml2_Message: Separate out getDecryptionKey() from decryptAssertion().
http://code.google.com/p/simplesamlphp/source/detail?r=1810
Modified:
/trunk/modules/saml2/lib/Message.php
=======================================
--- /trunk/modules/saml2/lib/Message.php Tue Sep 29 04:11:49 2009
+++ /trunk/modules/saml2/lib/Message.php Thu Oct 1 04:45:18 2009
@@ -220,6 +220,39 @@
throw new SimpleSAML_Error_Exception('Validation of
received messages
enabled, but no signature found on message.');
}
}
+
+
+ /**
+ * Retrieve the decryption key from metadata.
+ *
+ * @param SimpleSAML_Configuration $srcMetadata The metadata of the
sender (IdP).
+ * @param SimpleSAML_Configuration $dstMetadata The metadata of the
recipient (SP).
+ * @return XMLSecurityKey The decryption key.
+ */
+ private static function getDecryptionKey(SimpleSAML_Configuration
$srcMetadata,
+ SimpleSAML_Configuration $dstMetadata) {
+
+ $sharedKey = $srcMetadata->getString('sharedkey', NULL);
+ if ($sharedKey !== NULL) {
+ $key = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
+ $key->loadKey($sharedKey);
+ } else {
+ /* Find the private key we should use to decrypt
messages to this SP. */
+ $keyArray =
SimpleSAML_Utilities::loadPrivateKey($dstMetadata->toArray(), TRUE);
+ if (!array_key_exists('PEM', $keyArray)) {
+ throw new Exception('Unable to locate key we
should use to decrypt the
message.');
+ }
+
+ /* Extract the public key from the certificate for
encryption. */
+ $key = new XMLSecurityKey(XMLSecurityKey::RSA_1_5,
array('type'=>'private'));
+ if (array_key_exists('password', $keyArray)) {
+ $key->passphrase = $keyArray['password'];
+ }
+ $key->loadKey($keyArray['PEM']);
+ }
+
+ return $key;
+ }
/**
@@ -300,24 +333,10 @@
return $assertion;
}
-
- $sharedKey = $srcMetadata->getString('sharedkey', NULL);
- if ($sharedKey !== NULL) {
- $key = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
- $key->loadKey($sharedKey);
- } else {
- /* Find the private key we should use to decrypt
messages to this SP. */
- $keyArray =
SimpleSAML_Utilities::loadPrivateKey($dstMetadata->toArray(), TRUE);
- if (!array_key_exists('PEM', $keyArray)) {
- throw new Exception('Unable to locate key we
should use to decrypt the
assertion.');
- }
-
- /* Extract the public key from the certificate for
encryption. */
- $key = new XMLSecurityKey(XMLSecurityKey::RSA_1_5,
array('type'=>'private'));
- if (array_key_exists('password', $keyArray)) {
- $key->passphrase = $keyArray['password'];
- }
- $key->loadKey($keyArray['PEM']);
+ try {
+ $key = self::getDecryptionKey($srcMetadata,
$dstMetadata);
+ } catch (Exception $e) {
+ throw new SimpleSAML_Error_Exception('Error decrypting
assertion: ' .
$e->getMessage());
}
return $assertion->getAssertion($key);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/simplesamlphp-commits?hl=en
-~----------~----~----~----~------~----~------~--~---