Algorithm mismatch w/ trunk and Shib IdP

465 views
Skip to first unread message

Peter Schober

unread,
Sep 10, 2009, 6:52:05 PM9/10/09
to simple...@googlegroups.com
Updating the working copy of one of my SSP SPs (tracking trunk) I now
get this error after POSTing the assertion:

Algorithm mismatch between input key and key used to encrypt the
symmetric key for the message. Key was:
'http://www.w3.org/2001/04/xmlenc#rsa-1_5'; message was:
'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'

Which sounds rather clear, I just have no idea what could have brought
this up?
-peter

Olav Morken

unread,
Sep 11, 2009, 3:37:07 AM9/11/09
to simple...@googlegroups.com

There have been some large changes to the way SAML 2.0 messages are
handled (i.e. a complete rewrite). As part of the changes, some sanity
checks were added. The check you are seeing was meant to handle the case
where the SP specifies a different key for decryption than the IdP uses
for encryption. (E.g. different symmetric key chiphers, one side using
public key encryption while the other side uses symmetric key, ...)

It looks like this check is too strict in this case, since it assumes
that the only public key encryption method is rsa-1_5. I think the best
solution is to add a check for the cases where we "transform" the key
into a different type without problem. I believe this should be
possible for the various RSA public key algorithms.

I will look at implementing this. In the meantime, I believe you can
safely comment out this check.

--
Olav Morken

Stefano Gargiulo

unread,
Sep 11, 2009, 3:58:18 AM9/11/09
to simple...@googlegroups.com
Olav Morken ha scritto:
I've found the same problem during the development of a simpleSAMLphp based Joomla extension, then i modified simpleSAMLphp r1712 to support external algorithm autodetect and decrypting of EncryptedNameIDs (EncryptedNameIDs  are a standard configuration of Shibboleth's IdP, then if you not support this you must define a differet relying party on the IdP for the simpleSAMLphp SPs, and this is not elegant on a federation (and less secure) )

