When I am setting up as a application in Jenkins. The code works fine in local and other build environments. In Jenkins i am getting this error during the build and unit tests. Our application only needed external change is download JCE (Jave Crypto Extension) from oracle and replace the policy jars in JAVA_HOME/jre/lib/security folder. that I did. I can see log it is picking up those jars. Still i see below error. Do i need to do anything for secure random? SecureRandom.getInstanceStrong();
is causing the issue. any help?
[ERROR] Null/empty securerandom.strongAlgorithms Security Property
[ERROR] at com.test.cipher.AesGcmCipher.generate(AesGcmCipher.java:72)
[ERROR] at com.test.scheme.Version1CryptoSchemeAesGcmTest$1.getDefaultCipher(Version1CryptoSchemeAesGcmTest.java:27)
[ERROR] at com.test.scheme.Version1CryptoSchemeAesGcmTest$1.getDefaultCipher(Version1CryptoSchemeAesGcmTest.java:24)
[ERROR] at com.test.CachingCryptoCipherProvider.<init>(CachingCryptoCipherProvider.java:43)
[ERROR] at com.test.CryptoCipherProvider.asCachingProvider(CryptoCipherProvider.java:28)
[ERROR] at com.test.scheme.Version1CryptoSchemeAesGcmTest.createAesGcmProvider(Version1CryptoSchemeAesGcmTest.java:35)
[ERROR] at com.test.scheme.Version1CryptoSchemeAesGcmTest.<init>(Version1CryptoSchemeAesGcmTest.java:20)
[ERROR] ... 28 more
[ERROR] Caused by: java.security.NoSuchAlgorithmException: Null/empty securerandom.strongAlgorithms Security Property
[ERROR] at java.security.SecureRandom.getInstanceStrong(SecureRandom.java:627)
[ERROR] at com.test.cipher.AesGcmCipher.generate(AesGcmCipher.java:62)
[ERROR] ... 34 more`
Below is my java code.
public class AesGcmCipher {
public static AesGcmCipher generate(BiConsumer<AesGcmCipher, SecretKey> consumer) {
try {
UUID cipherId = UUID.randomUUID();
SecureRandom random = SecureRandom.getInstanceStrong();
KeyGenerator keyGen = KeyGenerator.getInstance(AES);
AesGcmCipher cipher = new AesGcmCipher(cipherId, secretKey, new Date());
return cipher;
} catch (NoSuchAlgorithmException ex) {
LOGGER.error(msg);
throw new CryptoException(msg, ex);
}
}
}
FYI Jenkins is running on java version "1.8.0_73"
. The code which is running perfectly on other machines with version 1.8.0_51
and 1.8.0_91
It should be an issue with your jdk. Could you verify this file $JAVA_HOME/jre/lib/security/java.security
:
securerandom.source=file:/dev/random
securerandom.strongAlgorithms=NativePRNGBlocking:SUN
This is my configuration, probably you'll need to reinstall JDK