z-kovacs commented on code in PR #20542:
URL: https://github.com/apache/pulsar/pull/20542#discussion_r1230637152


##########
pulsar-client-messagecrypto-bc/src/main/java/org/apache/pulsar/client/impl/crypto/MessageCryptoBc.java:
##########
@@ -106,28 +80,64 @@ public class MessageCryptoBc implements 
MessageCrypto<MessageMetadata, MessageMe
 
 
     private static final SecureRandom secureRandom;
+
+    private static final String providerName;
+    private static BcVersionSpecificCryptoUtility 
bcVersionSpecificCryptoUtilityDelegate;
+
     static {
-        SecureRandom rand = null;
-        try {
-            rand = SecureRandom.getInstance("NativePRNGNonBlocking");
-        } catch (NoSuchAlgorithmException nsa) {
-            rand = new SecureRandom();
-        }
 
-        secureRandom = rand;
+        providerName = SecurityUtility.getProvider().getName();
+
+        switch (providerName) {
+            case SecurityUtility.BC:
+                SecureRandom rand = null;
+                try {
+                    rand = SecureRandom.getInstance("NativePRNGNonBlocking", 
providerName);
+                } catch (NoSuchAlgorithmException | NoSuchProviderException 
nsa) {
+                    rand = new SecureRandom();
+                }
+                secureRandom = rand;
+                break;
+            case SecurityUtility.BC_FIPS:
+                try {
+                    secureRandom = SecureRandom.getInstance("NONCEANDIV", 
providerName);
+                } catch (NoSuchAlgorithmException | NoSuchProviderException 
nsa) {
+                    throw new RuntimeException(
+                            "In BC FIPS mode, we expect the specific Random 
generators to be available!");
+                }
+                break;

Review Comment:
   > Could we use the NONCEANDIV for generating ASE and sending messages?
   
   We can, but I would advise against it unless an expert says otherwise, as it 
is not for that based on the documentation. Generally for keys you want a 
higher-grade random generator (thus `DEFAULT` is prediction resistant). 
   A comment referring to this:
   
https://github.com/indrabasak/bouncycastle-fips-examples/blob/master/src/main/java/com/basaki/bc/fips/random/SecureRandomNumberExample.java#L86-L87
   
   Could you please elaborate on what would we gain from using `NONCEANDIV` for 
everything?
   
   On the other hand `DEFAULT` is configurable, so I assume if someone wants to 
use BC FIPS (as it's a very specific industry-related use-case), they should 
know about how to configure it in case they experience issues.
   see: https://www.bouncycastle.org/fips-java/BCFipsIn100.pdf page 13



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to