I send to you the modified files, it works, then you can use this temporary, waiting for the real merge on simpleSAMLphp trunk ( i've already send this files to Andreas Solberg. that replyed to me that them are in a merging-reviewing phase):

andreas...@gmail.com wrote:
Thanks for your contribution Stefano!

I forward this contribution to Olav Morken, which will look into testing it and merging it with trunk.

Andreas


Begin forwarded message:

From: Stefano Gargiulo <stefano....@garr.it>
Date: 27. august 2009 18:03.33 GMT+02.00
Subject: I've added saml:EncryptedNameID support to simpleSAMLphp SP (r1712), can i commit the code?

Hi Andreas,

I'm Stefano Gargiulo: a developer working at GARR (The Italian NREN),

I'm working to write a  portable Joomla extension targeted for the upcoming Italian education and research Federation : IDEM (http://www.idem.garr.it/).

IDEM is a federation project  (ready to production) based on Shibboleth2, then we have Shibboleth2.1.X IdPs and SPs, but i opted to write this Joomla component with simpleSAMLphp because shibd is to hard to distribute (hard installation
and configuration, zero portability,apache dependency etc.) then we need to offer an easy way to integrate existing portals and webapps in the AAI: your framework is perfect for this!

Then now i'm integrating simpleSAMLphp in Joomla!, using it as a SAML2.0 SP...

But i found two problems in the code (i checked-out revision 1712):

 1. No algorithm auto-detect of the recived encrypted assertions  -> Fixed!

 2. No support for encryptedNameIDs -> Added!

i'm attaching to you the ".diff" file of the modifications that i made (the diff is made on my own repository).

Then if you like it, i will appreciate if i can commit it in the official repo, or if I can appear in the contributors list as "Stefano Gargiulo (GARR)"..

If this is not possible there's no problem for me, but please add this "nameID encryption support"
because this kind of encryption now comes activated out-of-the-box with Shibboleth 2.1.X IdP.

Best Regards,
Stefano Gargiulo.

Index: JoomlaShib/com_idemauth/simplesamlphp/lib/SAML2/Assertion.php
===================================================================
--- JoomlaShib/com_idemauth/simplesamlphp/lib/SAML2/Assertion.php (revision 14)
+++ JoomlaShib/com_idemauth/simplesamlphp/lib/SAML2/Assertion.php (revision 15)
@@ -8,6 +8,9 @@
 */
class SAML2_Assertion implements SAML2_SignedElement {

+        public $hasNameIdEncrypted =false;
+
+
/**
* The identifier of this assertion.
*
@@ -219,15 +222,19 @@
throw new Exception('More than one <saml:Subject> in <saml:Assertion>.');
}
$subject = $subject[0];
- $nameId = SAML2_Utils::xpQuery($subject, './saml:NameID');
- if (empty($nameId)) {
- throw new Exception('Missing <saml:NameID> in <saml:Subject>.');
+        $nameId = SAML2_Utils::xpQuery($subject, './saml:NameID');
+        if (empty($nameId)) {
+                            $this->hasNameIdEncrypted = true;
+    $this->nameId = SAML2_Utils::xpQuery($subject, './saml:EncryptedID');
} elseif (count($nameId) > 1) {
throw new Exception('More than one <saml:NameID> in <saml:Subject>.');
}
- $nameId = $nameId[0];
- $this->nameId = SAML2_Utils::parseNameId($nameId);

+                if (!$this->hasNameIdEncrypted){
+                    $nameId = $nameId[0];
+                    $this->nameId = SAML2_Utils::parseNameId($nameId);
+                }
+
$subjectConfirmation = SAML2_Utils::xpQuery($subject, './saml:SubjectConfirmation');
if (empty($subjectConfirmation)) {
throw new Exception('Missing <saml:SubjectConfirmation> in <saml:Subject>.');
Index: JoomlaShib/com_idemauth/simplesamlphp/lib/SAML2/EncryptedAssertion.php
===================================================================
--- JoomlaShib/com_idemauth/simplesamlphp/lib/SAML2/EncryptedAssertion.php (revision 14)
+++ JoomlaShib/com_idemauth/simplesamlphp/lib/SAML2/EncryptedAssertion.php (revision 15)
@@ -8,160 +8,252 @@
 */
class SAML2_EncryptedAssertion {

- /**
- * The current encrypted assertion.
- *
- * @var DOMElement
- */
- private $encryptedData;
+/**
+ * The current encrypted assertion.
+ *
+ * @var DOMElement
+ */
+    private $encryptedData;


- /**
- * Constructor for SAML 2 encrypted assertions.
- *
- * @param DOMElement|NULL $xml  The encrypted assertion XML element.
- */
- public function __construct(DOMElement $xml = NULL) {
- if ($xml === NULL) {
- return;
- }
+    /**
+     * Constructor for SAML 2 encrypted assertions.
+     *
+     * @param DOMElement|NULL $xml  The encrypted assertion XML element.
+     */
+    public function __construct(DOMElement $xml = NULL) {
+        if ($xml === NULL) {
+            return;
+        }

- $data = SAML2_Utils::xpQuery($xml, './xenc:EncryptedData');
- if (count($data) === 0) {
- throw new Exception('Missing encrypted data in <saml:EncryptedAssertion>.');
- } elseif (count($data) > 1) {
- throw new Exception('More than one encrypted data element in <saml:EncryptedAssertion>.');
- }
- $this->encryptedData = $data[0];
- }
+        $data = SAML2_Utils::xpQuery($xml, './xenc:EncryptedData');
+        if (count($data) === 0) {
+            throw new Exception('Missing encrypted data in <saml:EncryptedAssertion>.');
+        } elseif (count($data) > 1) {
+            throw new Exception('More than one encrypted data element in <saml:EncryptedAssertion>.');
+        }
+        $this->encryptedData = $data[0];
+    }


- /**
- * Set the assertion.
- *
- * @param SAML2_Assertion $assertion  The assertion.
- * @param XMLSecurityKey $key  The key we should use to encrypt the assertion.
- */
- public function setAssertion(SAML2_Assertion $assertion, XMLSecurityKey $key) {
+    /**
+     * Set the assertion.
+     *
+     * @param SAML2_Assertion $assertion  The assertion.
+     * @param XMLSecurityKey $key  The key we should use to encrypt the assertion.
+     */
+    public function setAssertion(SAML2_Assertion $assertion, XMLSecurityKey $key) {

- $xml = $assertion->toXML();
+        $xml = $assertion->toXML();

- $enc = new XMLSecEnc();
- $enc->setNode($xml);
- $enc->type = XMLSecEnc::Element;
+        $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;
+        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:
- $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
- $symmetricKey->generateSessionKey();
+            case  XMLSecurityKey::RSA_1_5:
+                $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
+                $symmetricKey->generateSessionKey();

- $enc->encryptKey($key, $symmetricKey);
+                $enc->encryptKey($key, $symmetricKey);

- break;
+                break;

- default:
- throw new Exception('Unknown key type for encryption: ' . $key->type);
- }
+            default:
+                throw new Exception('Unknown key type for encryption: ' . $key->type);
+        }

- $this->encryptedData = $enc->encryptNode($symmetricKey);
- }
+        $this->encryptedData = $enc->encryptNode($symmetricKey);
+    }


- /**
- * Retrieve the assertion.
- *
- * @param XMLSecurityKey $key  The key we should use to decrypt the assertion.
- * @return SAML2_Assertion  The decrypted assertion.
- */
- public function getAssertion(XMLSecurityKey $inputKey) {
+    /**
+     * Retrieve the assertion.
+     *
+     * @param $keyArray  The key array containing the key we should use to decrypt the assertion.
+     * @return SAML2_Assertion  The decrypted assertion.
+     */
+    public function getAssertion($keyArray) {

- $enc = new XMLSecEnc();
+        $enc = new XMLSecEnc();

- $enc->setNode($this->encryptedData);
- $enc->type = $this->encryptedData->getAttribute("Type");
+        $enc->setNode($this->encryptedData);
+        $enc->type = $this->encryptedData->getAttribute("Type");

- $symmetricKey = $enc->locateKey($this->encryptedData);
- if (!$symmetricKey) {
- throw new Exception('Could not locate key algorithm in encrypted data.');
- }
+        $symmetricKey = $enc->locateKey($this->encryptedData);
+        if (!$symmetricKey) {
+            throw new Exception('Could not locate key algorithm in encrypted data.');
+        }

- $symmetricKeyInfo = $enc->locateKeyInfo($symmetricKey);
- if (!$symmetricKeyInfo) {
- throw new Exception('Could not locate <dsig:KeyInfo> for the encrypted key.');
- }
+        $symmetricKeyInfo = $enc->locateKeyInfo($symmetricKey);
+        if (!$symmetricKeyInfo) {
+            throw new Exception('Could not locate <dsig:KeyInfo> for the encrypted key.');
+        }

- if ($symmetricKeyInfo->isEncrypted) {
+
+                /* Extract the public key from the certificate for encryption. */
+        //Algorithm is fetched on received keyInfo:
+        $inputKey = new XMLSecurityKey($symmetricKeyInfo->getAlgorith(), array('type'=>'private'));
+
+        if (array_key_exists('password', $keyArray)) {
+            $inputKey->passphrase = $keyArray['password'];
+        }
+        $inputKey->loadKey($keyArray['PEM']);
+
+        if ($symmetricKeyInfo->isEncrypted) {
/* Make sure that the input key  format is the same as the one used to encrypt the key. */
- if ($inputKey->getAlgorith() !== $symmetricKeyInfo->getAlgorith()) {
-     throw new Exception('Algorithm mismatch between input key and key used to encrypt ' .
- ' the symmetric key for the message. Key was: ' .
- var_export($inputKey->getAlgorith(), TRUE) . '; message was: ' .
- var_export($symmetricKeyInfo->getAlgorith(), TRUE));
-                              
- }
+            if ($inputKey->getAlgorith() !== $symmetricKeyInfo->getAlgorith()) {
+                throw new Exception('Algorithm mismatch between input key and key used to encrypt ' .
+                    ' the symmetric key for the message. Key was: ' .
+                    var_export($inputKey->getAlgorith(), TRUE) . '; message was: ' .
+                    var_export($symmetricKeyInfo->getAlgorith(), TRUE));

- $encKey = $symmetricKeyInfo->encryptedCtx;
- $symmetricKeyInfo->key = $inputKey->key;
- $key = $encKey->decryptKey($symmetricKeyInfo);
- $symmetricKey->loadkey($key);
- } else {
+            }
+
+            $encKey = $symmetricKeyInfo->encryptedCtx;
+            $symmetricKeyInfo->key = $inputKey->key;
+            $key = $encKey->decryptKey($symmetricKeyInfo);
+            $symmetricKey->loadkey($key);
+        } else {
/* Make sure that the input key has the correct format. */
- if ($inputKey->getAlgorith() !== $symmetricKey->getAlgorith()) {
- throw new Exception('Algorithm mismatch between input key and key in message. ' .
- 'Key was: ' . var_export($inputKey->getAlgorith(), TRUE) . '; message was: ' .
- var_export($symmetricKey->getAlgorith(), TRUE));
- }
- $symmetricKey = $inputKey;
- }
+            if ($inputKey->getAlgorith() !== $symmetricKey->getAlgorith()) {
+                throw new Exception('Algorithm mismatch between input key and key in message. ' .
+                    'Key was: ' . var_export($inputKey->getAlgorith(), TRUE) . '; message was: ' .
+                    var_export($symmetricKey->getAlgorith(), TRUE));
+            }
+            $symmetricKey = $inputKey;
+        }

- $decrypted = $enc->decryptNode($symmetricKey, FALSE);
+        $decrypted = $enc->decryptNode($symmetricKey, FALSE);

/*
* This is a workaround for the case where only a subset of the XML
* tree was serialized for encryption. In that case, we may miss the
* namespaces needed to parse the XML.
*/
- $xml = '<root xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'.$decrypted.'</root>';
- $newDoc = new DOMDocument();
- if (!$newDoc->loadXML($xml)) {
- throw new Exception('Failed to parse decrypted XML. Maybe the wrong sharedkey was used?');
- }
- $assertionXML = $newDoc->firstChild->firstChild;
- if ($assertionXML === NULL) {
- throw new Exception('Missing encrypted assertion within <saml:EncryptedAssertion>.');
- }
- return new SAML2_Assertion($assertionXML);
- }
+        $xml = '<root xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'.$decrypted.'</root>';
+        $newDoc = new DOMDocument();
+        if (!$newDoc->loadXML($xml)) {
+            throw new Exception('Failed to parse decrypted XML. Maybe the wrong sharedkey was used?');
+        }
+        $assertionXML = $newDoc->firstChild->firstChild;
+        if ($assertionXML === NULL) {
+            throw new Exception('Missing encrypted assertion within <saml:EncryptedAssertion>.');
+        }
+        $decryptedAss = new SAML2_Assertion($assertionXML);
+        if ($decryptedAss->hasNameIdEncrypted) {
+            $encNameIDData=$decryptedAss->getNameId();
+            $encNameIDData= $encNameIDData[0]->firstChild;
+            $enc = new XMLSecEnc();
+            $enc->setNode($encNameIDData);
+            $enc->type = $encNameIDData->getAttribute("Type");

+            $symmetricKey = $enc->locateKey($encNameIDData);
+            if (!$symmetricKey) {
+                throw new Exception('Could not locate key algorithm in encrypted data.');
+            }

- /**
- * Convert this encrypted assertion to an XML element.
- *
- * @param DOMNode|NULL $parentElement  The DOM node the assertion should be created in.
- * @return DOMElement  This encrypted assertion.
- */
- public function toXML(DOMNode $parentElement = NULL) {
+            $symmetricKeyInfo = $enc->locateKeyInfo($symmetricKey);
+            if (!$symmetricKeyInfo) {
+                throw new Exception('Could not locate <dsig:KeyInfo> for the encrypted key.');
+            }

- if ($parentElement === NULL) {
- $document = new DOMDocument();
- $parentElement = $document;
- } else {
- $document = $parentElement->ownerDocument;
- }

- $root = $document->createElementNS(SAML2_Const::NS_SAML, 'saml:' . 'EncryptedAssertion');
- $parentElement->appendChild($root);
+            /* Extract the public key from the certificate for encryption. */
+            //Algorithm is fetched on received keyInfo:
+            $inputKey = new XMLSecurityKey($symmetricKeyInfo->getAlgorith(), array('type'=>'private'));

- $root->appendChild($document->importNode($this->encryptedData, TRUE));
+            if (array_key_exists('password', $keyArray)) {
+                $inputKey->passphrase = $keyArray['password'];
+            }
+            $inputKey->loadKey($keyArray['PEM']);

- return $root;
- }
+            if ($symmetricKeyInfo->isEncrypted) {
+ /* Make sure that the input key  format is the same as the one used to encrypt the key. */
+                if ($inputKey->getAlgorith() !== $symmetricKeyInfo->getAlgorith()) {
+                    throw new Exception('Algorithm mismatch between input key and key used to encrypt ' .
+                        ' the symmetric key for the encrypted NameID. Key was: ' .
+                        var_export($inputKey->getAlgorith(), TRUE) . '; message was: ' .
+                        var_export($symmetricKeyInfo->getAlgorith(), TRUE));

+                }
+
+                $encKey = $symmetricKeyInfo->encryptedCtx;
+                $symmetricKeyInfo->key = $inputKey->key;
+                $key = $encKey->decryptKey($symmetricKeyInfo);
+                $symmetricKey->loadkey($key);
+            } else {
+ /* Make sure that the input key has the correct format. */
+                if ($inputKey->getAlgorith() !== $symmetricKey->getAlgorith()) {
+                    throw new Exception('Algorithm mismatch between input key and key in encrypted NameID. ' .
+                        'Key was: ' . var_export($inputKey->getAlgorith(), TRUE) . '; message was: ' .
+                        var_export($symmetricKey->getAlgorith(), TRUE));
+                }
+                $symmetricKey = $inputKey;
+            }
+
+            $decrypted = $enc->decryptNode($symmetricKey, FALSE);
+
+
+            $xml = $decrypted;
+           
+                 $newNode= dom_import_simplexml(simplexml_load_string($xml));
+
+           // $newNode->
+            $decryptedAss->setNameId(SAML2_Utils::parseNameId($newNode));
+           
+          
+        }
+        return $decryptedAss;
+    }
+
+
+    //TODO decript Name ID
+/*
+ * <root xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ * <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_d79682e8ee53cb52e3be99a6fc254f45" IssueInstant="2009-08-26T16:54:25.915Z" Version="2.0">
+ * <saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://192.168.0.60/idp/shibboleth</saml:Issuer>
+ * <saml:Subject>
+ *
+ * <saml:EncryptedID><xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="_ae20983b33eb8657142d02c62193ff75" Type="http://www.w3.org/2001/04/xmlenc#Element">
+ * <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod><ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><xenc:EncryptedKey Id="_bbcb7e000893784c7ce0863c3cbb46e9"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod></xenc:EncryptionMethod><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhMCTk8xGDAWBgNV BAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDgYDVQQKEwdVTklORVRUMRgwFgYD VQQDEw9mZWlkZS5lcmxhbmcubm8xITAfBgkqhkiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAe Fw0wNzA2MTUxMjAxMzVaFw0wNzA4MTQxMjAxMzVaMIGEMQswCQYDVQQGEwJOTzEYMBYGA1UECBMP QW5kcmVhcyBTb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBAMT D2ZlaWRlLmVybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZXR0Lm5vMIGfMA0G CSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3BqKxupQe0LONoliupiBOesCO3SHbDrl 3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLCn7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3 TcfCGPtKTytHOge/OlJbo078dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUA A4GBACDVfp86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2WykUqRXF+dLfcUH9dWR63CtZIKFDbStN omPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJVhTyvLgFVK2QarQ4/6 7OZfHd7R+POBXhophSMv1ZOo</ds:X509Certificate></ds:X509Data></ds:KeyInfo><xenc:CipherData><xenc:CipherValue>m3rEm1q3e/6FqVU1aK9EzfTHyElWYXNCJxtAuyvUiqRgeLQUiDoFPJzOhtwlo59TylCXJsmRle2t 6TnagJVrDQ2g8lGOX626zFTkBT/7Y7ABVGlT//M18qQSI25l7PexB5n7L75Ip72ApDo+ZvkId0Jr uhqyZS6DAuxNW5t3Y1M=</xenc:CipherValue></xenc:CipherData></xenc:EncryptedKey></ds:KeyInfo><xenc:CipherData><xenc:CipherValue>QctiDQSpR327tifD2+pERpTnTlHrTq+4aUCKg4At6E3Ekg3hqi+9GSsJrw3cMb3bkn8cgF37yGpG tFeyytK+8PLH395JZf4VxYcT/fkoGD+lX5rfnIi9k9TBvfVHqYyGYI8FNMx7s6HrVd3yBbDB2ggl TODc8MVFi/n+1iKskRZMnpDIhgTcEmjhaYa2p37aOk7JKq4hRmnCdU1WXx6rqP+lAEfIGoFVOmrg Dq0QVIpXG8d73YJ4pny/2CjfIG60</xenc:CipherValue></xenc:CipherData></xenc:EncryptedData>
+ * </saml:EncryptedID>
+ *
+ * <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData Address="193.206.159.218" InResponseTo="_0b920ee54d38b3d23b6bad00fc46009850e31a1ec3" NotOnOrAfter="2009-08-26T16:59:25.915Z" Recipient="http://192.168.0.80/joomla/components/com_idemauth/simplesamlphp/www/saml2/sp/AssertionConsumerService.php"></saml:SubjectConfirmationData></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2009-08-26T16:54:25.915Z" NotOnOrAfter="2009-08-26T16:59:25.915Z"><saml:AudienceRestriction><saml:Audience>http://192.168.0.80/joomla/components/com_idemauth/simplesamlphp/www/saml2/sp/metadata.php</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="2009-08-26T16:54:25.854Z" SessionIndex="b20a70ad2d93d2ffff4b367c90b5c81ffc2ac13946720c92cbff04110f4e3cd0"><saml:SubjectLocality Address="193.206.159.218"></saml:SubjectLocality><saml:AuthnContext><saml:AuthnContextDeclRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextDeclRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute FriendlyName="eduPersonPrincipalNameAffiliation" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.6" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">garg...@garr.it</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="eduPersonAffiliation" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">member</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="facsimileTelephoneNumber" Name="urn:oid:2.5.4.23" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">+39</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="schacMotherTongue" Name="urn:oid:1.3.6.1.4.1.25178.1.2.1" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">it</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="eduPersonScopedAffiliation" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">mem...@garr.it</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="givenName" Name="urn:oid:2.5.4.42" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Stefano</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="preferredLanguage" Name="urn:oid:2.16.840.1.113730.3.1.39" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">it-en</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="title" Name="urn:oid:2.5.4.12" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Developer</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="eduPersonOrgDN" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.3" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">dc=garr,dc=it</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="schacUserPresenceID" Name="urn:oid:1.3.6.1.4.1.25178.1.2.12" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">skype:rast...@skype.com</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="eduPersonEntitlement" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.7" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">urn:mace:rediris.es:entitlement:wiki:tfemc2</saml:AttributeValue><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">urn:mace:garr.it:idem:dir:test_shibbolet_app1</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="mail" Name="urn:oid:0.9.2342.19200300.100.1.3" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">stefano....@garr.it</saml:AttributeValue><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">rast...@gmail.com</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="sn" Name="urn:oid:2.5.4.4" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Gargiulo</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="schacPersonalPosition" Name="urn:oid:1.3.6.1.4.1.25178.1.2.13" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">-- reserved for fututre IDEM implem. --</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="eduPersonTargetedID" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" NameQualifier="https://192.168.0.60/idp/shibboleth" SPNameQualifier="http://192.168.0.80/joomla/components/com_idemauth/simplesamlphp/www/saml2/sp/metadata.php">eEwVykWu/5CBeRbRASJPYtNEEWo=</saml:NameID></saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="eduPersonOrgUnitDN" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.4" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">dc=dir,dc=garr,dc=it</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="cn" Name="urn:oid:2.5.4.3" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Stefano Gargiulo</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="telephoneNumber" Name="urn:oid:2.5.4.20" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">+39 06 4962 2547</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="schacPersonalTitle" Name="urn:oid:1.3.6.1.4.1.25178.1.2.8" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Sig.</saml:AttributeValue></saml:Attribute><saml:Attribute FriendlyName="mobile" Name="urn:oid:0.9.2342.19200300.100.1.41" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">+39 380 340 66 81</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion></root>
+ *
+ *
+ *
+ */
+
+
+    /**
+     * Convert this encrypted assertion to an XML element.
+     *
+     * @param DOMNode|NULL $parentElement  The DOM node the assertion should be created in.
+     * @return DOMElement  This encrypted assertion.
+     */
+    public function toXML(DOMNode $parentElement = NULL) {
+
+        if ($parentElement === NULL) {
+            $document = new DOMDocument();
+            $parentElement = $document;
+        } else {
+            $document = $parentElement->ownerDocument;
+        }
+
+        $root = $document->createElementNS(SAML2_Const::NS_SAML, 'saml:' . 'EncryptedAssertion');
+        $parentElement->appendChild($root);
+
+        $root->appendChild($document->importNode($this->encryptedData, TRUE));
+
+        return $root;
+    }
+
}
Index: JoomlaShib/com_idemauth/simplesamlphp/modules/saml2/lib/Message.php
===================================================================
--- JoomlaShib/com_idemauth/simplesamlphp/modules/saml2/lib/Message.php (revision 14)
+++ JoomlaShib/com_idemauth/simplesamlphp/modules/saml2/lib/Message.php (revision 15)
@@ -312,16 +312,20 @@
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_OAEP_MGF1P, array('type'=>'private'));

