This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch camel-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/camel-main by this push:
new c69ee8518ec [camel-main] pqc: work around camel-pqc requiring
BouncyCastle 1.87
c69ee8518ec is described below
commit c69ee8518ec47f58d97fc35410c8756a54538b61
Author: James Netherton <[email protected]>
AuthorDate: Fri Nov 27 08:22:41 2026 +0000
[camel-main] pqc: work around camel-pqc requiring BouncyCastle 1.87
Ref #9583
camel-pqc is compiled against BouncyCastle 1.87, which moved the LMS / XMSS
JCA spec and key interfaces from org.bouncycastle.pqc.jcajce.* to
org.bouncycastle.jcajce.*. Quarkus 4.0.x manages BouncyCastle 1.86, so
camel-pqc LMS, HSS, XMSS and XMSSMT support fails with NoClassDefFoundError.
When the 1.87 classes are absent, remap the camel-pqc references to the 1.86
equivalents at build time. The members camel-pqc uses are identical in both
locations. The transformer is a no-op on BouncyCastle 1.87 and should be
removed once Quarkus aligns to 1.87.
- Use org.bouncycastle.crypto.params LMS parameters in the test producers,
which exist in both 1.86 and 1.87.
- Test stateful signatures with the camel-pqc default key material, covering
the remapped classes and stateful key index tracking.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../component/pqc/deployment/PqcProcessor.java | 72 ++++++++++++++++++++++
.../quarkus/component/pqc/it/PqcProducers.java | 4 +-
.../quarkus/component/pqc/it/PqcResource.java | 49 +++++++++++++++
.../camel/quarkus/component/pqc/it/PqcTest.java | 55 +++++++++++++++++
4 files changed, 178 insertions(+), 2 deletions(-)
diff --git
a/extensions/pqc/deployment/src/main/java/org/apache/camel/quarkus/component/pqc/deployment/PqcProcessor.java
b/extensions/pqc/deployment/src/main/java/org/apache/camel/quarkus/component/pqc/deployment/PqcProcessor.java
index 3c85c0f9ad2..9ef27b0933a 100644
---
a/extensions/pqc/deployment/src/main/java/org/apache/camel/quarkus/component/pqc/deployment/PqcProcessor.java
+++
b/extensions/pqc/deployment/src/main/java/org/apache/camel/quarkus/component/pqc/deployment/PqcProcessor.java
@@ -16,8 +16,10 @@
*/
package org.apache.camel.quarkus.component.pqc.deployment;
+import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import
io.quarkus.deployment.builditem.nativeimage.NativeImageSecurityProviderBuildItem;
@@ -26,11 +28,19 @@ import
org.apache.camel.quarkus.support.bouncycastle.BouncyCastleRecorder;
import
org.apache.camel.quarkus.support.bouncycastle.deployment.BouncyCastleAdditionalProviderBuildItem;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.commons.ClassRemapper;
+import org.objectweb.asm.commons.Remapper;
class PqcProcessor {
private static final Logger LOG = Logger.getLogger(PqcProcessor.class);
private static final String FEATURE = "camel-pqc";
+ private static final String BC_JCAJCE_PACKAGE = "org/bouncycastle/jcajce/";
+ private static final String LEGACY_BC_PQC_JCAJCE_PACKAGE =
"org/bouncycastle/pqc/jcajce/";
@BuildStep
FeatureBuildItem feature() {
@@ -72,4 +82,66 @@ class PqcProcessor {
return new
BouncyCastleAdditionalProviderBuildItem(BouncyCastleRecorder.BOUNCYCASTLE_PCQ_PROVIDER_NAME);
}
+ /**
+ * Workaround for camel-pqc being compiled against BouncyCastle 1.87 while
the Quarkus platform manages 1.86.
+ * <p>
+ * BouncyCastle 1.87 moved the LMS / XMSS JCA spec and key interfaces from
{@code org.bouncycastle.pqc.jcajce.*} to
+ * {@code org.bouncycastle.jcajce.*}. The members camel-pqc uses are
identical in both locations, so when the new
+ * classes are absent, camel-pqc references are remapped to the 1.86
equivalents.
+ * <p>
+ * TODO: Remove when Quarkus aligns to BouncyCastle 1.87 or newer.
+ */
+ @BuildStep
+ void remapBouncyCastleLmsXmssClasses(
+ CombinedIndexBuildItem combinedIndex,
+ BuildProducer<BytecodeTransformerBuildItem> transformers) {
+
+ if
(QuarkusClassLoader.isClassPresentAtRuntime("org.bouncycastle.jcajce.spec.LMSKeyGenParameterSpec"))
{
+ return;
+ }
+
+ LOG.debugf("BouncyCastle < 1.87 detected. Remapping camel-pqc LMS /
XMSS class references to %s",
+ LEGACY_BC_PQC_JCAJCE_PACKAGE.replace('/', '.'));
+
+ combinedIndex.getIndex().getKnownClasses().stream()
+ .map(ci -> ci.name().toString())
+ .filter(name ->
name.startsWith("org.apache.camel.component.pqc."))
+ .forEach(name -> transformers.produce(new
BytecodeTransformerBuildItem.Builder()
+ .setClassToTransform(name)
+ .setCacheable(true)
+ // A plain class rename does not need frames
recomputing. Avoiding COMPUTE_FRAMES prevents
+ // ASM from loading optional types that may be absent
(E.g. the AWS SDK used by key lifecycle managers)
+ .setInputTransformer((className, bytes) -> {
+ ClassReader reader = new ClassReader(bytes);
+ ClassWriter writer = new ClassWriter(reader, 0);
+ reader.accept(new
LegacyBouncyCastleLmsXmssRemapper(writer), 0);
+ return writer.toByteArray();
+ })
+ .build()));
+ }
+
+ private static final class LegacyBouncyCastleLmsXmssRemapper extends
ClassRemapper {
+ LegacyBouncyCastleLmsXmssRemapper(ClassVisitor cv) {
+ super(Opcodes.ASM9, cv, new Remapper(Opcodes.ASM9) {
+ @Override
+ public String map(String internalName) {
+ if (internalName != null &&
internalName.startsWith(BC_JCAJCE_PACKAGE)) {
+ String suffix =
internalName.substring(BC_JCAJCE_PACKAGE.length());
+ if (isMovedLmsXmssClass(suffix, "spec/") ||
isMovedLmsXmssClass(suffix, "interfaces/")) {
+ return LEGACY_BC_PQC_JCAJCE_PACKAGE + suffix;
+ }
+ }
+ return super.map(internalName);
+ }
+ });
+ }
+
+ private static boolean isMovedLmsXmssClass(String suffix, String
subPackage) {
+ if (!suffix.startsWith(subPackage)) {
+ return false;
+ }
+ String simpleName = suffix.substring(subPackage.length());
+ return simpleName.indexOf('/') == -1 &&
(simpleName.startsWith("LMS") || simpleName.startsWith("XMSS"));
+ }
+ }
}
diff --git
a/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcProducers.java
b/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcProducers.java
index 3b3a83d0f03..fa7b86a6f03 100644
---
a/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcProducers.java
+++
b/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcProducers.java
@@ -22,11 +22,11 @@ import java.security.spec.AlgorithmParameterSpec;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
+import org.bouncycastle.crypto.params.LMOtsParameters;
+import org.bouncycastle.crypto.params.LMSigParameters;
import org.bouncycastle.jcajce.spec.MLDSAParameterSpec;
import org.bouncycastle.jcajce.spec.MLKEMParameterSpec;
import org.bouncycastle.jcajce.spec.SLHDSAParameterSpec;
-import org.bouncycastle.pqc.crypto.lms.LMOtsParameters;
-import org.bouncycastle.pqc.crypto.lms.LMSigParameters;
import org.bouncycastle.pqc.jcajce.spec.FalconParameterSpec;
import org.bouncycastle.pqc.jcajce.spec.LMSParameterSpec;
import org.bouncycastle.pqc.jcajce.spec.XMSSParameterSpec;
diff --git
a/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcResource.java
b/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcResource.java
index 01a4f8b013c..4ff4f4021d3 100644
---
a/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcResource.java
+++
b/integration-tests/pqc/src/main/java/org/apache/camel/quarkus/component/pqc/it/PqcResource.java
@@ -35,6 +35,8 @@ import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.MediaType;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.pqc.PQCConstants;
+import org.apache.camel.component.pqc.stateful.StatefulKeyState;
import org.bouncycastle.jcajce.SecretKeyWithEncapsulation;
import org.jboss.logging.Logger;
@@ -90,6 +92,53 @@ public class PqcResource {
return Boolean.TRUE.equals(verification);
}
+ // Stateful signature tests: no keyPair is configured, so camel-pqc uses
its own default key material
+ @Path("/default/sign/{algorithm}")
+ @POST
+ @Consumes(MediaType.TEXT_PLAIN)
+ @jakarta.ws.rs.Produces(MediaType.TEXT_PLAIN)
+ public String signWithDefaultMaterial(String message,
@PathParam("algorithm") String algorithm) {
+ Exchange exchange = producerTemplate.request(
+ "pqc:sign?operation=sign&signatureAlgorithm=" + algorithm,
+ ex ->
ex.getIn().setBody(message.getBytes(StandardCharsets.UTF_8)));
+
+ byte[] signature =
exchange.getMessage().getHeader(PQCConstants.SIGNATURE, byte[].class);
+ return Base64.getEncoder().encodeToString(signature);
+ }
+
+ @Path("/default/verify/{algorithm}/{message}")
+ @POST
+ @Consumes(MediaType.TEXT_PLAIN)
+ @jakarta.ws.rs.Produces(MediaType.TEXT_PLAIN)
+ public boolean verifyWithDefaultMaterial(String signature,
+ @PathParam("algorithm") String algorithm,
+ @PathParam("message") String message) {
+ Exchange exchange = producerTemplate.request(
+ "pqc:verify?operation=verify&signatureAlgorithm=" + algorithm,
+ ex -> {
+
ex.getIn().setBody(message.getBytes(StandardCharsets.UTF_8));
+ ex.getIn().setHeader(PQCConstants.SIGNATURE,
Base64.getDecoder().decode(signature));
+ });
+
+ return
Boolean.TRUE.equals(exchange.getMessage().getHeader(PQCConstants.VERIFY));
+ }
+
+ @Path("/default/keyState/{algorithm}")
+ @POST
+ @jakarta.ws.rs.Produces(MediaType.APPLICATION_JSON)
+ public Map<String, Object>
keyStateWithDefaultMaterial(@PathParam("algorithm") String algorithm) {
+ Exchange exchange = producerTemplate.request(
+ "pqc:keyState?operation=getKeyState&signatureAlgorithm=" +
algorithm,
+ ex -> {
+ });
+
+ StatefulKeyState state =
exchange.getMessage().getHeader(PQCConstants.KEY_STATE, StatefulKeyState.class);
+ return Map.of(
+ "algorithm", state.getAlgorithm(),
+ "index", state.getIndex(),
+ "usagesRemaining", state.getUsagesRemaining());
+ }
+
@Path("/kem/encapsulate/{algorithm}/{keyAlgorithm}/{length}")
@POST
@jakarta.ws.rs.Produces(MediaType.APPLICATION_JSON)
diff --git
a/integration-tests/pqc/src/test/java/org/apache/camel/quarkus/component/pqc/it/PqcTest.java
b/integration-tests/pqc/src/test/java/org/apache/camel/quarkus/component/pqc/it/PqcTest.java
index 3acece8d4d3..a7e46ac95ec 100644
---
a/integration-tests/pqc/src/test/java/org/apache/camel/quarkus/component/pqc/it/PqcTest.java
+++
b/integration-tests/pqc/src/test/java/org/apache/camel/quarkus/component/pqc/it/PqcTest.java
@@ -66,6 +66,61 @@ class PqcTest {
.body(equalTo("true"));
}
+ @ParameterizedTest
+ @EnumSource(value = PQCSignatureAlgorithms.class, names = { "LMS", "HSS",
"XMSS", "XMSSMT" })
+ public void
testStatefulSignAndVerifyWithDefaultMaterial(PQCSignatureAlgorithms
signatureAlgorithm) {
+ String algorithm = signatureAlgorithm.name();
+
+ Map<String, Object> stateBefore =
getDefaultMaterialKeyState(algorithm);
+
+ String signature = RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body("Hello")
+ .post("/pqc/default/sign/" + algorithm)
+ .then()
+ .statusCode(200)
+ .extract()
+ .asString();
+
+ assertThat(signature).isNotBlank();
+
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body(signature)
+ .post("/pqc/default/verify/" + algorithm + "/Hello")
+ .then()
+ .statusCode(200)
+ .body(equalTo("true"));
+
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body(signature)
+ .post("/pqc/default/verify/" + algorithm + "/Wrong_text")
+ .then()
+ .statusCode(200)
+ .body(equalTo("false"));
+
+ // Signing with a stateful key consumes one one-time signature
+ Map<String, Object> stateAfter = getDefaultMaterialKeyState(algorithm);
+
assertThat(toLong(stateAfter.get("index"))).isEqualTo(toLong(stateBefore.get("index"))
+ 1);
+ assertThat(toLong(stateAfter.get("usagesRemaining")))
+ .isEqualTo(toLong(stateBefore.get("usagesRemaining")) - 1);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Map<String, Object> getDefaultMaterialKeyState(String
algorithm) {
+ return RestAssured.post("/pqc/default/keyState/" + algorithm)
+ .then()
+ .statusCode(200)
+ .body("algorithm", notNullValue())
+ .extract()
+ .as(Map.class);
+ }
+
+ private static long toLong(Object value) {
+ return ((Number) value).longValue();
+ }
+
@Test
public void testNegativeSignAndVerify() {
// Sign operation using Falcon algorithm