JiriOndrusek commented on code in PR #506:
URL: 
https://github.com/apache/camel-quarkus-examples/pull/506#discussion_r3264543914


##########
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()

Review Comment:
   I can remove the version at all (I've just tested it)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to