- if (array_key_exists('password', $keyArray)) {
- $key->passphrase = $keyArray['password'];
- }
- $key->loadKey($keyArray['PEM']);
+
+
+
}

- return $assertion->getAssertion($key);
+                $assertion = $assertion->getAssertion($keyArray);
+                try{
+                    $assertion->getNameId();
+                }catch(Exception $e){
+                    //se non
+                }
+
+ return $assertion;
}




Assertion.php
EncryptedAssertion.php
Message.php
Graphical_overview_of_the_CHANGESET.JPG

Olav Morken

unread,
Sep 11, 2009, 4:08:26 AM9/11/09
to simple...@googlegroups.com
> *I send to you the modified files*, it works, then you can use this
> temporary, waiting for the real merge on simpleSAMLphp trunk ( i've
> already send this files to Andreas Solberg. that replyed to me that them
> are in a merging-reviewing phase):

Yes, I have got the mail, but haven't had the time to look at it yet.
I will get around to it soon, probably early next week.

--
Olav Morken

Peter Schober

unread,
Sep 12, 2009, 8:04:31 AM9/12/09
to simple...@googlegroups.com
* Stefano Gargiulo <stefano....@garr.it> [2009-09-11 09:58]:

> EncryptedNameIDs (EncryptedNameIDs are a standard configuration of
> Shibboleth's IdP, then if you not support this you must define a
> differet relying party on the IdP for the simpleSAMLphp SPs, and
> this is not elegant on a federation (and less secure) )

