Decrypting assertion fails

Sandy sundeep.nitw at gmail.com
Wed Jan 21 06:53:07 EST 2015


Hi,

We are using Shibboleth as IdP, and OpenSaml for SP.

1. We turned on Encryption in IdP in relying-party.xml for our SP
2. SP supplies it's public key in its metadata
3. IdP is encrypting using the public key in SP's metadata(Sample assertion
below).
4. While decrypting at SP, we are using the private key for the public key
in SP metadata(code below)

The decryption fails with the following Exception:

ERROR org.opensaml.xml.encryption.Decrypter  - Error decrypting the
encrypted data element
org.apache.xml.security.encryption.XMLEncryptionException: Invalid AES key
length: 1218 bytes

My Cryptography knowledge is limited, so pardon me if I'm wrong. WikiPedia
says AES is symmetric key algorithm. If IdP uses public key for encryption,
why does org.opensaml.xml.encryption.Decrypter try to decrypt using AES and
fails?

---------------- Encrypted Assertion from IdP-------------------------

<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
Destination="http://myhost:8080/saml.jsp"
ID="_b5fc7c6e0aee49f7f8cae692d4f95300" InResponseTo="1421769637471"
IssueInstant="2015-01-20T16:00:37.504Z" Version="2.0">
  <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">
https://idp.mycompany.com/idp/shibboleth</saml2:Issuer>
  <saml2p:Status>
    <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
  </saml2p:Status>
  <saml2:EncryptedAssertion
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
    <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
Id="_52920151365a097df61102971ab20384" Type="
http://www.w3.org/2001/04/xmlenc#Element">
      <xenc:EncryptionMethod xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
Id="_557c37d85f9e2048780ac25e3b90bf39">
          <xenc:EncryptionMethod xmlns:xenc="
http://www.w3.org/2001/04/xmlenc#" Algorithm="
http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
            <ds:DigestMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
          </xenc:EncryptionMethod>
          <ds:KeyInfo>
            <ds:X509Data>
              <ds:X509Certificate>.... Certificate
Elided...</ds:X509Certificate>
            </ds:X509Data>
          </ds:KeyInfo>
          <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
            <xenc:CipherValue>..544 characters elided..</xenc:CipherValue>
          </xenc:CipherData>
        </xenc:EncryptedKey>
      </ds:KeyInfo>
      <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <xenc:CipherValue>..5632 characters elided...</xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedData>
  </saml2:EncryptedAssertion>
</saml2p:Response>

------------------ End of Assertion
------------------------------------------------

----------- Decryption code at SP
---------------------------------------------

FileInputStream fin = new FileInputStream(configuration.getTrustStore());
KeyStore keystore = KeyStore.getInstance(keyStoreType);
keystore.load(fin,null);
trustedCredentials = new ArrayList<Credential>();
Enumeration<String> aliases = keystore.aliases();
KeyStore.PasswordProtection passwordProt = new
KeyStore.PasswordProtection("mypassword".toCharArray());
//Add all certificates from trust store
while(aliases.hasMoreElements())
{
        alias = aliases.nextElement();
        if(alias!=null && !alias.isEmpty()) {
             X509Certificate cert = (X509Certificate)
keystore.getCertificate(alias);
             //keystore.
            BasicX509Credential otherCred1 = new BasicX509Credential();
            otherCred1.setEntityCertificate(cert);
            otherCred1.setEntityId(entityID);
            if(keystore.isKeyEntry(alias)) {
                        KeyStore.Entry ksEntry =
keystore.getEntry(alias,passwordProt);
                          if(ksEntry instanceof KeyStore.PrivateKeyEntry) {

otherCred1.setPrivateKey(((KeyStore.PrivateKeyEntry)
ksEntry).getPrivateKey());
                          }
                        }

             trustedCredentials.add(otherCred1);
        }
}

 List<EncryptedAssertion> encAssertions = response.getEncryptedAssertions();

if(encAssertions!=null && !encAssertions.isEmpty())
{
    StaticKeyInfoCredentialResolver skicr = new
StaticKeyInfoCredentialResolver(trustedCredentials);
    Decrypter samlDecrypter = new Decrypter(skicr,null,null);
    //samlDecrypter.setRootInNewDocument(true);
    if(assertions==null) assertions = new ArrayList<Assertion>();
    try
    {
        for(EncryptedAssertion encAssertion: encAssertions)
        {
            Assertion decAssertion = samlDecrypter.decrypt(encAssertion);
            assertions.add(decAssertion);
        }
    }catch(DecryptionException e)
    {
        fLogger.error("Error while decrypting assertion",e);
    }
}

-------------- End of decryption code-------------------------


Thank you,
Sundeep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20150121/2bc8b9f8/attachment.html 


More information about the dev mailing list