Unable to decrypt assertion in OpenSAML3
Brent Putman
putmanb at georgetown.edu
Wed Sep 4 18:34:07 EDT 2019
On 9/2/19 2:46 AM, DD K wrote:
>
> public static Assertion getDecryptedAssertion(EncryptedAssertion encryptedAssertion, X509Credential x509Credential)
> throws DecryptionException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
>
> KeyInfoCredentialResolver keyResolver = new StaticKeyInfoCredentialResolver(x509Credential); Decrypter decrypter = new Decrypter(null, keyResolver, null); EncryptedKey key = encryptedAssertion.getEncryptedData().getKeyInfo().getEncryptedKeys().get(0); SecretKey dkey = (SecretKey) decrypter.decryptKey(key, encryptedAssertion.getEncryptedData().
> getEncryptionMethod().getAlgorithm()); // Error caused here Credential shared = CredentialSupport.getSimpleCredential(dkey); decrypter = new Decrypter(new StaticKeyInfoCredentialResolver(shared), null, null); decrypter.setRootInNewDocument(true); return decrypter.decrypt(encryptedAssertion); }
>
I think your main issue is that you are using 2 different Decrypter
instances, and you aren't invoking setRootInNewDocument on the first
one, which (I think) is required by how you are using the output of
it. Try that and see how it goes.
A secondary issue is that you don't really need to do all that. The
code above is needlessly complicated. You really just want 1
Decrypter, with appropriate ctor args of:
- arg 0 as null
- arg 1 as the static KeyInfo cred resolver containing the X509
cred with private key (assuming you don't want a more realistic
resolution strategy)
- arg 2 as an EncryptedKeyResolver covering how you are placing the
EncryptedKey relative to the EncryptedData.
Then it handles internally all of what you are doing - locating and
decrypting the EncryptedKey to SecretKey, then using that to decrypt
the EncryptedData.
It's also artificial to encrypt and then immediately decrypt in that
fashion. To fully test a round trip you really ought to at least
marshall the EncryptedAssertion to DOM and then unmarshall a new
EncryptedAssertion around it. Or even marshall and then serialize it to
something (e.g. byte[]) and then parse it again and unmarshall.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/dev/attachments/20190904/8d3394c2/attachment.html>
More information about the dev
mailing list