1. From 2.1.3 on Shibboleth's default is to *not* encrypt NameIDs
inside encrypted assertions, so this has been dealt with.
For existing installations it always was just a one-word change in
a single config file (see below).

2. You *never* had to define a different relying party on the IdP,
you just once set encryptNameIds="never" on the SAML2SSOProfile
configuration and be done with it.

3. Finally, disabling encrypted NameIDs inside encrypted assertions is
*not* less secure by any sane definition of security.
It was more of an oversight on the Shib IdP side that the same
logic that caused assertions to be encrypted (i.e. the transport
not being secure when pushing over the browser) was applied for
the encryption of NameIDs. Encrypting it twice doesn't make it more
secure.

So while I think it's *great* you implemented handling of encrypted
NameIDs in simpleSAMLphp (and hopefully this will help interop), all
of the above reasoning is flawed.
-peter

Stefano Gargiulo

unread,
Sep 12, 2009, 5:34:53 PM9/12/09
to simple...@googlegroups.com
Peter Schober ha scritto:
* Stefano Gargiulo <stefano....@garr.it> [2009-09-11 09:58]:
  
EncryptedNameIDs (EncryptedNameIDs are a standard configuration of
Shibboleth's IdP, then if you not support this you must define a
differet relying party on the IdP for the simpleSAMLphp SPs, and
this is not elegant on a federation (and less secure) )
    
