JDeveloper ADF Mobile -- javax.crypto - unable to locate policy files

3.2k Views Asked by At

I am trying to encrypt some secure information in a mobile application being developed using ADF Mobile. I am using "javax.crypto.Cipher". As per my understanding ADF Mobile packs it's own JVM along with the application's apk/ipa for deployment purposes.But during deployment we are facing the following issue

java.lang.ExceptionInInitializerError
at java.lang.Class.runStaticInitializers(Unknown Source)
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.getInstance(Unknown Source)

Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
01-08 16:10:19.758: D/CVM(769): at javax.crypto.SunJCE_b.<clinit>(Unknown Source)
01-08 16:10:19.768: D/CVM(769): ... 14 more
01-08 16:10:19.768: D/CVM(769): Caused by: java.lang.SecurityException: Cannot locate    policy or framework files!
01-08 16:10:19.768: D/CVM(769): at javax.crypto.SunJCE_b.g(Unknown Source)
01-08 16:10:19.768: D/CVM(769): at javax.crypto.SunJCE_b.f(Unknown Source)
01-08 16:10:19.768: D/CVM(769): at javax.crypto.SunJCE_t.run(Unknown Source)

at the following line: Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

Where will these policy files be? How to check whether they are present or not?

Any help would be greatly appreciated.Please let me know if you need additional info.

1

There are 1 best solutions below

0
On

Looks like problem in Sun JCE provider, and doesn't ADF related. I can reproduce in jdk 1.4_2.19 and JCE 1.2.2 by replacing $JRE_HOME/lib/jce.jar to jce1_2_2.jar. In this case a got

Exception in thread "main" java.lang.ExceptionInInitializerError
    at javax.crypto.Cipher.a(DashoA6275)
    at javax.crypto.Cipher.getInstance(DashoA6275)
    at Test.main(Test.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs: java.security.PrivilegedActionException: java.net.MalformedURLException: no protocol: US_export_policy.jar
    at javax.crypto.SunJCE_b.<clinit>(DashoA6275)
    ... 8 more

As workaround you can use BouncyCastle provider (with returning original $JRE_HOME/lib/jce.jar back and removing all SunJCE related in $JRE_HOME/lib/ext).

public class Test {
    static {
        Security.addProvider(new BouncyCastleProvider());
    }
    public static void main(String[] args) throws Exception {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}