This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch CAMEL-22230-part-1 in repository https://gitbox.apache.org/repos/asf/camel.git
commit bca337921dfc79ef23d3398ec118eb507f1bb0be Author: Andrea Cosentino <[email protected]> AuthorDate: Thu Jul 10 14:43:54 2025 +0200 CAMEL-22230 - Camel-PQC: Support more signature and KEM algorithms - MAYO Signature Algorithm Signed-off-by: Andrea Cosentino <[email protected]> --- .../org/apache/camel/catalog/components/pqc.json | 4 +- .../org/apache/camel/component/pqc/pqc.json | 4 +- .../apache/camel/component/pqc/PQCComponent.java | 4 + .../camel/component/pqc/PQCConfiguration.java | 2 +- .../component/pqc/PQCSignatureAlgorithms.java | 3 +- .../pqc/crypto/PQCDefaultMAYOMaterial.java | 54 +++++++++++++ .../camel/component/pqc/PQCSignatureMAYOTest.java | 91 ++++++++++++++++++++++ 7 files changed, 156 insertions(+), 6 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pqc.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pqc.json index 13ceb0e4a1e..9f26fc38eee 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pqc.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pqc.json @@ -34,7 +34,7 @@ "keyPairAlias": { "index": 7, "kind": "property", "displayName": "Key Pair Alias", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyPair alias to use in combination with KeyStore parameter" }, "keyStore": { "index": 8, "kind": "property", "displayName": "Key Store", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.KeyStore", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyStore where we could get Cryptographic material" }, "keyStorePassword": { "index": 9, "kind": "property", "displayName": "Key Store Password", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The KeyStore password to use in combination with KeyStore Parameter" }, - "signatureAlgorithm": { "index": 10, "kind": "property", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "de [...] + "signatureAlgorithm": { "index": 10, "kind": "property", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA", "MAYO" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configurati [...] "signer": { "index": 11, "kind": "property", "displayName": "Signer", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.Signature", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The Signer to be used" }, "storeExtractedSecretKeyAsHeader": { "index": 12, "kind": "property", "displayName": "Store Extracted Secret Key As Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "In the context of extractSec [...] "symmetricKeyAlgorithm": { "index": 13, "kind": "property", "displayName": "Symmetric Key Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "AES", "ARIA", "RC2", "RC5", "CAMELLIA", "CAST5", "CAST6", "CHACHA7539", "DSTU7624", "GOST28147", "GOST3412_2015", "GRAIN128", "HC128", "HC256", "SALSA20", "SEED", "SM4", "DESEDE" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, " [...] @@ -58,7 +58,7 @@ "keyPairAlias": { "index": 6, "kind": "parameter", "displayName": "Key Pair Alias", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyPair alias to use in combination with KeyStore parameter" }, "keyStore": { "index": 7, "kind": "parameter", "displayName": "Key Store", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.KeyStore", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyStore where we could get Cryptographic material" }, "keyStorePassword": { "index": 8, "kind": "parameter", "displayName": "Key Store Password", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The KeyStore password to use in combination with KeyStore Parameter" }, - "signatureAlgorithm": { "index": 9, "kind": "parameter", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "de [...] + "signatureAlgorithm": { "index": 9, "kind": "parameter", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA", "MAYO" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configurati [...] "signer": { "index": 10, "kind": "parameter", "displayName": "Signer", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.Signature", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The Signer to be used" }, "storeExtractedSecretKeyAsHeader": { "index": 11, "kind": "parameter", "displayName": "Store Extracted Secret Key As Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "In the context of extractSe [...] "symmetricKeyAlgorithm": { "index": 12, "kind": "parameter", "displayName": "Symmetric Key Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "AES", "ARIA", "RC2", "RC5", "CAMELLIA", "CAST5", "CAST6", "CHACHA7539", "DSTU7624", "GOST28147", "GOST3412_2015", "GRAIN128", "HC128", "HC256", "SALSA20", "SEED", "SM4", "DESEDE" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, [...] diff --git a/components/camel-pqc/src/generated/resources/META-INF/org/apache/camel/component/pqc/pqc.json b/components/camel-pqc/src/generated/resources/META-INF/org/apache/camel/component/pqc/pqc.json index 13ceb0e4a1e..9f26fc38eee 100644 --- a/components/camel-pqc/src/generated/resources/META-INF/org/apache/camel/component/pqc/pqc.json +++ b/components/camel-pqc/src/generated/resources/META-INF/org/apache/camel/component/pqc/pqc.json @@ -34,7 +34,7 @@ "keyPairAlias": { "index": 7, "kind": "property", "displayName": "Key Pair Alias", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyPair alias to use in combination with KeyStore parameter" }, "keyStore": { "index": 8, "kind": "property", "displayName": "Key Store", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.KeyStore", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyStore where we could get Cryptographic material" }, "keyStorePassword": { "index": 9, "kind": "property", "displayName": "Key Store Password", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The KeyStore password to use in combination with KeyStore Parameter" }, - "signatureAlgorithm": { "index": 10, "kind": "property", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "de [...] + "signatureAlgorithm": { "index": 10, "kind": "property", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA", "MAYO" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configurati [...] "signer": { "index": 11, "kind": "property", "displayName": "Signer", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.Signature", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The Signer to be used" }, "storeExtractedSecretKeyAsHeader": { "index": 12, "kind": "property", "displayName": "Store Extracted Secret Key As Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "In the context of extractSec [...] "symmetricKeyAlgorithm": { "index": 13, "kind": "property", "displayName": "Symmetric Key Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "AES", "ARIA", "RC2", "RC5", "CAMELLIA", "CAST5", "CAST6", "CHACHA7539", "DSTU7624", "GOST28147", "GOST3412_2015", "GRAIN128", "HC128", "HC256", "SALSA20", "SEED", "SM4", "DESEDE" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, " [...] @@ -58,7 +58,7 @@ "keyPairAlias": { "index": 6, "kind": "parameter", "displayName": "Key Pair Alias", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyPair alias to use in combination with KeyStore parameter" }, "keyStore": { "index": 7, "kind": "parameter", "displayName": "Key Store", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.KeyStore", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "A KeyStore where we could get Cryptographic material" }, "keyStorePassword": { "index": 8, "kind": "parameter", "displayName": "Key Store Password", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The KeyStore password to use in combination with KeyStore Parameter" }, - "signatureAlgorithm": { "index": 9, "kind": "parameter", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "de [...] + "signatureAlgorithm": { "index": 9, "kind": "parameter", "displayName": "Signature Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "MLDSA", "SLHDSA", "LMS", "XMSS", "FALCON", "PICNIC", "RAINBOW", "SNOVA", "MAYO" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configurati [...] "signer": { "index": 10, "kind": "parameter", "displayName": "Signer", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.security.Signature", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "The Signer to be used" }, "storeExtractedSecretKeyAsHeader": { "index": 11, "kind": "parameter", "displayName": "Store Extracted Secret Key As Header", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.pqc.PQCConfiguration", "configurationField": "configuration", "description": "In the context of extractSe [...] "symmetricKeyAlgorithm": { "index": 12, "kind": "parameter", "displayName": "Symmetric Key Algorithm", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "AES", "ARIA", "RC2", "RC5", "CAMELLIA", "CAST5", "CAST6", "CHACHA7539", "DSTU7624", "GOST28147", "GOST3412_2015", "GRAIN128", "HC128", "HC256", "SALSA20", "SEED", "SM4", "DESEDE" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, [...] diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCComponent.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCComponent.java index 23b9e2c5bc0..2a719b50267 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCComponent.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCComponent.java @@ -90,6 +90,10 @@ public class PQCComponent extends HealthCheckComponent { configuration.setSigner(PQCDefaultSNOVAMaterial.signer); configuration.setKeyPair(PQCDefaultSNOVAMaterial.keyPair); break; + case "MAYO": + configuration.setSigner(PQCDefaultMAYOMaterial.signer); + configuration.setKeyPair(PQCDefaultMAYOMaterial.keyPair); + break; default: break; } diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCConfiguration.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCConfiguration.java index e7505304766..e1dd363bdad 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCConfiguration.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCConfiguration.java @@ -43,7 +43,7 @@ public class PQCConfiguration implements Cloneable { @UriParam @Metadata(label = "advanced", autowired = true) private Signature signer; - @UriParam(enums = "MLDSA,SLHDSA,LMS,XMSS,FALCON,PICNIC,RAINBOW,SNOVA") + @UriParam(enums = "MLDSA,SLHDSA,LMS,XMSS,FALCON,PICNIC,RAINBOW,SNOVA,MAYO") @Metadata(label = "advanced") private String signatureAlgorithm; @UriParam diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCSignatureAlgorithms.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCSignatureAlgorithms.java index 9a09da62d78..6785b433652 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCSignatureAlgorithms.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCSignatureAlgorithms.java @@ -27,7 +27,8 @@ public enum PQCSignatureAlgorithms { // Experimental and non-standardized FALCON("FALCON", "BCPQC"), PICNIC("PICNIC", "BCPQC"), - SNOVA("Snova", "BCPQC"); + SNOVA("Snova", "BCPQC"), + MAYO("Mayo", "BCPQC"); private final String algorithm; private final String bcProvider; diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMAYOMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMAYOMaterial.java new file mode 100644 index 00000000000..b746d50e4fd --- /dev/null +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMAYOMaterial.java @@ -0,0 +1,54 @@ +/* + * 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; + +import java.security.*; + +import org.apache.camel.component.pqc.PQCSignatureAlgorithms; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.pqc.jcajce.spec.MayoParameterSpec; + +public class PQCDefaultMAYOMaterial { + public static final KeyPair keyPair; + public static final Signature signer; + + static { + if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { + Security.addProvider(new BouncyCastleProvider()); + } + if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) == null) { + Security.addProvider(new BouncyCastlePQCProvider()); + } + KeyPairGenerator generator; + try { + generator = prepareKeyPair(); + keyPair = generator.generateKeyPair(); + signer = Signature.getInstance(PQCSignatureAlgorithms.MAYO.getAlgorithm()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static KeyPairGenerator prepareKeyPair() + throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { + KeyPairGenerator kpGen = KeyPairGenerator.getInstance(PQCSignatureAlgorithms.MAYO.getAlgorithm(), + PQCSignatureAlgorithms.MAYO.getBcProvider()); + kpGen.initialize(MayoParameterSpec.mayo5); + return kpGen; + } +} diff --git a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCSignatureMAYOTest.java b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCSignatureMAYOTest.java new file mode 100644 index 00000000000..a1d066c01c0 --- /dev/null +++ b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCSignatureMAYOTest.java @@ -0,0 +1,91 @@ +/* + * 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.*; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.EndpointInject; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.pqc.jcajce.spec.MayoParameterSpec; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PQCSignatureMAYOTest extends CamelTestSupport { + + @EndpointInject("mock:sign") + protected MockEndpoint resultSign; + + @EndpointInject("mock:verify") + protected MockEndpoint resultVerify; + + @Produce("direct:sign") + protected ProducerTemplate templateSign; + + public PQCSignatureMAYOTest() throws NoSuchAlgorithmException { + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:sign").to("pqc:sign?operation=sign").to("mock:sign").to("pqc:verify?operation=verify") + .to("mock:verify"); + } + }; + } + + @BeforeAll + public static void startup() throws Exception { + Security.addProvider(new BouncyCastleProvider()); + Security.addProvider(new BouncyCastlePQCProvider()); + } + + @Test + void testSignAndVerify() throws Exception { + resultSign.expectedMessageCount(1); + resultVerify.expectedMessageCount(1); + templateSign.sendBody("Hello"); + resultSign.assertIsSatisfied(); + resultVerify.assertIsSatisfied(); + assertTrue(resultVerify.getExchanges().get(0).getMessage().getHeader(PQCConstants.VERIFY, Boolean.class)); + } + + @BindToRegistry("Keypair") + public KeyPair setKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { + KeyPairGenerator kpGen = KeyPairGenerator.getInstance(PQCSignatureAlgorithms.MAYO.getAlgorithm(), + PQCSignatureAlgorithms.MAYO.getBcProvider()); + kpGen.initialize(MayoParameterSpec.mayo5); + KeyPair kp = kpGen.generateKeyPair(); + return kp; + } + + @BindToRegistry("Signer") + public Signature getSigner() throws NoSuchAlgorithmException { + Signature mlDsa = Signature.getInstance(PQCSignatureAlgorithms.MAYO.getAlgorithm()); + return mlDsa; + } +}
