davsclaus commented on code in PR #27768:
URL: https://github.com/apache/camel/pull/27768#discussion_r4257437189


##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java:
##########
@@ -625,41 +635,75 @@ private static byte[] bodyToByteArray(Message message) 
throws InvalidPayloadExce
         }
     }
 
+    /**
+     * Returns the KEM {@link KeyGenerator} to use for a single exchange.
+     * <p>
+     * A KEM {@code KeyGenerator} keeps the spec passed to {@code init()} 
until {@code generateKey()} reads it and is
+     * not thread-safe, so the two calls of one exchange must not interleave 
with those of another. As with
+     * {@link #signerForExchange()}, an instance this producer created is 
simply created again, while a configured one -
+     * an autowired bean can be shared by every endpoint, and {@code 
PQCDefault*Material.keyGenerator} JVM-wide - is
+     * handed back as-is, and the caller serializes on whatever it gets.
+     */
+    private KeyGenerator keyGeneratorForExchange() throws 
NoSuchAlgorithmException {
+        if (keyGeneratorAlgorithm == null) {
+            return keyGenerator;
+        }
+        return KeyGenerator.getInstance(keyGeneratorAlgorithm, 
keyGeneratorProvider);
+    }

Review Comment:
   Optional, could be a follow-up: the producer treats any `KeyGenerator` it 
finds in the configuration as configured. But `PQCComponent` puts one there 
itself in two cases:
   
   - With `parameterSpec` and no key material, 
`configureParameterSpecMaterial()` does 
`configuration.setKeyGenerator(KeyGenerator.getInstance(...))`. That endpoint 
now runs all its KEM exchanges one at a time, although nobody configured that 
instance.
   - With no key material at all, `createEndpoint()` sets 
`PQCDefault*Material.keyGenerator`. That lock is JVM-wide, shared by every 
`pqc` KEM endpoint that uses the default material.
   
   A `KeyGenerator` holds no key, so the component could set only the `keyPair` 
in those two places. The producer would then create its own generator for each 
exchange from `keyEncapsulationAlgorithm`. The same applies to the `Signature` 
set in `configureParameterSpecMaterial()` from CAMEL-24445. This is not a 
correctness problem, and the upgrade guide already describes the 
default-material case, so it is fine to leave it out of this PR.



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