1. From 2.1.3 on Shibboleth's default is to *not* encrypt NameIDs
   inside encrypted assertions, so this has been dealt with.
   For existing installations it always was just a one-word change in
   a single config file (see below).
  
That's true, i didn't know that...

2. You *never* had to define a different relying party on the IdP,
   you just once set encryptNameIds="never" on the SAML2SSOProfile
   configuration and be done with it.
  
That's teorically true, but pratically if you have a federated IdP you may don't want to set encryptNameIds="never"  for all the federation entities... don't you think?

In fact all the simpleSAMLphp SP -> Shibboleth 2.1.x  guides that i found on the web suggested to do this:
   <RelyingParty id="your-sp-id"
                  provider="https://your-idp-host/idp/shibboleth"
                  defaultSigningCredentialRef="IdPCredential" >
       <ProfileConfiguration xsi:type="saml:SAML2SSOProfile"
                             encryptNameIds="never"
                             encryptAssertions="never"
                             />
    </RelyingParty
the source of this is your official site:
 http://rnd.feide.no/content/using-simplesamlphp-sp-with-shibboleth-21-idp

Then maybe you don't wanna to do this, and maybe (this was my case) you don't wanna ask all the sysadmin of all the IdPs to change their configuration when adding a simpleSAMLphp to your federation, but you want just to update the federation metadata with the new SP...

