oscerd commented on code in PR #28091:
URL: https://github.com/apache/camel/pull/28091#discussion_r4314486191
##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCComponent.java:
##########
@@ -345,8 +354,13 @@ private void configureHybridKEMMaterial(PQCConfiguration
configuration) {
return;
}
+ // Captured before anything is auto-configured: the pre-built hybrid
materials below replace the PQC half as
+ // well, and must only do so when the route author did not supply it
+ boolean pqcMaterialMissing =
ObjectHelper.isEmpty(configuration.getKeyGenerator())
Review Comment:
You are right, and this was the most valuable catch of the round — thank
you. I reproduced it: with the version I had pushed, a hybrid KEM endpoint
using X25519 or ECDH_P256 with MLKEM ends up on `PQCDefaultMLKEMMaterial`
(ML-KEM-512) instead of the matched ML-KEM-768 material. I shipped a silent
security-level downgrade.
Fixed in cfee7fd. Both flags are now captured in `createEndpoint`
immediately after `setProperties`, before `configureParameterSpecMaterial` and
the two generic blocks, and passed into `configureHybridSignatureMaterial` /
`configureHybridKEMMaterial`.
_Claude Code on behalf of @oscerd_
##########
components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCHybridKeyPairPreservedTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.SecureRandom;
+import java.security.Security;
+
+import javax.crypto.KeyGenerator;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.bouncycastle.jcajce.spec.MLDSAParameterSpec;
+import org.bouncycastle.jcajce.spec.MLKEMParameterSpec;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+/**
+ * Auto-configuring the classical half of a hybrid endpoint must not replace
PQC key material the route author supplied:
+ * signing with a silently substituted key produces signatures nobody can
verify against the real key.
+ */
+public class PQCHybridKeyPairPreservedTest {
+
+ // Per-test: until CAMEL-25795 lands, stopping a context de-registers the
providers for the whole JVM
+ @BeforeEach
+ void setup() {
+ if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
+ Security.addProvider(new BouncyCastleProvider());
+ }
+ if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) ==
null) {
+ Security.addProvider(new BouncyCastlePQCProvider());
+ }
+ }
+
+ @Test
+ void hybridSignKeepsTheConfiguredPqcKeyPair() throws Exception {
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("ML-DSA", "BC");
+ kpg.initialize(MLDSAParameterSpec.ml_dsa_65, new SecureRandom());
+ KeyPair myKeyPair = kpg.generateKeyPair();
+
+ try (CamelContext context = new DefaultCamelContext()) {
+ // keyPair and classicalKeyPair are both autowired, so a single
KeyPair bean would be injected into both
+ // and the classical branch under test would never run
+ context.setAutowiredEnabled(false);
+ context.getRegistry().bind("myKeyPair", myKeyPair);
+ context.start();
+
+ PQCEndpoint endpoint = context.getEndpoint(
+ "pqc:sign?operation=hybridSign&signatureAlgorithm=MLDSA"
+ +
"&classicalSignatureAlgorithm=ECDSA_P256&keyPair=#myKeyPair",
+ PQCEndpoint.class);
+
+ assertSame(myKeyPair, endpoint.getConfiguration().getKeyPair(),
+ "the configured PQC key pair must survive hybrid
auto-configuration");
+ assertNotNull(endpoint.getConfiguration().getClassicalKeyPair(),
+ "the classical half must still be auto-configured");
+ }
+ }
+
+ @Test
+ void hybridKemKeepsTheConfiguredPqcKeyPair() throws Exception {
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("ML-KEM", "BC");
+ kpg.initialize(MLKEMParameterSpec.ml_kem_768, new SecureRandom());
+ KeyPair myKeyPair = kpg.generateKeyPair();
+ KeyGenerator myKeyGenerator = KeyGenerator.getInstance("ML-KEM", "BC");
+
+ try (CamelContext context = new DefaultCamelContext()) {
+ // keyPair and classicalKeyPair are both autowired, so a single
KeyPair bean would be injected into both
+ // and the classical branch under test would never run
+ context.setAutowiredEnabled(false);
+ context.getRegistry().bind("myKeyPair", myKeyPair);
+ context.getRegistry().bind("myKeyGenerator", myKeyGenerator);
+ context.start();
+
+ PQCEndpoint endpoint = context.getEndpoint(
+
"pqc:kem?operation=hybridGenerateSecretKeyEncapsulation&keyEncapsulationAlgorithm=MLKEM"
+ +
"&classicalKEMAlgorithm=X25519&keyPair=#myKeyPair&keyGenerator=#myKeyGenerator",
+ PQCEndpoint.class);
+
+ assertSame(myKeyPair, endpoint.getConfiguration().getKeyPair(),
+ "the configured PQC key pair must survive hybrid
auto-configuration");
+ assertSame(myKeyGenerator,
endpoint.getConfiguration().getKeyGenerator(),
+ "the configured PQC key generator must survive hybrid
auto-configuration");
+ assertNotNull(endpoint.getConfiguration().getClassicalKeyPair(),
+ "the classical half must still be auto-configured");
+ }
+ }
+
+ @Test
+ void hybridSignStillAutoConfiguresWhenNothingIsSupplied() throws Exception
{
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.start();
+
+ PQCEndpoint endpoint = context.getEndpoint(
+
"pqc:sign?operation=hybridSign&signatureAlgorithm=MLDSA&classicalSignatureAlgorithm=ECDSA_P256",
+ PQCEndpoint.class);
+
+ assertNotNull(endpoint.getConfiguration().getKeyPair(), "the PQC
half must be auto-configured");
Review Comment:
Done in cfee7fd. `hybridSignStillAutoConfiguresWhenNothingIsSupplied` is now
`hybridSignStillAutoConfiguresTheMatchedPair` and asserts
`assertSame(PQCDefaultECDSAMLDSAMaterial.pqcKeyPair, ...)`, and there is a new
`hybridKemStillAutoConfiguresTheMatchedPair` asserting
`PQCDefaultX25519MLKEMMaterial.pqcKeyPair`.
Confirmed they work: against the previously pushed commit both fail with a
KeyPair identity mismatch. The `assertNotNull` version passed against it,
exactly as you said.
_Claude Code on behalf of @oscerd_
--
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]