12

Can someone explain to me how to install Unlimited Strength Jurisdiction Policy Files. I downloaded .jar files from Oracle website but I'm having a problem with installing them. Java program that I'm making keeps giving me this error:

Jan 11, 2017 12:32:31 AM com.subgraph.orchid.TorClient start
INFO: Starting Orchid (version: 1.0.0)
Jan 11, 2017 12:32:31 AM com.subgraph.orchid.TorClient verifyUnlimitedStrengthPolicyInstalled
SEVERE: Unlimited Strength Jurisdiction Policy Files are required but not installed.
Exception in thread "main" com.subgraph.orchid.TorException: Unlimited Strength Jurisdiction Policy Files are required but not installed.
    at com.subgraph.orchid.TorClient.verifyUnlimitedStrengthPolicyInstalled(TorClient.java:208)
    at com.subgraph.orchid.TorClient.start(TorClient.java:79)
    at com.nikola.WebCrawlerApp.App$OrchidDemo.startOrchid(App.java:46)
    at com.nikola.WebCrawlerApp.App$OrchidDemo.access$000(App.java:38)
    at com.nikola.WebCrawlerApp.App.main(App.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Derlin
  • 9,572
  • 2
  • 32
  • 53
  • Try a [web search](https://www.google.com/search?q=How+to+install+Unlimited+Strength+Jurisdiction+Policy+Files%3F) for the title of your question. Alternative: **Read the README file** that 's in the zip file you download. Down-vote for lack of research. – Andreas Jan 10 '17 at 23:56
  • 1
    How did you "install" them? – assylias Jan 10 '17 at 23:56
  • Related: https://stackoverflow.com/questions/3862800/invalidkeyexception-illegal-key-size – Mark Rotteveel Apr 23 '19 at 14:49
  • Rather than trying to change my current JDK I installed Java JDK1.8.0_301 which solved the issue for me as the security files have already been updated there... – Andre Nel Jul 29 '21 at 10:46

6 Answers6

23

2018-01-15 Update

According to JDK-8170157, since JDK 6u181, 7u171, 8u161, 9b148 unlimited cryptographic policy is enabled by default. So all you have to do is just upgrade to the corresponding baseline.

Original answer

Since Java 9 and Java 8u151 there's no need to download and manually install jurisdiction policy files anymore. According to release notes:

In older releases, JCE jurisdiction files had to be downloaded and installed separately to allow unlimited cryptography to be used by the JDK. The download and install steps are no longer necessary. To enable unlimited cryptography, one can use the new crypto.policy Security property. If that new Security property is set in the java.security file, or has been set dynamically by using the Security.setProperty() call before the JCE framework has been initialized, that setting will be honoured. By default, the property will be undefined. If the property is undefined and the legacy JCE jurisdiction files don't exist in the legacy lib/security directory, then the default cryptographic level will remain at limited. To configure the JDK to use unlimited cryptography, set the crypto.policy to a value of unlimited. See the notes in the java.security file shipping with this release for more information.

Community
  • 1
  • 1
Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51
9

You need to determine your Java home path (either via System.getenv("JAVA_HOME") from Java or $ echo $JAVA_HOME on the command line). It should be a path like the following:

  • C:\Program Files\Java\jre8 on Windows
  • /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home on Mac OS X
  • /usr/java/jdk1.8.0_101/bin/java on *nix

You then need to copy the US_export_policy.jar and local_policy.jar files you downloaded into the directory: <JAVA_HOME>/jre/lib/security and overwrite the existing files of the same name.

Updated 05/17/17

The following code (for demonstration purposes only) will instruct the JVM that it is allowed to use AES-256 bit encryption and corresponding TLS ciphers regardless of the policy files installed. It is not recommended to employ this method.

if (Cipher.getMaxAllowedKeyLength("AES") < 256) {
  try {
    Field field = Class.forName("javax.crypto.JceSecurity").
    getDeclaredField("isRestricted");
    field.setAccessible(true);
    field.set(null, java.lang.Boolean.FALSE);
  } catch (Exception e) {
    fail("Could not override JCE cryptography strength policy setting");
    fail(e.getMessage());
  }
}
Andy
  • 13,916
  • 1
  • 36
  • 78
  • 1
    What if you want your application to be portable , and bring them as libraries ? Is there any solution for this :) ? – GOXR3PLUS May 17 '17 at 22:34
  • There are brittle hacks of the JVM using reflection to override the security check, or you could bundle them in an installer package that installed them to the user's JRE home (this may violate Oracle's TOS, I don't know). If you want your application to be truly portable, don't rely on the unlimited strength policies being present. AES-128 is still plenty strong at this time. – Andy May 18 '17 at 00:00
  • Unfortunately it isn't enough for the purpose i want http://stackoverflow.com/questions/44031398/fetching-data-from-httpurlconnection-as-text-throws-javax-net-ssl-sslhandshakeex , i need `256-bit symmetric ciphers` – GOXR3PLUS May 18 '17 at 01:00
  • You can hack the JVM to believe it has access to 256-bit ciphers. Full disclaimer: this code is for demonstration only; I am not recommending you do this (see updated answer). – Andy May 18 '17 at 01:06
  • I appreciate a lot your effort . I am using Java 1.8.0_121 and it isn't working i mean [if you try the code from my question on the link](http://stackoverflow.com/questions/44031398/fetching-data-from-httpurlconnection-as-text-throws-javax-net-ssl-sslhandshakeex) it produces the same error . It seems that `Java 8 Update 121` is not allowing reflection hacks . The only hope i see is with Java 9. – GOXR3PLUS May 18 '17 at 01:14
  • The answer helps a lot while I was working with blockchain. Thanks. – Arefe Aug 21 '17 at 10:11
1

i had the same problem and none of the above answers worked for me so as i found the solution i decided to share it here to help others

what worked for me in the end was simply download the Unlimited Strength Jurisdiction Policy Files from oracle website

unzip the folder and move the files inside the folder into $JAVA_HOME\jre\lib\security overwriting the files already in there with the same name

replace JAVA_HOME with the actual jdk folder of your java installation

Moshe Edri
  • 244
  • 2
  • 10
  • For me also file was there already but still was not working and by replacing files as per your suggestion helped me resolve issue. – TechnoCrat Feb 10 '20 at 14:11
0

In $JAVA_HOME/jre/lib/security, edit the file java.security and uncomment the line crypto.policy=unlimited (it's about 823 lines down a 932-line file).

ejoftheweb
  • 301
  • 1
  • 2
  • 10
-1

For JDK 1.6 you can do it the following way:

private void hackJCE() throws Exception {
    try {
        if (Cipher.getMaxAllowedKeyLength("AES") < 256) {
            Field field = Class.forName("javax.crypto.SunJCE_b").
            getDeclaredField("g");
            field.setAccessible(true);
            field.set(null, false);
        }
    } catch (Exception e) {
        return;
    }
}
-2

To programmatically handle this, The following code in Scala will help you do it. The code given above will not work for java version 8. You will get an error. Error : Can not set static final boolean field javax.crypto.JceSecurity.isRestricted to java.lang.Boolean

if (Cipher.getMaxAllowedKeyLength("AES") < 256) {
 try {
 var field=Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted")
    field.setAccessible(true)
   var modifiersField = classOf[Field].getDeclaredField( "modifiers" )
   modifiersField.setAccessible(true);
   modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(null, java.lang.Boolean.FALSE)
  }

  catch{
    case ex:Exception=>throw ex
  }
}