From 9ed502174da32af5ca5c49c1126fe9033b3694b6 Mon Sep 17 00:00:00 2001 From: Oscar Guindzberg Date: Mon, 17 Dec 2018 18:50:34 -0300 Subject: [PATCH] Add code to avoid manual step for setting unlimited cipher length in JDK 8 (no jce_policy-8.zip to copy anymore) Cherry pick https://github.com/bisq-network/bitcoinj/commit/d508df1157afe94572d6602bb48d3ce602442dc2 --- .../bitcoinj/crypto/BIP38PrivateKeyTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/test/java/org/bitcoinj/crypto/BIP38PrivateKeyTest.java b/core/src/test/java/org/bitcoinj/crypto/BIP38PrivateKeyTest.java index 5cbbc30ec7c..982f1ede0a9 100644 --- a/core/src/test/java/org/bitcoinj/crypto/BIP38PrivateKeyTest.java +++ b/core/src/test/java/org/bitcoinj/crypto/BIP38PrivateKeyTest.java @@ -20,21 +20,40 @@ import org.bitcoinj.crypto.BIP38PrivateKey.BadPassphraseException; import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.TestNet3Params; +import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.fail; public class BIP38PrivateKeyTest { private static final MainNetParams MAINNET = MainNetParams.get(); private static final TestNet3Params TESTNET = TestNet3Params.get(); + @Before + public void setUnlimitedCipherInJDK8() { + // hack for JCE Unlimited Strength for jdk8 does not require to copy jce_policy-8.zip in $JAVA_HOME/jre/lib/security/ + try { + Field field = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted"); + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, false); + } catch (Exception e) { + e.printStackTrace(System.err); + } + } + @Test public void bip38testvector_noCompression_noEcMultiply_test1() throws Exception { BIP38PrivateKey encryptedKey = BIP38PrivateKey.fromBase58(MAINNET,