3. Finally, disabling encrypted NameIDs inside encrypted assertions is
   *not* less secure by any sane definition of security.
   It was more of an oversight on the Shib IdP side that the same
   logic that caused assertions to be encrypted (i.e. the transport
   not being secure when pushing over the browser) was applied for
   the encryption of NameIDs. Encrypting it twice doesn't make it more
   secure.
  
secuirty managers not are sane.. they are paranoic, for profession...

but in my mind, when i wrote "less secure" i was thinking to another thing that simpleSAMLphp - Shibboleth interop doesn't permit:
Did you have noted that in the interop guide that i quoted there is aslo said to set a relying party with:
                             encryptAssertions="never"
this is a more serious security issue... don't you think? I solved it with the algorithm detection... (the issue reported in this email subject)...

then your point 1. is not valid because ecryptAssertion="true" is still a default in head svn Shib IdP revision... then you can't interoperate by the default relying party... (that's was my point)


So while I think it's *great* you implemented handling of encrypted
NameIDs in simpleSAMLphp (and hopefully this will help interop), all
of the above reasoning is flawed.
-peter
  
I don't implemented it.... I just reused your code to implement it... :)


but why discuss on this??? we are not in war... then let's just make running the open-source engine!

bye,
Stefano.

Olav Morken

unread,
Sep 16, 2009, 5:00:21 AM9/16/09
to simple...@googlegroups.com

I just committed a patch which I believe fixes this problem.

--
Olav Morken

Peter Schober

unread,
Sep 16, 2009, 11:05:53 AM9/16/09
to simple...@googlegroups.com
* Olav Morken <olav....@uninett.no> [2009-09-16 11:00]:

> I just committed a patch which I believe fixes this problem.

r1757 did it, thanks!
-peter

Reply all
Reply to author
Forward
0 new messages