Copilot commented on code in PR #26154:
URL: https://github.com/apache/pulsar/pull/26154#discussion_r3537101050


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/KeyManagerProxy.java:
##########
@@ -96,7 +96,17 @@ private void updateKeyManager()
             final CertificateFactory cf = 
CertificateFactory.getInstance("X.509");
             final List<X509Certificate> certificateList = 
cf.generateCertificates(publicCertStream)
                     .stream().map(o -> (X509Certificate) 
o).collect(Collectors.toList());
-            keyStore = KeyStore.getInstance("JKS");
+            // In-memory keystore holding the PEM-loaded key and cert chain. 
JKS is preferred
+            // because it accepts certificate lists that do not form a linked 
chain (which
+            // PKCS12 rejects); fall back to the platform default type on JVMs 
where the JKS
+            // keystore type is unavailable, e.g. under a FIPS-restricted 
security configuration.
+            KeyStore selectedKeyStore;
+            try {
+                selectedKeyStore = KeyStore.getInstance("JKS");
+            } catch (KeyStoreException e) {
+                selectedKeyStore = 
KeyStore.getInstance(KeyStore.getDefaultType());
+            }
+            keyStore = selectedKeyStore;

Review Comment:
   If the fallback KeyStore type also fails, the original JKS failure is lost, 
which makes diagnosing provider/FIPS issues harder. Consider rethrowing the 
fallback exception with the original JKS exception added as suppressed (or vice 
versa).



##########
pulsar-client-messagecrypto-bc/src/main/java/org/apache/pulsar/client/impl/crypto/MessageCryptoBc.java:
##########
@@ -124,7 +124,16 @@ private static Provider bcProvider() {
     static {
         SecureRandom rand;
         try {
-            rand = SecureRandom.getInstance("NativePRNGNonBlocking");
+            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).
+                rand = SecureRandom.getInstance("DEFAULT", bcfips);
+            } else {
+                rand = SecureRandom.getInstance("NativePRNGNonBlocking");
+            }
         } catch (NoSuchAlgorithmException nsa) {

Review Comment:
   When the BCFIPS provider is present, a failure to obtain its "DEFAULT" DRBG 
currently falls back to `new SecureRandom()`, which may select a non-FIPS 
provider depending on provider order. If the intent is to keep key/IV 
generation within the FIPS-validated module when BCFIPS is registered, it’s 
safer to fail fast (or otherwise ensure a BCFIPS-backed SecureRandom) rather 
than silently falling back.



-- 
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