gnodet commented on code in PR #22296:
URL: https://github.com/apache/camel/pull/22296#discussion_r3001323491
##########
components/camel-netty/src/main/java/org/apache/camel/component/netty/ssl/SSLEngineFactory.java:
##########
@@ -17,20 +17,50 @@
package org.apache.camel.component.netty.ssl;
import java.io.InputStream;
+import java.lang.reflect.Method;
import java.security.KeyStore;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
import javax.net.ssl.TrustManagerFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class SSLEngineFactory {
- private static final String SSL_PROTOCOL = "TLS";
+ private static final Logger LOG =
LoggerFactory.getLogger(SSLEngineFactory.class);
+
+ private static final String SSL_PROTOCOL = "TLSv1.3";
+
+ // PQC named group constants — mirrored from SSLContextParameters to keep
this class self-contained
+ private static final String PQC_NAMED_GROUP = "X25519MLKEM768";
+ private static final List<String> PQC_PREFERRED_NAMED_GROUPS
+ = List.of("X25519MLKEM768", "x25519", "secp256r1", "secp384r1");
Review Comment:
These constants and reflection handles are duplicated from
`BaseSSLContextParameters` / `SSLContextParameters`. The duplication is
justified since `BaseSSLContextParameters.getNamedGroupsFromParams()` is
package-private (cross-module boundary).
However, if the preferred PQC groups change, both sites must be updated in
lockstep. Consider improving the cross-reference:
```suggestion
// PQC named group constants — keep in sync with
SSLContextParameters.PQC_NAMED_GROUP
// and SSLContextParameters.PQC_PREFERRED_NAMED_GROUPS
private static final String PQC_NAMED_GROUP = "X25519MLKEM768";
private static final List<String> PQC_PREFERRED_NAMED_GROUPS
= List.of("X25519MLKEM768", "x25519", "secp256r1", "secp384r1");
```
##########
components/camel-netty/src/main/java/org/apache/camel/component/netty/ssl/SSLEngineFactory.java:
##########
@@ -72,6 +102,54 @@ public SSLContext createSSLContext(
return answer;
}
+ /**
+ * Applies post-quantum named group defaults to an {@link SSLEngine} when
the JVM supports them (typically JDK 25+).
+ * <p>
+ * When {@code X25519MLKEM768} is available, this method reorders the
named groups to prioritize post-quantum key
+ * exchange, matching the auto-configuration behavior of
+ * {@link
org.apache.camel.support.jsse.SSLContextParameters#createSSLContext}. This
should be called on SSLEngines
+ * created via the SSLEngineFactory fallback path (without
SSLContextParameters).
+ */
+ public static void applyPqcNamedGroups(SSLEngine engine) {
+ if (GET_NAMED_GROUPS == null || SET_NAMED_GROUPS == null) {
+ return;
+ }
+
+ try {
+ SSLParameters params = engine.getSSLParameters();
+ String[] availableGroups = (String[])
GET_NAMED_GROUPS.invoke(params);
+
+ if (availableGroups == null) {
+ return;
+ }
+
+ List<String> available = Arrays.asList(availableGroups);
+ if (!available.contains(PQC_NAMED_GROUP)) {
+ return;
+ }
+
+ // Build preferred ordering: PQC preferred groups first, then
remaining
+ List<String> ordered = new ArrayList<>();
+ for (String preferred : PQC_PREFERRED_NAMED_GROUPS) {
+ if (available.contains(preferred)) {
+ ordered.add(preferred);
+ }
+ }
+ for (String group : availableGroups) {
+ if (!ordered.contains(group)) {
+ ordered.add(group);
+ }
+ }
+
+ SET_NAMED_GROUPS.invoke(params, (Object) ordered.toArray(new
String[0]));
+ engine.setSSLParameters(params);
+
+ LOG.debug("Applied PQC named groups to SSLEngine: {}", ordered);
+ } catch (Exception e) {
+ LOG.debug("Could not apply PQC named groups to SSLEngine: {}",
e.getMessage());
+ }
+ }
+
public SSLEngine createServerSSLEngine(SSLContext sslContext) {
Review Comment:
`createServerSSLEngine()` and `createClientSSLEngine()` (below) are public
methods that create `SSLEngine` instances without applying PQC named groups.
Grep confirms zero callers in the codebase — the 5 initializer factories all
create engines directly via `sslContext.createSSLEngine()`.
Consider either:
- Applying `applyPqcNamedGroups()` in these methods for API consistency
- Deprecating/removing them since they're unused
##########
components/camel-netty/src/test/java/org/apache/camel/component/netty/SSLEngineFactoryTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.netty;
+
+import java.lang.reflect.Method;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
+
+import org.apache.camel.component.netty.ssl.SSLEngineFactory;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class SSLEngineFactoryTest {
+
+ @Test
+ public void testApplyPqcNamedGroupsOnSupportedJdk() throws Exception {
+ SSLContext context = SSLContext.getInstance("TLSv1.3");
+ context.init(null, null, null);
+ SSLEngine engine = context.createSSLEngine();
+
+ SSLEngineFactory.applyPqcNamedGroups(engine);
+
+ // Verify named groups were reordered if JDK supports the API and PQC
groups
+ try {
+ Method getNamedGroups =
SSLParameters.class.getMethod("getNamedGroups");
+ String[] groups = (String[])
getNamedGroups.invoke(engine.getSSLParameters());
+ if (groups != null) {
+ boolean pqcAvailable = false;
+ for (String group : groups) {
+ if ("X25519MLKEM768".equals(group)) {
+ pqcAvailable = true;
+ break;
+ }
+ }
+ if (pqcAvailable) {
+ assertEquals("X25519MLKEM768", groups[0],
+ "PQC named group should be first when available");
+ }
+ }
Review Comment:
Nit: This only verifies `X25519MLKEM768` is the first element. On a
PQC-capable JDK, consider also verifying the secondary preferred ordering —
e.g., that `x25519` appears before `secp256r1` in the resulting array, matching
`PQC_PREFERRED_NAMED_GROUPS`.
--
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]