This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch CAMEL-21993 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2963cab1748e883f104319066cc96bd53544e9bc Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Apr 23 10:04:30 2025 +0200 CAMEL-21993 - Camel-PQC - Provide default KeyGenerator for KEM operations Signed-off-by: Andrea Cosentino <[email protected]> --- .../apache/camel/component/pqc/PQCComponent.java | 21 +++++ .../PQCDefaultBIKEMaterial.java} | 16 ++-- .../PQCDefaultCMCEMaterial.java} | 16 ++-- .../PQCDefaultFRODOMaterial.java} | 16 ++-- .../PQCDefaultHQCMaterial.java} | 16 ++-- .../crypto/{ => kem}/PQCDefaultMLKEMMaterial.java | 2 +- .../PQCDefaultSABERMaterial.java} | 16 ++-- ...IKEGenerateEncapsulationAESNoAutowiredTest.java | 89 ++++++++++++++++++++++ ...MCEGenerateEncapsulationAESNoAutowiredTest.java | 89 ++++++++++++++++++++++ ...ODOGenerateEncapsulationAESNoAutowiredTest.java | 89 ++++++++++++++++++++++ ...HQCGenerateEncapsulationAESNoAutowiredTest.java | 89 ++++++++++++++++++++++ ...BERGenerateEncapsulationAESNoAutowiredTest.java | 89 ++++++++++++++++++++++ 12 files changed, 507 insertions(+), 41 deletions(-) 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 66c2dc9e710..eca95c19d14 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 @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.component.pqc.crypto.*; +import org.apache.camel.component.pqc.crypto.kem.*; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.HealthCheckComponent; @@ -82,6 +83,26 @@ public class PQCComponent extends HealthCheckComponent { configuration.setKeyGenerator(PQCDefaultMLKEMMaterial.keyGenerator); configuration.setKeyPair(PQCDefaultMLKEMMaterial.keyPair); break; + case "BIKE": + configuration.setKeyGenerator(PQCDefaultBIKEMaterial.keyGenerator); + configuration.setKeyPair(PQCDefaultBIKEMaterial.keyPair); + break; + case "HQC": + configuration.setKeyGenerator(PQCDefaultHQCMaterial.keyGenerator); + configuration.setKeyPair(PQCDefaultHQCMaterial.keyPair); + break; + case "CMCE": + configuration.setKeyGenerator(PQCDefaultCMCEMaterial.keyGenerator); + configuration.setKeyPair(PQCDefaultCMCEMaterial.keyPair); + break; + case "SABER": + configuration.setKeyGenerator(PQCDefaultSABERMaterial.keyGenerator); + configuration.setKeyPair(PQCDefaultSABERMaterial.keyPair); + break; + case "FRODO": + configuration.setKeyGenerator(PQCDefaultFRODOMaterial.keyGenerator); + configuration.setKeyPair(PQCDefaultFRODOMaterial.keyPair); + break; default: break; } diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultBIKEMaterial.java similarity index 80% copy from components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java copy to components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultBIKEMaterial.java index f4a30af33e0..30402200646 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultBIKEMaterial.java @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.pqc.crypto; +package org.apache.camel.component.pqc.crypto.kem; import java.security.*; import javax.crypto.KeyGenerator; import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms; -import org.bouncycastle.jcajce.spec.MLKEMParameterSpec; +import org.bouncycastle.pqc.jcajce.spec.BIKEParameterSpec; -public class PQCDefaultMLKEMMaterial { +public class PQCDefaultBIKEMaterial { public static final KeyPair keyPair; public static final KeyGenerator keyGenerator; @@ -41,15 +41,15 @@ public class PQCDefaultMLKEMMaterial { protected static KeyPairGenerator prepareKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); - kpg.initialize(MLKEMParameterSpec.ml_kem_512, new SecureRandom()); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.BIKE.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.BIKE.getBcProvider()); + kpg.initialize(BIKEParameterSpec.bike192, new SecureRandom()); return kpg; } protected static KeyGenerator prepareKeyGenerator() throws NoSuchAlgorithmException, NoSuchProviderException { - KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); + KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.BIKE.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.BIKE.getBcProvider()); return kg; } } diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultCMCEMaterial.java similarity index 79% copy from components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java copy to components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultCMCEMaterial.java index f4a30af33e0..b42b88ece7c 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultCMCEMaterial.java @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.pqc.crypto; +package org.apache.camel.component.pqc.crypto.kem; import java.security.*; import javax.crypto.KeyGenerator; import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms; -import org.bouncycastle.jcajce.spec.MLKEMParameterSpec; +import org.bouncycastle.pqc.jcajce.spec.CMCEParameterSpec; -public class PQCDefaultMLKEMMaterial { +public class PQCDefaultCMCEMaterial { public static final KeyPair keyPair; public static final KeyGenerator keyGenerator; @@ -41,15 +41,15 @@ public class PQCDefaultMLKEMMaterial { protected static KeyPairGenerator prepareKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); - kpg.initialize(MLKEMParameterSpec.ml_kem_512, new SecureRandom()); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.CMCE.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.CMCE.getBcProvider()); + kpg.initialize(CMCEParameterSpec.mceliece8192128f, new SecureRandom()); return kpg; } protected static KeyGenerator prepareKeyGenerator() throws NoSuchAlgorithmException, NoSuchProviderException { - KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); + KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.CMCE.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.CMCE.getBcProvider()); return kg; } } diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultFRODOMaterial.java similarity index 80% copy from components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java copy to components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultFRODOMaterial.java index f4a30af33e0..f0f76f40914 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultFRODOMaterial.java @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.pqc.crypto; +package org.apache.camel.component.pqc.crypto.kem; import java.security.*; import javax.crypto.KeyGenerator; import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms; -import org.bouncycastle.jcajce.spec.MLKEMParameterSpec; +import org.bouncycastle.pqc.jcajce.spec.FrodoParameterSpec; -public class PQCDefaultMLKEMMaterial { +public class PQCDefaultFRODOMaterial { public static final KeyPair keyPair; public static final KeyGenerator keyGenerator; @@ -41,15 +41,15 @@ public class PQCDefaultMLKEMMaterial { protected static KeyPairGenerator prepareKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); - kpg.initialize(MLKEMParameterSpec.ml_kem_512, new SecureRandom()); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.FRODO.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.FRODO.getBcProvider()); + kpg.initialize(FrodoParameterSpec.frodokem976aes, new SecureRandom()); return kpg; } protected static KeyGenerator prepareKeyGenerator() throws NoSuchAlgorithmException, NoSuchProviderException { - KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); + KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.FRODO.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.FRODO.getBcProvider()); return kg; } } diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultHQCMaterial.java similarity index 80% copy from components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java copy to components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultHQCMaterial.java index f4a30af33e0..fcc81dbd40c 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultHQCMaterial.java @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.pqc.crypto; +package org.apache.camel.component.pqc.crypto.kem; import java.security.*; import javax.crypto.KeyGenerator; import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms; -import org.bouncycastle.jcajce.spec.MLKEMParameterSpec; +import org.bouncycastle.pqc.jcajce.spec.HQCParameterSpec; -public class PQCDefaultMLKEMMaterial { +public class PQCDefaultHQCMaterial { public static final KeyPair keyPair; public static final KeyGenerator keyGenerator; @@ -41,15 +41,15 @@ public class PQCDefaultMLKEMMaterial { protected static KeyPairGenerator prepareKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); - kpg.initialize(MLKEMParameterSpec.ml_kem_512, new SecureRandom()); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.HQC.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.HQC.getBcProvider()); + kpg.initialize(HQCParameterSpec.hqc192, new SecureRandom()); return kpg; } protected static KeyGenerator prepareKeyGenerator() throws NoSuchAlgorithmException, NoSuchProviderException { - KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); + KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.HQC.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.HQC.getBcProvider()); return kg; } } diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultMLKEMMaterial.java similarity index 97% copy from components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java copy to components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultMLKEMMaterial.java index f4a30af33e0..a79fb075e8b 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultMLKEMMaterial.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.pqc.crypto; +package org.apache.camel.component.pqc.crypto.kem; import java.security.*; diff --git a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultSABERMaterial.java similarity index 80% rename from components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java rename to components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultSABERMaterial.java index f4a30af33e0..b6dfe5d2f9b 100644 --- a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/PQCDefaultMLKEMMaterial.java +++ b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/crypto/kem/PQCDefaultSABERMaterial.java @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.pqc.crypto; +package org.apache.camel.component.pqc.crypto.kem; import java.security.*; import javax.crypto.KeyGenerator; import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms; -import org.bouncycastle.jcajce.spec.MLKEMParameterSpec; +import org.bouncycastle.pqc.jcajce.spec.SABERParameterSpec; -public class PQCDefaultMLKEMMaterial { +public class PQCDefaultSABERMaterial { public static final KeyPair keyPair; public static final KeyGenerator keyGenerator; @@ -41,15 +41,15 @@ public class PQCDefaultMLKEMMaterial { protected static KeyPairGenerator prepareKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); - kpg.initialize(MLKEMParameterSpec.ml_kem_512, new SecureRandom()); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(PQCKeyEncapsulationAlgorithms.SABER.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.SABER.getBcProvider()); + kpg.initialize(SABERParameterSpec.lightsaberkem256r3, new SecureRandom()); return kpg; } protected static KeyGenerator prepareKeyGenerator() throws NoSuchAlgorithmException, NoSuchProviderException { - KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(), - PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider()); + KeyGenerator kg = KeyGenerator.getInstance(PQCKeyEncapsulationAlgorithms.SABER.getAlgorithm(), + PQCKeyEncapsulationAlgorithms.SABER.getBcProvider()); return kg; } } diff --git a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCBIKEGenerateEncapsulationAESNoAutowiredTest.java b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCBIKEGenerateEncapsulationAESNoAutowiredTest.java new file mode 100644 index 00000000000..25f4501191d --- /dev/null +++ b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCBIKEGenerateEncapsulationAESNoAutowiredTest.java @@ -0,0 +1,89 @@ +/* + * 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.NoSuchAlgorithmException; +import java.security.Security; + +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.jcajce.SecretKeyWithEncapsulation; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PQCBIKEGenerateEncapsulationAESNoAutowiredTest extends CamelTestSupport { + + @EndpointInject("mock:encapsulate") + protected MockEndpoint resultEncapsulate; + + @Produce("direct:encapsulate") + protected ProducerTemplate templateEncapsulate; + + @EndpointInject("mock:extract") + protected MockEndpoint resultExtract; + + public PQCBIKEGenerateEncapsulationAESNoAutowiredTest() throws NoSuchAlgorithmException { + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:encapsulate").to( + "pqc:keyenc?operation=generateSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=BIKE") + .to("mock:encapsulate") + .to("pqc:keyenc?operation=extractSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=BIKE") + .to("mock:extract"); + } + }; + } + + @BeforeAll + public static void startup() throws Exception { + Security.addProvider(new BouncyCastleProvider()); + Security.addProvider(new BouncyCastlePQCProvider()); + } + + @Test + void testSignAndVerify() throws Exception { + resultEncapsulate.expectedMessageCount(1); + resultExtract.expectedMessageCount(1); + templateEncapsulate.sendBody("Hello"); + resultEncapsulate.assertIsSatisfied(); + assertNotNull(resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncrypted + = resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertNotNull(resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncryptedExtracted + = resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertTrue(Arrays.areEqual(secEncrypted.getEncoded(), secEncryptedExtracted.getEncoded())); + } +} diff --git a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCCMCEGenerateEncapsulationAESNoAutowiredTest.java b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCCMCEGenerateEncapsulationAESNoAutowiredTest.java new file mode 100644 index 00000000000..546b0dbc4ca --- /dev/null +++ b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCCMCEGenerateEncapsulationAESNoAutowiredTest.java @@ -0,0 +1,89 @@ +/* + * 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.NoSuchAlgorithmException; +import java.security.Security; + +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.jcajce.SecretKeyWithEncapsulation; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PQCCMCEGenerateEncapsulationAESNoAutowiredTest extends CamelTestSupport { + + @EndpointInject("mock:encapsulate") + protected MockEndpoint resultEncapsulate; + + @Produce("direct:encapsulate") + protected ProducerTemplate templateEncapsulate; + + @EndpointInject("mock:extract") + protected MockEndpoint resultExtract; + + public PQCCMCEGenerateEncapsulationAESNoAutowiredTest() throws NoSuchAlgorithmException { + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:encapsulate").to( + "pqc:keyenc?operation=generateSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=CMCE") + .to("mock:encapsulate") + .to("pqc:keyenc?operation=extractSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=CMCE") + .to("mock:extract"); + } + }; + } + + @BeforeAll + public static void startup() throws Exception { + Security.addProvider(new BouncyCastleProvider()); + Security.addProvider(new BouncyCastlePQCProvider()); + } + + @Test + void testSignAndVerify() throws Exception { + resultEncapsulate.expectedMessageCount(1); + resultExtract.expectedMessageCount(1); + templateEncapsulate.sendBody("Hello"); + resultEncapsulate.assertIsSatisfied(); + assertNotNull(resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncrypted + = resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertNotNull(resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncryptedExtracted + = resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertTrue(Arrays.areEqual(secEncrypted.getEncoded(), secEncryptedExtracted.getEncoded())); + } +} diff --git a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCFRODOGenerateEncapsulationAESNoAutowiredTest.java b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCFRODOGenerateEncapsulationAESNoAutowiredTest.java new file mode 100644 index 00000000000..936cbad8508 --- /dev/null +++ b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCFRODOGenerateEncapsulationAESNoAutowiredTest.java @@ -0,0 +1,89 @@ +/* + * 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.NoSuchAlgorithmException; +import java.security.Security; + +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.jcajce.SecretKeyWithEncapsulation; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PQCFRODOGenerateEncapsulationAESNoAutowiredTest extends CamelTestSupport { + + @EndpointInject("mock:encapsulate") + protected MockEndpoint resultEncapsulate; + + @Produce("direct:encapsulate") + protected ProducerTemplate templateEncapsulate; + + @EndpointInject("mock:extract") + protected MockEndpoint resultExtract; + + public PQCFRODOGenerateEncapsulationAESNoAutowiredTest() throws NoSuchAlgorithmException { + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:encapsulate").to( + "pqc:keyenc?operation=generateSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=FRODO") + .to("mock:encapsulate") + .to("pqc:keyenc?operation=extractSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=FRODO") + .to("mock:extract"); + } + }; + } + + @BeforeAll + public static void startup() throws Exception { + Security.addProvider(new BouncyCastleProvider()); + Security.addProvider(new BouncyCastlePQCProvider()); + } + + @Test + void testSignAndVerify() throws Exception { + resultEncapsulate.expectedMessageCount(1); + resultExtract.expectedMessageCount(1); + templateEncapsulate.sendBody("Hello"); + resultEncapsulate.assertIsSatisfied(); + assertNotNull(resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncrypted + = resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertNotNull(resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncryptedExtracted + = resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertTrue(Arrays.areEqual(secEncrypted.getEncoded(), secEncryptedExtracted.getEncoded())); + } +} diff --git a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCHQCGenerateEncapsulationAESNoAutowiredTest.java b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCHQCGenerateEncapsulationAESNoAutowiredTest.java new file mode 100644 index 00000000000..835ca926f29 --- /dev/null +++ b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCHQCGenerateEncapsulationAESNoAutowiredTest.java @@ -0,0 +1,89 @@ +/* + * 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.NoSuchAlgorithmException; +import java.security.Security; + +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.jcajce.SecretKeyWithEncapsulation; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PQCHQCGenerateEncapsulationAESNoAutowiredTest extends CamelTestSupport { + + @EndpointInject("mock:encapsulate") + protected MockEndpoint resultEncapsulate; + + @Produce("direct:encapsulate") + protected ProducerTemplate templateEncapsulate; + + @EndpointInject("mock:extract") + protected MockEndpoint resultExtract; + + public PQCHQCGenerateEncapsulationAESNoAutowiredTest() throws NoSuchAlgorithmException { + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:encapsulate").to( + "pqc:keyenc?operation=generateSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=HQC") + .to("mock:encapsulate") + .to("pqc:keyenc?operation=extractSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=HQC") + .to("mock:extract"); + } + }; + } + + @BeforeAll + public static void startup() throws Exception { + Security.addProvider(new BouncyCastleProvider()); + Security.addProvider(new BouncyCastlePQCProvider()); + } + + @Test + void testSignAndVerify() throws Exception { + resultEncapsulate.expectedMessageCount(1); + resultExtract.expectedMessageCount(1); + templateEncapsulate.sendBody("Hello"); + resultEncapsulate.assertIsSatisfied(); + assertNotNull(resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncrypted + = resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertNotNull(resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncryptedExtracted + = resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertTrue(Arrays.areEqual(secEncrypted.getEncoded(), secEncryptedExtracted.getEncoded())); + } +} diff --git a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCSABERGenerateEncapsulationAESNoAutowiredTest.java b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCSABERGenerateEncapsulationAESNoAutowiredTest.java new file mode 100644 index 00000000000..a10da24b9ae --- /dev/null +++ b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCSABERGenerateEncapsulationAESNoAutowiredTest.java @@ -0,0 +1,89 @@ +/* + * 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.NoSuchAlgorithmException; +import java.security.Security; + +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.jcajce.SecretKeyWithEncapsulation; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.bouncycastle.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PQCSABERGenerateEncapsulationAESNoAutowiredTest extends CamelTestSupport { + + @EndpointInject("mock:encapsulate") + protected MockEndpoint resultEncapsulate; + + @Produce("direct:encapsulate") + protected ProducerTemplate templateEncapsulate; + + @EndpointInject("mock:extract") + protected MockEndpoint resultExtract; + + public PQCSABERGenerateEncapsulationAESNoAutowiredTest() throws NoSuchAlgorithmException { + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:encapsulate").to( + "pqc:keyenc?operation=generateSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=SABER") + .to("mock:encapsulate") + .to("pqc:keyenc?operation=extractSecretKeyEncapsulation&symmetricKeyAlgorithm=AES&keyEncapsulationAlgorithm=SABER") + .to("mock:extract"); + } + }; + } + + @BeforeAll + public static void startup() throws Exception { + Security.addProvider(new BouncyCastleProvider()); + Security.addProvider(new BouncyCastlePQCProvider()); + } + + @Test + void testSignAndVerify() throws Exception { + resultEncapsulate.expectedMessageCount(1); + resultExtract.expectedMessageCount(1); + templateEncapsulate.sendBody("Hello"); + resultEncapsulate.assertIsSatisfied(); + assertNotNull(resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncrypted + = resultEncapsulate.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertNotNull(resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class)); + assertEquals(PQCSymmetricAlgorithms.AES.getAlgorithm(), + resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class).getAlgorithm()); + SecretKeyWithEncapsulation secEncryptedExtracted + = resultExtract.getExchanges().get(0).getMessage().getBody(SecretKeyWithEncapsulation.class); + assertTrue(Arrays.areEqual(secEncrypted.getEncoded(), secEncryptedExtracted.getEncoded())); + } +}
