Search code examples
aemkeystoresaml

Loading a PKCS-12 keystore in AEM 6.0


I am trying to move my SAML integration code from a CQ 5.6.1 environment to AEM 6.0.

While my login works correctly, I'm stuck at the logout implementation. The same snippet of code runs on 5.6.1, but throws an I.O Exception in AEM 6.0

Here's the code in question

     Node contentNode = resourceResolver.getResource("path_to_cert")
            .adaptTo(Node.class);

    Binary content = contentNode.getProperty("jcr:data").getBinary();
    log.info("Binary data from certificate -->"+content);

    InputStream stream = content.getStream();

    KeyStore keyStoreFile = java.security.KeyStore.getInstance("PKCS12");
    keyStoreFile.load(stream, "Newuser@123".toCharArray());

And here is the error I see :-

Caused by: java.io.IOException: Could not decrypt data.
    at com.rsa.cryptoj.o.gx.b(Unknown Source)
    at com.rsa.cryptoj.o.gx.a(Unknown Source)
    at com.rsa.cryptoj.o.gx.a(Unknown Source)
    at com.rsa.cryptoj.o.gx.a(Unknown Source)
    at com.rsa.cryptoj.o.gx.a(Unknown Source)
    at com.rsa.cryptoj.o.gx.engineLoad(Unknown Source)
    at java.security.KeyStore.load(Unknown Source)
    at 

This snippet works perfectly fine on CQ 5.6.1, and the certificates generated in both 5.6.1 and AEM 6.0 are identical, created on my Java 7 machine.

Are there any certificate/keystore related changes unique to AEM 6.0 that is causing this? Or what am I doing wrong?


Solution

  • i have had a similar issue and solved it by passing a provider-String:

    Keystore.getInstance("PKCS12", "SunJSSE")