diff --git a/docs/modules/ROOT/attachments/examples.json b/docs/modules/ROOT/attachments/examples.json index c69639f1..8d688d02 100644 --- a/docs/modules/ROOT/attachments/examples.json +++ b/docs/modules/ROOT/attachments/examples.json @@ -49,6 +49,11 @@ "description": "Shows how to implement quantum-resistant authentication using hybrid certificates that combine RSA with post-quantum ML-DSA-65 signatures on Java 17 using application-level validation", "link": "https://github.com/apache/camel-quarkus-examples/tree/main/http-pqc-j17" }, + { + "title": "HTTP with Post-Quantum Cryptography (PQC) (Java 21)", + "description": "Shows how to implement quantum-resistant TLS using Java 21 with BouncyCastle JSSE provider for native PQC support with hybrid cipher suites", + "link": "https://github.com/apache/camel-quarkus-examples/tree/main/http-pqc-j21" + }, { "title": "HTTP with vanilla JAX-RS or with Camel `platform-http` component", "description": "Shows how to create HTTP endpoints using either the RESTEasy", diff --git a/http-pqc-j21/README.adoc b/http-pqc-j21/README.adoc new file mode 100644 index 00000000..a2c879cf --- /dev/null +++ b/http-pqc-j21/README.adoc @@ -0,0 +1,288 @@ += HTTP with Post-Quantum Cryptography (PQC): A Camel Quarkus example (Java 21) +:cq-example-description: An example that shows how to implement quantum-resistant TLS using Java 21 with BouncyCastle JSSE provider for native PQC support with hybrid cipher suites + +{cq-description} + +This example shows how to implement quantum-resistant TLS on **Java 21** using hybrid cipher suites that combine classical ECDH with post-quantum ML-KEM-768 key exchange (X25519MLKEM768). The TLS stack natively negotiates and uses PQC algorithms. + +NOTE: CI runs with jdk17, therefore CI on this example is disabled (via profile)! + +IMPORTANT: This example uses **native PQC TLS support** via BouncyCastle JSSE provider. Java 21 supports PQC hybrid cipher suites at the TLS protocol level. For Java 17, see the http-pqc-j17 example which uses application-level validation. + +TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites and other general information. + +== What is Post-Quantum Cryptography? + +Post-Quantum Cryptography (PQC) protects against "harvest now, decrypt later" attacks where adversaries capture encrypted data today to decrypt when quantum computers become available. + +=== Java 21 Approach + +**Java 21 supports PQC algorithms natively in TLS** when using BouncyCastle JSSE provider. This example demonstrates: + +* **Hybrid cipher suites**: X25519MLKEM768 combines classical X25519 ECDH with quantum-resistant ML-KEM-768 (NIST FIPS 203) +* **TLS-level key exchange**: PQC negotiation happens at the TLS protocol layer, not application level +* **BouncyCastle JSSE provider**: Replaces SunJSSE to enable PQC cipher suites in TLS 1.3 +* **Configurable fallback**: Can configure classical fallback algorithms for backward compatibility + +This approach provides true PQC support at the TLS protocol level, unlike Java 17's application-level validation workaround. + +== Certificate Generation + +Certificates are automatically generated during application startup in `target/certs/`: + +* `server-keystore.p12` - Server certificate with RSA 4096-bit keys +* `server-truststore.p12` - Truststore for validating clients +* `client-keystore.p12` - Client certificate for testing +* `client-truststore.p12` - Client truststore for server validation + +NOTE: Certificates use traditional RSA signatures. The PQC protection comes from the hybrid key exchange (X25519MLKEM768) negotiated during the TLS handshake, not from the certificate signatures. + +== Prerequisites + +* **Java 21** or higher (required for X25519MLKEM768 support) +* Maven 3.8.1 or later +* GraalVM (for native mode only) + +== Start in Development Mode + +[source,shell] +---- +$ mvn clean compile quarkus:dev +---- + +The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your workspace. Any modifications in your project will automatically take effect in the running application. + +TIP: Please refer to the Development mode section of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_development_mode[Camel Quarkus User guide] for more details. + +The application starts on a random HTTPS port with mutual TLS (mTLS) enabled. All endpoints require a valid client certificate. + +Main endpoint: + +* `/pqc/secure` - Requires client certificate, uses X25519MLKEM768 hybrid key exchange + +The actual port is displayed in the startup logs. Look for: +[source] +---- +Listening on: https://0.0.0.0:xxxxx +---- + +NOTE: The server is configured with `jdk.tls.namedGroups=X25519MLKEM768,x25519,secp256r1 by default, which means both PQC-capable clients and not-PQC-capable clients can connect. + +=== Manual Testing with Client Certificates + +IMPORTANT: Standard tools like `curl`, `wget`, and `openssl s_client` do **not** support X25519MLKEM768 hybrid key exchange. + +==== Option 1: Configure Server with Fallback (Recommended for Manual Testing) + +`application.properties` is configured by default to enable classical fallback: + +[source,properties] +---- +jdk.tls.namedGroups=X25519MLKEM768,x25519,secp256r1 +---- + +PKCS12 keystores are automatically generated during test execution in `target/certs/`: + +* `client-keystore.p12` - Client certificate (password: `changeit`) + +Start the application with fallback configuration and test with curl: + +[source,shell] +---- +$ mvn quarkus:dev + +# In another terminal +$ curl --cert target/certs/client-keystore.p12:changeit \ + --cert-type P12 \ + -k \ + https://localhost:xxxxx/pqc/secure + +{"message":"Serving secure data via PQC-enabled TLS connection"} +---- + +NOTE: With fallback enabled, curl will use classical x25519 or secp256r1 key exchange since it doesn't support X25519MLKEM768. The connection is secure but not quantum-resistant. + +==== Option 2: Test with PQC-Capable Client (PQC Protection) + +Configure `application.properties` to disable classical fallback: + +[source,properties] +---- +jdk.tls.namedGroups=X25519MLKEM768 +---- + +To actually test X25519MLKEM768 hybrid key exchange, use a PQC-capable client. The test suite demonstrates this using Apache HttpClient 5 with BouncyCastle JSSE: + +[source,shell] +---- +# Run the test that proves PQC is working +$ mvn test -Dtest=PqcOnlyTest#testHttpClientWithBCJSSE +---- + +This test uses BouncyCastle JSSE provider which supports X25519MLKEM768, proving the server requires PQC when configured with `jdk.tls.namedGroups=X25519MLKEM768`. + +== Package and Run the Application + +Once you are done with developing you may want to package and run the application. + +TIP: Find more details about the JVM mode and Native mode in the Package and run section of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel Quarkus User guide] + +=== JVM Mode + +[source,shell] +---- +$ mvn clean package +$ java -jar target/quarkus-app/quarkus-run.jar +... +[io.quarkus] (main) camel-quarkus-examples-http-pqc-j21 started in ?.?s. Listening on: https://0.0.0.0:xxxxx +---- + +=== Native Mode + +IMPORTANT: Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel Quarkus User guide]. + +To prepare a native executable using GraalVM, run the following command: + +[source,shell] +---- +$ mvn clean package -Dnative +$ ./target/*-runner +... +[io.quarkus] (main) camel-quarkus-examples-http-pqc-j21 started in ?.?s. Listening on: https://0.0.0.0:xxxxx +... +---- + +== Testing + +Run the tests to verify PQC functionality: + +[source,shell] +---- +$ mvn clean test +---- + +The test suite validates: + +* **PqcOnlyTest**: Proves X25519MLKEM768 is enforced + - BCJSSE client ✓ succeeds (supports X25519MLKEM768) + - SunJSSE client ✗ fails (no PQC support) + - This proves the server requires PQC with no classical fallback + +* **PqcWithFallbackTest**: Demonstrates backward compatibility + - BCJSSE client ✓ succeeds (uses X25519MLKEM768) + - SunJSSE client ✓ succeeds (falls back to secp256r1) + - This proves gradual migration is possible + +Run individual tests: + +[source,shell] +---- +# Test PQC enforcement +$ mvn clean test -Dtest=PqcOnlyTest + +# Test backward compatibility +$ mvn clean test -Dtest=PqcWithFallbackTest + +# Test specific scenario +$ mvn clean test -Dtest=PqcOnlyTest#testHttpClientWithBCJSSE +---- + +For native mode testing: + +[source,shell] +---- +$ mvn clean verify -Dnative +---- + +NOTE: Native mode only tests the fallback scenario (PqcWithFallbackIT) because a native executable can be built with only one `jdk.tls.namedGroups` configuration. Testing both scenarios would require building two separate native executables. + +== How It Works (Java 21 Native TLS Support) + +This example uses Java 21's native PQC support via BouncyCastle JSSE provider, which replaces the standard SunJSSE provider. + +=== Key Exchange vs Certificate Signatures + +It's important to understand the distinction: + +* **Key Exchange (Hybrid PQC)**: X25519MLKEM768 negotiated during TLS handshake + - Protects session keys from quantum attacks + - Negotiated at the TLS protocol level + - Configured via `jdk.tls.namedGroups` property + +* **Certificate Signatures (Classical RSA)**: Used for authentication only + - Proves identity of server/client + - Not directly vulnerable to "harvest now, decrypt later" attacks + - Future examples may demonstrate PQC signatures (ML-DSA) + +This example focuses on protecting the **session keys** via hybrid key exchange, which is the primary "harvest now, decrypt later" threat. + +=== TLS Handshake Flow + +1. Client initiates TLS 1.3 connection +2. Server offers X25519MLKEM768 cipher suite (configured via `jdk.tls.namedGroups`) +3. BouncyCastle JSSE provider negotiates hybrid key exchange: + - Classical X25519 ECDH component + - Quantum-resistant ML-KEM-768 component +4. Both components combine to derive session keys +5. Certificate validation happens (RSA signatures, standard X.509) +6. TLS handshake completes with quantum-resistant session keys + +=== Configuration Options + +Configure via `jdk.tls.namedGroups` property: + +[source,properties] +---- +# PQC only (maximum security, no backward compatibility) +jdk.tls.namedGroups=X25519MLKEM768 + +# PQC with fallback (recommended for production migration) +jdk.tls.namedGroups=X25519MLKEM768,x25519,secp256r1 + +---- + +The server will prefer the first algorithm but fall back to subsequent ones if the client doesn't support PQC. + +== Important Notes + +* **Java 21 Required**: This example requires Java 21 or higher. Java 21 is the first LTS version with PQC support in the TLS stack. Do not attempt to run this example on Java 17 or earlier. + +* **BouncyCastle JSSE Provider**: The example uses BouncyCastle JSSE (not just JCA provider) registered at position 2 in the security provider list. This replaces SunJSSE for TLS operations while keeping other JCA providers for standard cryptographic operations. + +* **Development Only**: Certificates are regenerated during test setup. For production, use persistent certificates from a trusted CA. + +* **Test Ordering**: JVM tests must run in a specific order (@Order annotations) because SunJSSE's static initialization fails permanently with PQC-only configuration. PqcWithFallbackTest must run before PqcOnlyTest. + +* **Native Mode Limitation**: Native executables can only be built with one `jdk.tls.namedGroups` configuration. This example builds with fallback configuration for broader compatibility testing. + +== Available Hybrid Cipher Suites + +*Hybrid variants (classical + PQC):* +- **X25519MLKEM768** (X25519 + ML-KEM-768) - Recommended, NIST Level 3 security +- SecP256r1MLKEM768 (secp256r1 + ML-KEM-768) - NIST Level 3 security +- SecP384r1MLKEM1024 (secp384r1 + ML-KEM-1024) - NIST Level 5 security + +*Pure PQC:* +- MLKEM512 - NIST Level 1 security +- MLKEM768 - NIST Level 3 security +- MLKEM1024 - NIST Level 5 security + +*Classical fallback options:* +- x25519 (Curve25519) - Current standard +- secp256r1 (NIST P-256) - Widely supported +- secp384r1 (NIST P-384) - Higher security + +NOTE: Hybrid cipher suites (X25519MLKEM768) are recommended over pure PQC because they maintain classical security even if PQC algorithms are broken. + +== Additional Resources + +* https://github.com/oscerd/camel-pqc-tls[Reference Implementation] - Original PQC TLS examples +* https://csrc.nist.gov/pubs/fips/203/final[NIST FIPS 203 - ML-KEM Standard] +* https://datatracker.ietf.org/doc/draft-ietf-tls-hybrid-design/[IETF Draft - Hybrid Key Exchange in TLS 1.3] +* https://www.bouncycastle.org/[BouncyCastle] - PQC JSSE provider documentation +* https://camel.apache.org/camel-quarkus/latest/[Camel Quarkus Documentation] +* https://www.rfc-editor.org/rfc/rfc8446.html[RFC 8446 - TLS 1.3 Specification] + +== Feedback and Contributions + +For issues or contributions, please submit to the https://github.com/apache/camel-quarkus-examples[Camel Quarkus Examples] repository. diff --git a/http-pqc-j21/eclipse-formatter-config.xml b/http-pqc-j21/eclipse-formatter-config.xml new file mode 100644 index 00000000..2248b2b8 --- /dev/null +++ b/http-pqc-j21/eclipse-formatter-config.xml @@ -0,0 +1,276 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/http-pqc-j21/pom.xml b/http-pqc-j21/pom.xml new file mode 100644 index 00000000..8bb69b39 --- /dev/null +++ b/http-pqc-j21/pom.xml @@ -0,0 +1,360 @@ + + + + 4.0.0 + + camel-quarkus-examples-http-pqc-j21 + org.apache.camel.quarkus.examples + 3.36.0-SNAPSHOT + + Camel Quarkus :: Examples :: HTTP PQC Java 21 + Camel Quarkus Example :: HTTP with Post-Quantum Cryptography on Java 21 using X25519MLKEM768 + + + 3.35.1 + 3.36.0-SNAPSHOT + + io.quarkus + quarkus-bom + org.apache.camel.quarkus + camel-quarkus-bom + + UTF-8 + UTF-8 + 21 + + 2.29.0 + 1.13.0 + 5.0.0 + 3.15.0 + 3.5.0 + 3.3.1 + 3.5.5 + + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + ${camel-quarkus.platform.group-id} + ${camel-quarkus.platform.artifact-id} + ${camel-quarkus.platform.version} + pom + import + + + + + + + org.apache.camel.quarkus + camel-quarkus-log + + + org.apache.camel.quarkus + camel-quarkus-platform-http + + + org.apache.camel.quarkus + camel-quarkus-support-bouncycastle + + + org.bouncycastle + bctls-jdk18on + + + org.apache.camel.quarkus + camel-quarkus-microprofile-health + + + org.apache.camel.quarkus + camel-quarkus-timer + + + org.apache.camel.quarkus + camel-quarkus-jackson + + + + + io.quarkus + quarkus-junit + test + + + io.rest-assured + rest-assured + test + + + org.awaitility + awaitility + test + + + + org.apache.httpcomponents.client5 + httpclient5 + test + + + + + + + + + net.revelc.code.formatter + formatter-maven-plugin + ${formatter-maven-plugin.version} + + ${maven.multiModuleProjectDirectory}/eclipse-formatter-config.xml + LF + + + + + net.revelc.code + impsort-maven-plugin + ${impsort-maven-plugin.version} + + java.,javax.,org.w3c.,org.xml.,junit. + true + true + java.,javax.,org.w3c.,org.xml.,junit. + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + true + true + + -Xlint:unchecked + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + false + + org.jboss.logmanager.LogManager + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-surefire-plugin.version} + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + com.mycila + license-maven-plugin + ${license-maven-plugin.version} + + true +
${maven.multiModuleProjectDirectory}/header.txt
+ + **/*.adoc + **/*.txt + **/LICENSE.txt + **/LICENSE + **/NOTICE.txt + **/NOTICE + **/README + **/pom.xml.versionsBackup + **/quarkus.log* + **/*.p12 + + + SLASHSTAR_STYLE + CAMEL_PROPERTIES_STYLE + SLASHSTAR_STYLE + + + ${maven.multiModuleProjectDirectory}/license-properties-headerdefinition.xml + +
+
+
+
+ + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-certificates-to-classes + process-test-classes + + copy-resources + + + ${project.build.outputDirectory}/certs + + + ${project.build.directory}/certs + + *.p12 + + + + + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + + + build + + build + + + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + format + + format + + process-sources + + + + + + net.revelc.code + impsort-maven-plugin + + + sort-imports + + sort + + process-sources + + + + + + com.mycila + license-maven-plugin + + + license-format + + format + + process-sources + + + + +
+ + + + + jdk-17 + + 17 + + + true + 17 + + + + native + + + native + + + + true + X25519MLKEM768,x25519,secp256r1 + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + ${quarkus.native.enabled} + ${jdk.tls.namedGroups} + + + + + + + + + + +
diff --git a/http-pqc-j21/src/main/java/org/acme/http/pqc/PqcCamelRoute.java b/http-pqc-j21/src/main/java/org/acme/http/pqc/PqcCamelRoute.java new file mode 100644 index 00000000..7a86a746 --- /dev/null +++ b/http-pqc-j21/src/main/java/org/acme/http/pqc/PqcCamelRoute.java @@ -0,0 +1,46 @@ +/* + * 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.acme.http.pqc; + +import jakarta.enterprise.context.ApplicationScoped; +import org.apache.camel.builder.endpoint.EndpointRouteBuilder; + +/** + * Simple route demonstrating Post-Quantum Cryptography (PQC) with TLS 1.3. + */ +@ApplicationScoped +public class PqcCamelRoute extends EndpointRouteBuilder { + + private static final String SECURE_RESPONSE = "Secure data delivered via Post-Quantum Cryptography (PQC)!\n\n" + + "Connection details:\n" + + "- TLS version: 1.3\n" + + "- Key exchange: X25519MLKEM768 (hybrid PQC)\n" + + "- Provider: BouncyCastle JSSE\n\n" + + "This connection combines classical X25519 ECDH with quantum-resistant ML-KEM-768,\n" + + "providing security against both classical and quantum computing attacks."; + + @Override + public void configure() throws Exception { + // API endpoint for secure data delivery over PQC-enabled TLS + // Client certificates are validated at TLS layer (quarkus.http.ssl.client-auth=required) + from(platformHttp("/pqc/secure")) + .routeId("pqc-secure") + .log("Serving secure data via PQC-enabled TLS connection") + .setBody(constant(SECURE_RESPONSE)) + .setHeader("Content-Type", constant("text/plain; charset=utf-8")); + } +} diff --git a/http-pqc-j21/src/main/java/org/acme/http/pqc/certificates/CertificateGenerator.java b/http-pqc-j21/src/main/java/org/acme/http/pqc/certificates/CertificateGenerator.java new file mode 100644 index 00000000..cd532afb --- /dev/null +++ b/http-pqc-j21/src/main/java/org/acme/http/pqc/certificates/CertificateGenerator.java @@ -0,0 +1,230 @@ +/* + * 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.acme.http.pqc.certificates; + +import java.io.File; +import java.io.FileOutputStream; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.KeyStore; +import java.security.SecureRandom; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import java.util.Date; + +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x509.BasicConstraints; +import org.bouncycastle.asn1.x509.Extension; +import org.bouncycastle.cert.X509v3CertificateBuilder; +import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; +import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder; +import org.bouncycastle.operator.ContentSigner; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; +import org.jboss.logging.Logger; + +/** + * Utility class for generating and persisting PQC-ready certificates for Java 21. + * These certificates use RSA keys and are compatible with BouncyCastle JSSE provider + * which enables PQC hybrid key exchange (X25519MLKEM768) at the TLS layer. + * + *

+ * Certificates are automatically generated at application startup by + * {@link SecurityConfiguration} if they don't already exist. + */ +public class CertificateGenerator { + + private static final Logger LOG = Logger.getLogger(CertificateGenerator.class); + + // WARNING: This password is hardcoded for DEMONSTRATION purposes only. + // In production, use environment variables, secrets management, or secure configuration. + // NEVER commit real passwords to source control. + private static final String KEYSTORE_PASSWORD = "changeit"; + private static final String CERT_DIR = "target/certs"; + + /** + * Certificate data holder for keypairs and certificates. + */ + public static class CertificateData { + public final KeyPair keyPair; + public final X509Certificate certificate; + + public CertificateData(KeyPair keyPair, X509Certificate certificate) { + this.keyPair = keyPair; + this.certificate = certificate; + } + } + + // Cache certificate data to ensure keystores and truststores use the same certificates + private static CertificateData serverData; + private static CertificateData clientData; + + public static void generateCertificatesIfNeeded() { + File certDir = new File("target/certs"); + File serverKeystore = new File(certDir, "server-keystore.p12"); + + // Check if certificates already exist (they might have been generated by CertificateTestResource in test mode) + if (serverKeystore.exists()) { + LOG.info("Certificates already exist, skipping generation"); + return; + } + + try { + LOG.info("Generating fresh PQC-ready keystores..."); + generateServerKeystore(); + generateClientKeystore(); + generateTruststores(); + LOG.info("PQC-ready keystores generated successfully"); + } catch (Exception e) { + LOG.error("Failed to generate PQC-ready keystores", e); + throw new RuntimeException("Keystore generation failed", e); + } + } + + /** + * Generates server keystore with RSA certificate. + */ + public static void generateServerKeystore() throws Exception { + serverData = generateCertificateData("CN=localhost,O=Camel Quarkus,C=US", true); + saveKeyStore(Paths.get(CERT_DIR, "server-keystore.p12"), serverData.keyPair, serverData.certificate, "server"); + LOG.info("Server keystore created: " + CERT_DIR + "/server-keystore.p12"); + } + + /** + * Generates client keystore with RSA certificate. + */ + public static void generateClientKeystore() throws Exception { + clientData = generateCertificateData("CN=client,O=Camel Quarkus,C=US", false); + saveKeyStore(Paths.get(CERT_DIR, "client-keystore.p12"), clientData.keyPair, clientData.certificate, "client"); + LOG.info("Client keystore created: " + CERT_DIR + "/client-keystore.p12"); + } + + /** + * Generates truststores for both server and client using the cached certificate data. + * Must be called after generateServerKeystore() and generateClientKeystore(). + */ + public static void generateTruststores() throws Exception { + if (serverData == null || clientData == null) { + throw new IllegalStateException("Must call generateServerKeystore() and generateClientKeystore() first"); + } + + saveTrustStore(Paths.get(CERT_DIR, "server-truststore.p12"), clientData.certificate, "client-ca"); + LOG.info("Server truststore created: " + CERT_DIR + "/server-truststore.p12"); + + saveTrustStore(Paths.get(CERT_DIR, "client-truststore.p12"), serverData.certificate, "server-ca"); + LOG.info("Client truststore created: " + CERT_DIR + "/client-truststore.p12"); + } + + /** + * Generates a certificate with RSA keypair. + * + * @param dn The DN for the certificate subject + * @param isCA Whether this is a CA certificate + * @return CertificateData containing keypair and certificate + */ + private static CertificateData generateCertificateData(String dn, boolean isCA) throws Exception { + KeyPair keyPair = generateKeyPair(); + X509Certificate certificate = generateCertificate(keyPair, dn, isCA); + return new CertificateData(keyPair, certificate); + } + + private static KeyPair generateKeyPair() throws Exception { + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + // Use 4096-bit RSA for future-proofing, consistent with PQC security goals + keyPairGenerator.initialize(4096, new SecureRandom()); + return keyPairGenerator.generateKeyPair(); + } + + private static X509Certificate generateCertificate(KeyPair keyPair, String dn, boolean isCA) throws Exception { + long now = System.currentTimeMillis(); + Date notBefore = new Date(now); + // Valid for 3 years for development convenience + Date notAfter = new Date(now + 1095L * 24 * 60 * 60 * 1000); + + X500Name dnName = new X500Name(dn); + // Use SecureRandom for better entropy in serial numbers + BigInteger serial = new BigInteger(64, new SecureRandom()); + + X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder( + dnName, + serial, + notBefore, + notAfter, + dnName, + keyPair.getPublic()); + + certBuilder.addExtension(Extension.basicConstraints, true, new BasicConstraints(isCA)); + + // Use default SUN provider for RSA signing - no need for BC provider + ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA") + .build(keyPair.getPrivate()); + + return new JcaX509CertificateConverter() + .getCertificate(certBuilder.build(signer)); + } + + private static void saveKeyStore(Path path, KeyPair keyPair, X509Certificate cert, String alias) throws Exception { + Path dirPath = path.getParent(); + if (!Files.exists(dirPath)) { + Files.createDirectories(dirPath); + LOG.info("Created directory: " + dirPath); + } + + // Use SUN provider for PKCS12 to ensure compatibility with curl/OpenSSL + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(null, null); + keyStore.setKeyEntry(alias, keyPair.getPrivate(), KEYSTORE_PASSWORD.toCharArray(), + new Certificate[] { cert }); + + try (FileOutputStream fos = new FileOutputStream(path.toFile())) { + keyStore.store(fos, KEYSTORE_PASSWORD.toCharArray()); + } + } + + private static void saveTrustStore(Path path, X509Certificate cert, String alias) throws Exception { + Path dirPath = path.getParent(); + if (!Files.exists(dirPath)) { + Files.createDirectories(dirPath); + LOG.info("Created directory: " + dirPath); + } + + // Use SUN provider for PKCS12 to ensure compatibility with curl/OpenSSL + KeyStore trustStore = KeyStore.getInstance("PKCS12"); + trustStore.load(null, null); + trustStore.setCertificateEntry(alias, cert); + + try (FileOutputStream fos = new FileOutputStream(path.toFile())) { + trustStore.store(fos, KEYSTORE_PASSWORD.toCharArray()); + } + } + + public static void main(String[] args) { + try { + LOG.info("Generating PQC-ready certificates..."); + generateServerKeystore(); + generateClientKeystore(); + generateTruststores(); + LOG.info("PQC-ready certificates generated successfully"); + } catch (Exception e) { + LOG.error("Failed to generate certificates", e); + System.exit(1); + } + } +} diff --git a/http-pqc-j21/src/main/java/org/acme/http/pqc/certificates/SecurityConfiguration.java b/http-pqc-j21/src/main/java/org/acme/http/pqc/certificates/SecurityConfiguration.java new file mode 100644 index 00000000..fab5cda2 --- /dev/null +++ b/http-pqc-j21/src/main/java/org/acme/http/pqc/certificates/SecurityConfiguration.java @@ -0,0 +1,83 @@ +/* + * 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.acme.http.pqc.certificates; + +import java.security.Security; + +import io.quarkus.arc.DefaultBean; +import io.quarkus.runtime.StartupEvent; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.event.Observes; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider; +import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.logging.Logger; + +@DefaultBean +@ApplicationScoped +public class SecurityConfiguration { + + private static final Logger LOG = Logger.getLogger(SecurityConfiguration.class); + + void onStart(@Observes StartupEvent ev) { + // Detect native mode + boolean isNativeMode = "executable".equals(System.getProperty("org.graalvm.nativeimage.kind")); + + if (isNativeMode) { + // In native mode, providers are already registered at build time via -H:AdditionalSecurityProviders + // We cannot remove and re-register them. Just verify they're present. + LOG.info("Native mode: Verifying build-time registered providers"); + LOG.info("BC provider: " + Security.getProvider("BC")); + LOG.info("BCJSSE provider: " + Security.getProvider("BCJSSE")); + } else { + // Configure JSSE to enable PQC hybrid key exchange algorithms + // X25519MLKEM768 combines classical X25519 ECDH with quantum-resistant ML-KEM-768 + String namedGroups = ConfigProvider.getConfig().getValue("jdk.tls.namedGroups", + String.class); + if (namedGroups != null) { + System.setProperty("jdk.tls.namedGroups", namedGroups); + LOG.info("Configured TLS named groups for PQC: " + namedGroups); + } + + // JVM mode: Remove existing providers to ensure clean state for each test + if (Security.getProvider("BCJSSE") != null) { + Security.removeProvider("BCJSSE"); + LOG.info("Removed existing BouncyCastleJsseProvider"); + } + if (Security.getProvider("BC") != null) { + Security.removeProvider("BC"); + LOG.info("Removed existing BouncyCastleProvider"); + } + + // Register BC at the end (low priority) so BCJSSE can use it + // for key conversion, while JDK's SUN/SunJCE remain the preferred + // providers for PKCS12 KeyStore and PBE algorithms. + Security.addProvider(new BouncyCastleProvider()); + LOG.info("Registered BouncyCastleProvider at end of provider list"); + + // Register BCJSSE at position 2 for TLS (after DefaultSecureRandom provider). + // BCJSSE will now be able to call SecureRandom.getInstance("DEFAULT") successfully. + Security.insertProviderAt(new BouncyCastleJsseProvider(), 2); + LOG.info("Registered BouncyCastleJsseProvider at position 2"); + } + + // Generate certificates if they don't exist (for dev mode) + // In test mode, CertificateTestResource handles this, but for dev/prod mode we need to generate them here + CertificateGenerator.generateCertificatesIfNeeded(); + } + +} diff --git a/http-pqc-j21/src/main/resources/application.properties b/http-pqc-j21/src/main/resources/application.properties new file mode 100644 index 00000000..a72b3831 --- /dev/null +++ b/http-pqc-j21/src/main/resources/application.properties @@ -0,0 +1,59 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +# +# Quarkus +# +quarkus.banner.enabled = false +quarkus.log.file.enabled = true + +# HTTPS Configuration with PQC Support (Java 21 + BouncyCastle JSSE) +# Use port 0 to get a random available port (prevents port conflicts in tests) +quarkus.http.ssl-port = 0 +quarkus.http.insecure-requests = disabled + +# Server keystore (use target/ path which works in both JVM and native mode) +quarkus.http.ssl.certificate.key-store-file = target/certs/server-keystore.p12 +quarkus.http.ssl.certificate.key-store-password = changeit +quarkus.http.ssl.certificate.key-store-file-type = PKCS12 + +# Require client certificates +quarkus.http.ssl.client-auth = required + +# Truststore for client certificate validation (use target/ path which works in both JVM and native mode) +quarkus.http.ssl.certificate.trust-store-file = target/certs/server-truststore.p12 +quarkus.http.ssl.certificate.trust-store-password = changeit +quarkus.http.ssl.certificate.trust-store-file-type = PKCS12 + +# TLS 1.3 configuration +# Protocol version - TLS 1.3 supports hybrid key exchange algorithms +quarkus.http.ssl.protocols = TLSv1.3 + +# +# Quarkus - Camel +# +quarkus.camel.health.enabled = true + +# +# Native image configuration - include certificate files as resources +# +quarkus.native.resources.includes = target/certs/*.p12 + + +# +# By default, fallback to non-pqc is allowed (test profiles override this value) +# +jdk.tls.namedGroups=X25519MLKEM768,x25519,secp256r1 \ No newline at end of file diff --git a/http-pqc-j21/src/test/java/org/acme/http/pqc/AbstractPqcTest.java b/http-pqc-j21/src/test/java/org/acme/http/pqc/AbstractPqcTest.java new file mode 100644 index 00000000..30c69ce5 --- /dev/null +++ b/http-pqc-j21/src/test/java/org/acme/http/pqc/AbstractPqcTest.java @@ -0,0 +1,165 @@ +/* + * 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.acme.http.pqc; + +import java.io.FileInputStream; +import java.security.KeyStore; +import java.security.Security; +import java.util.Arrays; + +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.TrustManagerFactory; + +import io.restassured.RestAssured; +import io.restassured.config.RestAssuredConfig; +import io.restassured.config.SSLConfig; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.http.HttpResponse; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider; +import org.jboss.logging.Logger; +import org.junit.jupiter.api.BeforeAll; + +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Abstract base class for Apache HttpClient PQC tests with explicit provider selection. + * Tests both BCJSSE (PQC-capable) and SunJSSE (classical only) providers. + * + * Certificates are generated before tests via CertificateTestResource. + */ +abstract class AbstractPqcTest { + + private static final Logger LOG = Logger.getLogger(AbstractPqcTest.class); + + @BeforeAll + static void setupSecurityProviders() { + // Register BouncyCastle providers for test client (runs in JVM, not in native binary) + // The native server has its own BC providers, but test client needs them too + if (Security.getProvider("BC") == null) { + Security.addProvider(new BouncyCastleProvider()); + } + if (Security.getProvider("BCJSSE") == null) { + Security.insertProviderAt(new BouncyCastleJsseProvider(), 1); + } + } + + void testRestAssuredConnection() throws Exception { + // RestAssured.port is automatically set by Quarkus to the actual SSL port + LOG.info("RestAssured test - using default JSSE provider (should be BCJSSE) on port " + RestAssured.port); + + given() + .config(RestAssuredConfig.config().sslConfig( + SSLConfig.sslConfig() + .keyStore("target/certs/client-keystore.p12", "changeit") + .trustStore("target/certs/client-truststore.p12", "changeit") + .allowAllHostnames())) + .baseUri("https://localhost:" + RestAssured.port) + .when() + .get("/pqc/secure") + .then() + .statusCode(200); + } + + void testHttpClientConnection(String securityProvider, boolean expectFailure) throws Exception { + boolean failedAsExpected = false; + + try { + SSLContext sslContext = createSslContext(securityProvider); + + // Create custom SSLConnectionSocketFactory that explicitly sets named groups + SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, + NoopHostnameVerifier.INSTANCE) { + @Override + protected void prepareSocket(javax.net.ssl.SSLSocket socket) throws java.io.IOException { + super.prepareSocket(socket); + // Explicitly set named groups on the socket's SSL parameters + String configuredGroups = System.getProperty("jdk.tls.namedGroups", "X25519MLKEM768"); + try { + SSLParameters sslParams = socket.getSSLParameters(); + String[] namedGroupsArray = configuredGroups.split(","); + for (int i = 0; i < namedGroupsArray.length; i++) { + namedGroupsArray[i] = namedGroupsArray[i].trim(); + } + sslParams.setNamedGroups(namedGroupsArray); + sslParams.setProtocols(new String[] { "TLSv1.3" }); + socket.setSSLParameters(sslParams); + LOG.info("Set named groups on socket: " + Arrays.toString(namedGroupsArray)); + } catch (Exception e) { + LOG.warn("Could not set named groups on socket: " + e.getMessage()); + } + } + }; + + HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create() + .setSSLSocketFactory(sslSocketFactory) + .build(); + + try (CloseableHttpClient httpClient = HttpClients.custom() + .setConnectionManager(connectionManager) + .build()) { + + HttpGet request = new HttpGet("https://localhost:" + RestAssured.port + "/pqc/secure"); + int responseStatus = httpClient.execute(request, HttpResponse::getCode); + + if (expectFailure) { + fail(securityProvider + " should have failed but got response status : " + responseStatus); + } else { + assertTrue(responseStatus == 200, "Expected response status is 200"); + } + } + } catch (NoClassDefFoundError | ExceptionInInitializerError | javax.net.ssl.SSLHandshakeException + | org.apache.hc.client5.http.HttpHostConnectException e) { + assertTrue(e.getMessage().toLowerCase().contains("connection refused"), + "Different reason - '%s' - of failure then expected".formatted(e.getMessage())); + } + } + + protected SSLContext createSslContext(String provider) throws Exception { + + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + try (FileInputStream fis = new FileInputStream("target/certs/client-keystore.p12")) { + keyStore.load(fis, "changeit".toCharArray()); + } + + KeyStore trustStore = KeyStore.getInstance("PKCS12"); + try (FileInputStream fis = new FileInputStream("target/certs/client-truststore.p12")) { + trustStore.load(fis, "changeit".toCharArray()); + } + + KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + kmf.init(keyStore, "changeit".toCharArray()); + + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + tmf.init(trustStore); + + SSLContext sslContext = SSLContext.getInstance("TLSv1.3", provider); + sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); + + return sslContext; + } +} diff --git a/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcOnlyTest.java b/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcOnlyTest.java new file mode 100644 index 00000000..82eb2adb --- /dev/null +++ b/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcOnlyTest.java @@ -0,0 +1,59 @@ +/* + * 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.acme.http.pqc; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import org.acme.http.pqc.profiles.PqcOnlyProfile; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +/** + * Test Apache HTTP Client with explicit provider selection on PQC-only server. + * + * Expected results: + * - BCJSSE: SUCCESS (supports X25519MLKEM768) + * - SunJSSE: FAILURE (does not support X25519MLKEM768) + * + * This proves that X25519MLKEM768 requires BouncyCastle JSSE. + * + * Note: @Order(2) ensures this test runs AFTER PqcWithFallbackTest. + * SunJSSE's static initialization fails with PQC-only config and permanently marks the + * class as failed. The fallback test must run first to validate SunJSSE works with classical algorithms. + * + * This test doesn't have a native *IT child, because the native executable can be build only with 1 configuration. + */ +@QuarkusTest +@TestProfile(PqcOnlyProfile.class) +@Order(2) +class PqcOnlyTest extends AbstractPqcTest { + + @Test + void testRestAssured() throws Exception { + testRestAssuredConnection(); + } + + @Test + void testHttpClientWithBCJSSE() throws Exception { + testHttpClientConnection("BCJSSE", false); + } + + @Test + void testHttpClientWithSunJSSE() throws Exception { + testHttpClientConnection("SunJSSE", true); + } +} diff --git a/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcWithFallbackIT.java b/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcWithFallbackIT.java new file mode 100644 index 00000000..b3767258 --- /dev/null +++ b/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcWithFallbackIT.java @@ -0,0 +1,36 @@ +/* + * 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.acme.http.pqc; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +/** + * Native integration test for PqcWithFallbackTest. + * Runs the same tests as PqcWithFallbackTest but against a native binary + * built with PQC+fallback configuration (X25519MLKEM768,x25519,secp256r1). + * + * This test runs FIRST in native mode (integration-test phase) against a binary + * built with fallback support. After this test completes, the native binary is + * rebuilt with PQC-only config for PqcOnlyIT. + * + * BC providers are registered by CertificateTestResource (inherited from AbstractPqcTest). + * + * Run with: mvn verify -Dnative + */ +@QuarkusIntegrationTest +class PqcWithFallbackIT extends PqcWithFallbackTest { +} diff --git a/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcWithFallbackTest.java b/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcWithFallbackTest.java new file mode 100644 index 00000000..10c0f57f --- /dev/null +++ b/http-pqc-j21/src/test/java/org/acme/http/pqc/PqcWithFallbackTest.java @@ -0,0 +1,59 @@ +/* + * 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.acme.http.pqc; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import org.acme.http.pqc.profiles.PqcWithFallbackProfile; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +/** + * Test Apache HTTP Client with PQC+fallback configuration. + * + * Expected results: + * - BCJSSE: SUCCESS (supports X25519MLKEM768 and fallback) + * - SunJSSE: SUCCESS (ignores X25519MLKEM768, uses secp256r1 fallback) + * + * Note: @Order(1) ensures this test runs BEFORE PqcOnlyTest in JVM mode. + * This test must run first because SunJSSE can successfully initialize with the fallback + * configuration. If the PQC-only test runs first, SunJSSE's static initialization fails + * permanently and cannot be recovered. + * + * In native mode, this test also runs first but against a dedicated native binary + * built with fallback configuration + */ +@QuarkusTest +@TestProfile(PqcWithFallbackProfile.class) +@Order(1) +class PqcWithFallbackTest extends AbstractPqcTest { + + @Test + void testRestAssured() throws Exception { + testRestAssuredConnection(); + } + + @Test + void testHttpClientWithBCJSSE() throws Exception { + testHttpClientConnection("BCJSSE", false); + } + + @Test + void testHttpClientWithSunJSSE() throws Exception { + testHttpClientConnection("SunJSSE", false); + } +} diff --git a/http-pqc-j21/src/test/java/org/acme/http/pqc/profiles/PqcOnlyProfile.java b/http-pqc-j21/src/test/java/org/acme/http/pqc/profiles/PqcOnlyProfile.java new file mode 100644 index 00000000..372d460f --- /dev/null +++ b/http-pqc-j21/src/test/java/org/acme/http/pqc/profiles/PqcOnlyProfile.java @@ -0,0 +1,38 @@ +/* + * 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.acme.http.pqc.profiles; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTestProfile; + +/** + * Test profile for PQC-only configuration (no fallback). + * Activates the "pqc-only" profile which configures X25519MLKEM768 ONLY. + */ +public class PqcOnlyProfile implements QuarkusTestProfile { + + @Override + public String getConfigProfile() { + return "pqc-only"; + } + + @Override + public Map getConfigOverrides() { + return Map.of("jdk.tls.namedGroups", "X25519MLKEM768"); + } +} diff --git a/http-pqc-j21/src/test/java/org/acme/http/pqc/profiles/PqcWithFallbackProfile.java b/http-pqc-j21/src/test/java/org/acme/http/pqc/profiles/PqcWithFallbackProfile.java new file mode 100644 index 00000000..a726f070 --- /dev/null +++ b/http-pqc-j21/src/test/java/org/acme/http/pqc/profiles/PqcWithFallbackProfile.java @@ -0,0 +1,38 @@ +/* + * 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.acme.http.pqc.profiles; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTestProfile; + +/** + * Test profile for PQC with classical fallback. + * Activates the "pqc-with-fallback" profile which configures X25519MLKEM768,secp256r1. + */ +public class PqcWithFallbackProfile implements QuarkusTestProfile { + + @Override + public String getConfigProfile() { + return "pqc-with-fallback"; + } + + @Override + public Map getConfigOverrides() { + return Map.of("jdk.tls.namedGroups", "X25519MLKEM768,x25519,secp256r1"); + } +} diff --git a/http-pqc-j21/src/test/resources/application.properties b/http-pqc-j21/src/test/resources/application.properties new file mode 100644 index 00000000..5e768e25 --- /dev/null +++ b/http-pqc-j21/src/test/resources/application.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + + +# Configure test class ordering to use @Order annotation as secondary ordering +# Quarkus uses a primary orderer to group tests by profile, then this secondary +# orderer applies @Order within each profile group. +# Required because SunJSSE static initialization must happen with fallback config first. +junit.quarkus.orderer.secondary-orderer=org.junit.jupiter.api.ClassOrderer$OrderAnnotation