Workaround unknown SecureRandom strong algorithm with OpenJDK17 & RHEL & BCFIPS provider when run in FIPS-enabled environment #40665
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes: #40659
When run on RHEL8 with Open JDK 17 with BCFIPS provider the SecureRandom strong algorithm is
NativePRNGBlocking:SUN,DRBG:SUN
, algorithms that are not available.Keycloak works around that by just initializing default SecureRandom with known strong algorithms (PKCS11:SunPKCS11-NSS-FIPS) and removing them, but that means that when Vert.x loads keystores during the HTTP Server startup (when users can't provide their fixes, before app starts) and
org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider#getCoreSecureRandom
is invoked whilegetInstanceStrong
throws exception, it leads to initializingorg.bouncycastle.jcajce.provider.BouncyCastleFipsProvider.CoreSecureRandom#CoreSecureRandom
withsun.security.provider.SecureRandom()
and following exception is thrownBouncyCastleFipsProvider$CoreSecureRandom (in unnamed module @0x621a387f) cannot access class sun.security.provider.SecureRandom
.I've tried both using reflection to invoke
org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider#getDefaultSecureRandom
and initialize initialize SecureRandom instance via Java API, but BCFIPS require this strong algorithm later as well. I think we need to keep it in place.My thinking (AKA selected code lines from KC) is that if
NoSuchAlgorithmException
is thrown, that won't change until user code is run on app startup (extensions could do something sooner). Which is too late, and if they want to change the strong algorithm, they can change what we set as well.Tested only in JVM as native mode is not working #37500.