Skip to content

Commit cf308ab

Browse files
committed
Merge pull request lightbody#351 from jekh/fix-test-error-when-unlimited-strength-not-available
Remove test dependency on unlimited strength policy files
2 parents 29de4db + ca5b21c commit cf308ab

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

mitm/src/main/java/net/lightbody/bmp/mitm/util/EncryptionUtil.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import net.lightbody.bmp.mitm.exception.ExportException;
44
import net.lightbody.bmp.mitm.exception.ImportException;
55

6+
import javax.crypto.Cipher;
67
import java.io.File;
78
import java.io.IOException;
89
import java.math.BigInteger;
910
import java.nio.charset.StandardCharsets;
1011
import java.nio.file.Files;
1112
import java.security.Key;
13+
import java.security.NoSuchAlgorithmException;
1214
import java.security.interfaces.DSAKey;
1315
import java.security.interfaces.ECKey;
1416
import java.security.interfaces.RSAKey;
@@ -107,4 +109,19 @@ public static String readPemStringFromFile(File file) {
107109
throw new ImportException("Unable to read PEM-encoded data from file: " + file.getName());
108110
}
109111
}
112+
113+
/**
114+
* Determines if unlimited-strength cryptography is allowed, i.e. if this JRE has then the unlimited strength policy
115+
* files installed.
116+
*
117+
* @return true if unlimited strength cryptography is allowed, otherwise false
118+
*/
119+
public static boolean isUnlimitedStrengthAllowed() {
120+
try {
121+
return Cipher.getMaxAllowedKeyLength("AES") >= 256;
122+
} catch (NoSuchAlgorithmException e) {
123+
return false;
124+
}
125+
126+
}
110127
}

mitm/src/test/groovy/net/lightbody/bmp/mitm/PemFileCertificateSourceTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package net.lightbody.bmp.mitm
22

33
import net.lightbody.bmp.mitm.exception.ImportException
44
import net.lightbody.bmp.mitm.test.util.CertificateTestUtil
5+
import net.lightbody.bmp.mitm.util.EncryptionUtil
56
import org.junit.Before
67
import org.junit.Rule
78
import org.junit.Test
@@ -11,6 +12,7 @@ import java.nio.file.Files
1112
import java.nio.file.StandardCopyOption
1213

1314
import static org.junit.Assert.assertNotNull
15+
import static org.junit.Assume.assumeTrue
1416

1517
class PemFileCertificateSourceTest {
1618

@@ -34,6 +36,8 @@ class PemFileCertificateSourceTest {
3436

3537
@Test
3638
void testCanLoadCertificateAndPasswordProtectedKey() {
39+
assumeTrue("Skipping test because unlimited strength cryptography is not available", EncryptionUtil.isUnlimitedStrengthAllowed())
40+
3741
PemFileCertificateSource pemFileCertificateSource = new PemFileCertificateSource(certificateFile, encryptedPrivateKeyFile, "password")
3842

3943
CertificateAndKey certificateAndKey = pemFileCertificateSource.load()

0 commit comments

Comments
 (0)