You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2026/08/28 15:54:55 UTC
(pulsar) branch master updated: [improve][client] Seed MessageCryptoBc from the BC-FIPS DRBG when that provider is registered (#26154)
This is an automated email from the ASF dual-hosted git repository.
merlimat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 367caffaa1fa [improve][client] Seed MessageCryptoBc from the BC-FIPS DRBG when that provider is registered (#26154)
367caffaa1fa is described below
commit 367caffaa1faa6bc97b7e2f5640df71b1476c206
Author: David Kjerrumgaard <35...@users.noreply.github.com>
AuthorDate: Fri Aug 28 08:54:48 2026 -0700
[improve][client] Seed MessageCryptoBc from the BC-FIPS DRBG when that provider is registered (#26154)
Co-authored-by: Copilot Autofix powered by AI <17...@users.noreply.github.com>
---
.../pulsar/client/impl/crypto/MessageCryptoBc.java | 31 +++++++++++++++++++---
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/pulsar-client-messagecrypto-bc/src/main/java/org/apache/pulsar/client/impl/crypto/MessageCryptoBc.java b/pulsar-client-messagecrypto-bc/src/main/java/org/apache/pulsar/client/impl/crypto/MessageCryptoBc.java
index 7363cc3ecdb0..e42e8d2a9583 100644
--- a/pulsar-client-messagecrypto-bc/src/main/java/org/apache/pulsar/client/impl/crypto/MessageCryptoBc.java
+++ b/pulsar-client-messagecrypto-bc/src/main/java/org/apache/pulsar/client/impl/crypto/MessageCryptoBc.java
@@ -124,10 +124,33 @@ public class MessageCryptoBc implements MessageCrypto<MessageMetadata, MessageMe
private static final SecureRandom secureRandom;
static {
SecureRandom rand;
- try {
- rand = SecureRandom.getInstance("NativePRNGNonBlocking");
- } catch (NoSuchAlgorithmException nsa) {
- rand = new SecureRandom();
+ Provider bcfips = Security.getProvider("BCFIPS");
+ if (bcfips != null) {
+ // When the BC-FIPS provider is registered, source randomness from its SP 800-90A
+ // DRBG so data-key and IV generation stays within the FIPS-validated module.
+ // Only registered providers are consulted here to avoid triggering BouncyCastle
+ // classpath resolution during class loading (see BcProviderHolder above).
+ try {
+ rand = SecureRandom.getInstance("DEFAULT", bcfips);
+ } catch (NoSuchAlgorithmException nsa) {
+ // Deliberately fatal rather than falling back: new SecureRandom() resolves by provider
+ // search order and may land outside the validated module, which is exactly what this
+ // branch exists to prevent. Registering BCFIPS is an operator asking for FIPS-approved
+ // randomness, and a data key or GCM IV drawn from anywhere else leaves no trace at run
+ // time -- SP 800-38D only permits a random 96-bit GCM IV from an approved DRBG. Failing
+ // class initialization surfaces the misconfiguration at the point it can still be fixed.
+ throw new IllegalStateException("The BCFIPS provider is registered but its DEFAULT SP "
+ + "800-90A DRBG could not be obtained; refusing to fall back to a non-FIPS "
+ + "SecureRandom for data-key and IV generation.", nsa);
+ }
+ } else {
+ try {
+ rand = SecureRandom.getInstance("NativePRNGNonBlocking");
+ } catch (NoSuchAlgorithmException nsa) {
+ // Unchanged: on a JVM without NativePRNGNonBlocking the platform default is the
+ // long-standing behaviour, and no FIPS guarantee was being claimed on this path.
+ rand = new SecureRandom();
+ }
}
secureRandom = rand;