gnodet-bot commented on code in PR #30945:
URL: https://github.com/apache/camel/pull/30945#discussion_r4717714339


##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java:
##########
@@ -840,58 +832,48 @@ private void generateEncapsulation(Exchange exchange)
         }
 
         KeyGenerator generator = keyGeneratorForExchange();
-        SecretKeyWithEncapsulation secEnc1;
+        BouncyCastleKemSupport.EncapsulationResult secEnc1;
         synchronized (PQCKemLocks.lockFor(generator, keyPair.getPublic())) {
-            // initialise for creating an encapsulation and shared secret.
-            generator.init(
-                    new KEMGenerateSpec(
-                            keyPair.getPublic(),
-                            // The mapped JCE algorithm name, as the extract 
operations use: for the algorithms whose
-                            // enum name differs from the JCE name 
(GOST3412_2015 -> GOST3412-2015, DESEDE -> DESede)
-                            // the raw name is not a resolvable cipher, and 
the two ends of the exchange would disagree
-                            // on the identity of the key
-                            
PQCSymmetricAlgorithms.valueOf(getConfiguration().getSymmetricKeyAlgorithm()).getAlgorithm(),
-                            
getEndpoint().getConfiguration().getSymmetricKeyLength()),
+            secEnc1 = BouncyCastleKemSupport.encapsulate(

Review Comment:
   ⚠️ **Redundant lock — now superseded by `BouncyCastleKemSupport`**
   
   After this refactoring `BouncyCastleKemSupport.encapsulate(generator, ...)` 
acquires `PQCKemLocks.lockFor(generator, publicKey)` **internally** (see 
`BouncyCastleKemSupport` line 89). This outer `synchronized` block takes the 
same lock first. Java monitors are reentrant so there is no deadlock, but the 
outer lock is now dead weight: the locking contract is split across two layers.
   
   Since `BouncyCastleKemSupport` now owns the locking for the `KeyGenerator` 
path, please remove the `synchronized` block here (and the matching one in 
`extractEncapsulation`). The same applies to the equivalent blocks in 
`HybridKEM`.



##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/BouncyCastlePqcCompatibility.java:
##########
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.pqc;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.GeneralSecurityException;
+import java.security.PrivateKey;
+import java.security.spec.AlgorithmParameterSpec;
+
+/**
+ * Isolates the LMS/HSS and XMSS/XMSSMT JCA API package changes between Bouncy 
Castle releases.
+ *
+ * <p>
+ * BC 1.86 exposes these parameter specs and stateful-key interfaces in the 
legacy {@code org.bouncycastle.pqc.jcajce}
+ * packages. BC 1.87 also exposes the current {@code org.bouncycastle.jcajce} 
types and deprecates the legacy aliases.
+ * This class keeps those version-specific names out of the component's 
compile-time dependencies. It prefers the
+ * current API and falls back to the legacy API only when the current type is 
unavailable.
+ * </p>
+ *
+ * <p>
+ * Reflection is deliberately limited to this compatibility boundary. Runtime 
BC classes are resolved with the
+ * application context class loader first, then the component class loader, so 
a platform BOM can supply the runtime
+ * implementation. The adapter does not retain resolved BC classes in global 
caches. Stateful-key accessors use
+ * {@link ClassValue} so their lifetime follows the key class. Callers use 
ordinary {@link AlgorithmParameterSpec} and

Review Comment:
   💡 **Javadoc claim contradicts the implementation**
   
   The class Javadoc states: _"The adapter does not retain resolved BC classes 
in global caches."_
   
   However, `STATEFUL_KEY_ACCESSORS` is a `ClassValue<StatefulKeyAccessors>` — 
that IS a global cache (keyed by `Class<?>`). The statement is likely referring 
to parameter-spec classes (which are intentionally not cached), but as written 
it is incorrect.
   
   Suggested correction: _"Parameter-spec classes are resolved on demand 
without global caching. Stateful-key accessors are cached via `ClassValue` with 
key-class lifetime."_



##########
components/camel-pqc/src/test/java/org/apache/camel/component/pqc/crypto/hybrid/HybridKEMHkdfTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.pqc.crypto.hybrid;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HexFormat;
+
+import org.bouncycastle.crypto.Digest;
+import org.bouncycastle.crypto.digests.SHA256Digest;
+import org.bouncycastle.crypto.digests.SHA384Digest;
+import org.bouncycastle.crypto.digests.SHA512Digest;
+import org.bouncycastle.crypto.generators.HKDFBytesGenerator;
+import org.bouncycastle.crypto.params.HKDFParameters;

Review Comment:
   ⚠️ **Test imports BC internal `crypto` package**
   
   The new `Hkdf.java` deliberately avoids BC imports, using only 
`javax.crypto.Mac`. This test reintroduces coupling to 
`org.bouncycastle.crypto.*` internal types (`HKDFBytesGenerator`, 
`SHA256Digest`, etc.) to cross-validate the output. If BC reorganizes its 
internal API (it already did so between 1.86 and 1.87 for the PQC specs), this 
test breaks even though `Hkdf.java` itself is unchanged.
   
   Consider replacing with [RFC 5869 Appendix 
A](https://www.rfc-editor.org/rfc/rfc5869#appendix-A) known-answer test vectors 
— they provide stronger correctness guarantees and have no external 
dependencies.



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