This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new 8c3a7aa5477 CXF-9281: Apply the configured TLS named groups in all
HTTP transports (#3782)
8c3a7aa5477 is described below
commit 8c3a7aa54772e5324fe605503cfd952ecc332445
Author: Freeman(Yue) Fang <[email protected]>
AuthorDate: Thu Nov 26 08:49:47 2026 -0500
CXF-9281: Apply the configured TLS named groups in all HTTP transports
(#3782)
* CXF-9281: Apply the configured TLS named groups in all HTTP transports
The TLS named groups configured with <sec:namedGroups> (tlsServerParameters
/
tlsClientParameters) or TLSParameterBase.setNamedGroups() were not passed
on to
the TLS engine in several places, so the handshake used the JVM-wide named
groups instead:
- The Spring bean definition parsers of the HTTP conduit and of the Jetty,
Undertow and Netty server engines did not map the namedGroups element, so
getNamedGroups() was empty at runtime.
- The Undertow and Netty server engines, the Netty client, the URLConnection
conduit and the hc/hc5 async conduits never applied the named groups.
The parsers now map namedGroups, and the named groups are applied to every
SSLEngine/SSLSocket that CXF configures, through SSLParameters (JDK 20+) or,
for BC JSSE, BCSSLParameters. The Jetty server applies them to each
SSLEngine,
BC JSSE first. Undertow only accepts an SSLContext, so its engines are
created
by a wrapping NamedGroupsSSLContext. The BC JSSE reflection is resolved
once.
On a JDK without SSLParameters.setNamedGroups() (before JDK 20), configured
groups that BC JSSE does not apply are ignored, and a warning is logged
once.
The JDK HttpClient only keeps the named groups of the SSLParameters it is
given from JDK 26 on, so HttpClientHTTPConduit logs a warning once when the
configured groups are dropped, including for a shared client reused from the
cache.
* CXF-9281: Recognise BC JSSE by the engine's own class and fall back if BC
fails
- Find the BCSSLEngine / BCSSLSocket interface through the engine or socket
class itself, cached per class
with a ClassValue, rather than loading it by name with SSLUtils' class
loader. A BC JSSE provider that
SSLUtils' class loader cannot see (such as a separately installed bundle
in OSGi) is now recognised,
and no class loader is kept reachable.
- If setting the named groups through BC JSSE fails, log a warning and fall
back to SSLParameters,
rather than dropping them silently.
- Before JDK 20, without BC JSSE, warn and return without reading and
setting the SSLParameters of
every engine and socket.
---
.../http/asyncclient/AsyncHTTPConduit.java | 1 +
.../asyncclient/URLConnectionAsyncHTTPConduit.java | 1 +
.../AsyncHTTPConduitNamedGroupsTest.java | 88 +++++++
.../http/asyncclient/hc5/AsyncHTTPConduit.java | 1 +
.../hc5/URLConnectionAsyncHTTPConduit.java | 1 +
.../hc5/AsyncHTTPConduitNamedGroupsTest.java | 88 +++++++
.../http_jetty/JettyHTTPServerEngine.java | 12 +-
.../JettyHTTPServerEngineBeanDefinitionParser.java | 4 +
.../http_jetty/spring/ApplicationContextTest.java | 3 +
.../transport/http_jetty/spring/beans-props.xml | 4 +
.../cxf/transport/http_jetty/spring/beans.xml | 4 +
.../client/NettyHttpClientPipelineFactory.java | 2 +
.../server/NettyHttpServletPipelineFactory.java | 1 +
.../NettyHttpServerEngineBeanDefinitionParser.java | 4 +
.../server/spring/ApplicationContextTest.java | 3 +
.../http/netty/server/spring/beans-props.xml | 4 +
.../transport/http/netty/server/spring/beans.xml | 4 +
.../http_undertow/NamedGroupsSSLContext.java | 117 ++++++++++
.../http_undertow/UndertowHTTPServerEngine.java | 3 +-
...dertowHTTPServerEngineBeanDefinitionParser.java | 4 +
.../http_undertow/NamedGroupsSSLContextTest.java | 67 ++++++
.../spring/ApplicationContextTest.java | 3 +
.../transport/http_undertow/spring/beans-props.xml | 4 +
.../cxf/transport/http_undertow/spring/beans.xml | 4 +
.../cxf/transport/http/HttpClientHTTPConduit.java | 28 ++-
.../spring/HttpConduitBeanDefinitionParser.java | 3 +
.../transport/https/HttpsURLConnectionFactory.java | 2 +-
.../transport/https/SSLSocketFactoryWrapper.java | 12 +
.../org/apache/cxf/transport/https/SSLUtils.java | 185 +++++++++++++--
.../http/spring/HttpConduitConfigurationTest.java | 3 +
.../cxf/transport/http/spring/conduit-bean.xml | 4 +
.../transport/http/spring/conduit-tlsrefs-bean.xml | 4 +
.../transport/https/SSLUtilsNamedGroupsTest.java | 112 +++++++++
.../http_undertow/http2/NamedGroupsBookServer.java | 32 +++
.../http2/UndertowNamedGroupsTest.java | 94 ++++++++
.../http_undertow/http2/server-named-groups.xml | 44 ++++
.../systest/https/namedgroups/NamedGroupsTest.java | 256 +++++++++++++++++++++
.../https/namedgroups/named-groups-server.xml | 72 ++++++
38 files changed, 1247 insertions(+), 31 deletions(-)
diff --git
a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
index 2e941b7bbac..9d00594d5a6 100755
---
a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
+++
b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
@@ -988,6 +988,7 @@ public class AsyncHTTPConduit extends HttpClientHTTPConduit
{
params.setServerNames(serverNames.stream().map(SNIHostName::new).collect(Collectors.toList()));
sslengine.setSSLParameters(params);
}
+ org.apache.cxf.transport.https.SSLUtils.applyNamedGroups(sslengine,
tlsClientParameters.getNamedGroups());
}
private String[] findProtocols(String p, String[] options) {
diff --git
a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/URLConnectionAsyncHTTPConduit.java
b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/URLConnectionAsyncHTTPConduit.java
index b563833d650..e161eab1a98 100755
---
a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/URLConnectionAsyncHTTPConduit.java
+++
b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/URLConnectionAsyncHTTPConduit.java
@@ -978,6 +978,7 @@ public class URLConnectionAsyncHTTPConduit extends
URLConnectionHTTPConduit {
if (p != null) {
sslengine.setEnabledProtocols(p);
}
+ org.apache.cxf.transport.https.SSLUtils.applyNamedGroups(sslengine,
tlsClientParameters.getNamedGroups());
}
private String[] findProtocols(String p, String[] options) {
diff --git
a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitNamedGroupsTest.java
b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitNamedGroupsTest.java
new file mode 100644
index 00000000000..e79465b6109
--- /dev/null
+++
b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitNamedGroupsTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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.cxf.transport.http.asyncclient;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.https.SSLUtils;
+
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * The TLS named groups of the conduit's TLS client parameters are applied to
its SSLEngine.
+ */
+public class AsyncHTTPConduitNamedGroupsTest {
+ private static final List<String> GROUPS = Arrays.asList("secp384r1",
"x25519");
+ private Bus bus;
+ private AsyncHTTPConduitFactory factory;
+
+ @Before
+ public void setUp() {
+ bus = new ExtensionManagerBus();
+ factory = new AsyncHTTPConduitFactory(bus);
+ }
+
+ @After
+ public void tearDown() {
+ factory.shutdown();
+ bus.shutdown(true);
+ }
+
+ @Test
+ public void testNamedGroupsAreApplied() throws Exception {
+ Assume.assumeTrue("SSLParameters.setNamedGroups() requires JDK 20+",
hasNamedGroupsApi());
+ EndpointInfo ei = new EndpointInfo();
+ ei.setAddress("https://localhost/test");
+ AsyncHTTPConduit conduit = new AsyncHTTPConduit(bus, ei, null,
factory);
+ TLSClientParameters tls = new TLSClientParameters();
+ tls.setNamedGroups(GROUPS);
+ conduit.setTlsClientParameters(tls);
+
+ SSLContext context = SSLContext.getDefault();
+ SSLEngine engine = context.createSSLEngine("localhost", 443);
+ engine.setUseClientMode(true);
+ conduit.initializeSSLEngine(context, engine);
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(engine.getSSLParameters()));
+ conduit.close();
+ }
+
+ private static boolean hasNamedGroupsApi() {
+ try {
+ SSLParameters.class.getMethod("setNamedGroups", String[].class);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+}
diff --git
a/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
b/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
index 44cfa10bd16..9a3455ef1d8 100644
---
a/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
+++
b/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
@@ -999,6 +999,7 @@ public class AsyncHTTPConduit extends HttpClientHTTPConduit
{
params.setServerNames(serverNames.stream().map(SNIHostName::new).collect(Collectors.toList()));
sslengine.setSSLParameters(params);
}
+ org.apache.cxf.transport.https.SSLUtils.applyNamedGroups(sslengine,
tlsClientParameters.getNamedGroups());
}
@Override
diff --git
a/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/URLConnectionAsyncHTTPConduit.java
b/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/URLConnectionAsyncHTTPConduit.java
index 553dfa26d13..6d8fdc852d5 100644
---
a/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/URLConnectionAsyncHTTPConduit.java
+++
b/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/URLConnectionAsyncHTTPConduit.java
@@ -985,6 +985,7 @@ public class URLConnectionAsyncHTTPConduit extends
URLConnectionHTTPConduit {
if (p != null) {
sslengine.setEnabledProtocols(p);
}
+ org.apache.cxf.transport.https.SSLUtils.applyNamedGroups(sslengine,
tlsClientParameters.getNamedGroups());
}
@Override
diff --git
a/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitNamedGroupsTest.java
b/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitNamedGroupsTest.java
new file mode 100644
index 00000000000..468efdc0b04
--- /dev/null
+++
b/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitNamedGroupsTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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.cxf.transport.http.asyncclient.hc5;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.https.SSLUtils;
+
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * The TLS named groups of the conduit's TLS client parameters are applied to
its SSLEngine.
+ */
+public class AsyncHTTPConduitNamedGroupsTest {
+ private static final List<String> GROUPS = Arrays.asList("secp384r1",
"x25519");
+ private Bus bus;
+ private AsyncHTTPConduitFactory factory;
+
+ @Before
+ public void setUp() {
+ bus = new ExtensionManagerBus();
+ factory = new AsyncHTTPConduitFactory(bus);
+ }
+
+ @After
+ public void tearDown() {
+ factory.shutdown();
+ bus.shutdown(true);
+ }
+
+ @Test
+ public void testNamedGroupsAreApplied() throws Exception {
+ Assume.assumeTrue("SSLParameters.setNamedGroups() requires JDK 20+",
hasNamedGroupsApi());
+ EndpointInfo ei = new EndpointInfo();
+ ei.setAddress("https://localhost/test");
+ AsyncHTTPConduit conduit = new AsyncHTTPConduit(bus, ei, null,
factory);
+ TLSClientParameters tls = new TLSClientParameters();
+ tls.setNamedGroups(GROUPS);
+ conduit.setTlsClientParameters(tls);
+
+ SSLContext context = SSLContext.getDefault();
+ SSLEngine engine = context.createSSLEngine("localhost", 443);
+ engine.setUseClientMode(true);
+ conduit.initializeSSLEngine(context, engine);
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(engine.getSSLParameters()));
+ conduit.close();
+ }
+
+ private static boolean hasNamedGroupsApi() {
+ try {
+ SSLParameters.class.getMethod("setNamedGroups", String[].class);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+}
diff --git
a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
index f17a42dc9ef..7dd8beda4d0 100644
---
a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
+++
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
@@ -41,7 +41,6 @@ import java.util.logging.Logger;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLParameters;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.RequestDispatcher;
@@ -734,16 +733,11 @@ public class JettyHTTPServerEngine implements
ServerEngine, HttpServerEngineSupp
//we'll handle this later
}
@Override
- public SSLParameters customize(SSLParameters sslParams) {
- sslParams = super.customize(sslParams);
- org.apache.cxf.transport.https.SSLUtils.applyNamedGroups(
- sslParams, tlsServerParameters.getNamedGroups());
- return sslParams;
- }
- @Override
public void customize(SSLEngine sslEngine) {
super.customize(sslEngine);
- org.apache.cxf.transport.https.SSLUtils.applyNamedGroupsBC(
+ // through BCSSLParameters for a BC JSSE engine, otherwise
SSLParameters (JDK 20+), so
+ // that the groups are only reported as ignored when
neither can apply them
+ org.apache.cxf.transport.https.SSLUtils.applyNamedGroups(
sslEngine, tlsServerParameters.getNamedGroups());
}
};
diff --git
a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
index f21b49eac22..aa984b375ad 100644
---
a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
+++
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
@@ -42,6 +42,7 @@ import org.apache.cxf.configuration.security.ExcludeProtocols;
import org.apache.cxf.configuration.security.FiltersType;
import org.apache.cxf.configuration.security.IncludeProtocols;
import org.apache.cxf.configuration.security.KeyManagersType;
+import org.apache.cxf.configuration.security.NamedGroups;
import org.apache.cxf.configuration.security.SecureRandomParameters;
import org.apache.cxf.configuration.security.TLSServerParametersType;
import org.apache.cxf.configuration.security.TrustManagersType;
@@ -213,6 +214,9 @@ public class JettyHTTPServerEngineBeanDefinitionParser
extends AbstractBeanDefin
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element)n, paramsbean, ename,
CertificateConstraintsType.class);
+ } else if ("namedGroups".equals(ename)) {
+ mapElementToJaxbProperty((Element)n, paramsbean, ename,
+ NamedGroups.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
diff --git
a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java
index 8cabb33f1e8..73f4b9878b6 100644
---
a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java
+++
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.cxf.transport.http_jetty.spring;
+import java.util.Arrays;
+
import javax.xml.namespace.QName;
import org.xml.sax.SAXParseException;
@@ -156,6 +158,7 @@ public class ApplicationContextTest {
assertEquals("TestPrefix",
engine.getThreadingParameters().getThreadNamePrefix());
assertTrue(engine.getTlsServerParameters().getClientAuthentication().isWant());
assertTrue(engine.getTlsServerParameters().getClientAuthentication().isRequired());
+ assertEquals(Arrays.asList("x25519", "secp384r1"),
engine.getTlsServerParameters().getNamedGroups());
JettyHTTPDestination jd4 =
(JettyHTTPDestination)factory.getDestination(
diff --git
a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans-props.xml
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans-props.xml
index 134156326f0..ebd140f2df8 100644
---
a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans-props.xml
+++
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans-props.xml
@@ -72,6 +72,10 @@
<hj:engine port="${engine.port.nine.two}">
<hj:tlsServerParameters>
<sec:clientAuthentication want="true" required="true"/>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</hj:tlsServerParameters>
<hj:threadingParametersRef id="sampleThreading1"/>
</hj:engine>
diff --git
a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans.xml
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans.xml
index 1b81d6cbef7..8bb9a52b95b 100644
---
a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans.xml
+++
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/beans.xml
@@ -59,6 +59,10 @@
<hj:engine port="9002">
<hj:tlsServerParameters>
<sec:clientAuthentication want="true" required="true"/>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</hj:tlsServerParameters>
<hj:threadingParametersRef id="sampleThreading1"/>
</hj:engine>
diff --git
a/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientPipelineFactory.java
b/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientPipelineFactory.java
index c3b53152b8b..e315359b11b 100644
---
a/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientPipelineFactory.java
+++
b/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientPipelineFactory.java
@@ -283,6 +283,8 @@ public class NettyHttpClientPipelineFactory extends
ChannelInitializer<Channel>
}
}
+ SSLUtils.applyNamedGroups(sslEngine,
tlsClientParameters.getNamedGroups());
+
if (peerHost == null && !tlsClientParameters.isDisableCNCheck()) {
LOG.warning("No peer host information was supplied to the
pipeline factory: TLS "
+ "hostname verification cannot be performed. Use the
constructor taking a "
diff --git
a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java
b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java
index 4134c3f44f7..397c0cf16c7 100644
---
a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java
+++
b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java
@@ -364,6 +364,7 @@ public class NettyHttpServletPipelineFactory extends
ChannelInitializer<Channel>
SslContext sslCtx = configureServerHttp2SSLOnDemand();
if (sslCtx != null) {
final SslHandler sslHandler = sslCtx.newHandler(channel.alloc());
+ SSLUtils.applyNamedGroups(sslHandler.engine(),
tlsServerParameters.getNamedGroups());
LOG.log(Level.FINE,
"Server SSL handler configured and added as an interceptor
against the ChannelPipeline: {}",
diff --git
a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/spring/NettyHttpServerEngineBeanDefinitionParser.java
b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/spring/NettyHttpServerEngineBeanDefinitionParser.java
index d6e9f337902..1e97acbe830 100644
---
a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/spring/NettyHttpServerEngineBeanDefinitionParser.java
+++
b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/spring/NettyHttpServerEngineBeanDefinitionParser.java
@@ -39,6 +39,7 @@ import org.apache.cxf.configuration.security.CipherSuites;
import org.apache.cxf.configuration.security.ClientAuthentication;
import org.apache.cxf.configuration.security.FiltersType;
import org.apache.cxf.configuration.security.KeyManagersType;
+import org.apache.cxf.configuration.security.NamedGroups;
import org.apache.cxf.configuration.security.SecureRandomParameters;
import org.apache.cxf.configuration.security.TLSServerParametersType;
import org.apache.cxf.configuration.security.TrustManagersType;
@@ -192,6 +193,9 @@ public class NettyHttpServerEngineBeanDefinitionParser
extends AbstractBeanDefin
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element)n, paramsbean, ename,
CertificateConstraintsType.class);
+ } else if ("namedGroups".equals(ename)) {
+ mapElementToJaxbProperty((Element)n, paramsbean, ename,
+ NamedGroups.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
diff --git
a/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/spring/ApplicationContextTest.java
b/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/spring/ApplicationContextTest.java
index 9a5d8350b40..3e7f580f7f0 100644
---
a/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/spring/ApplicationContextTest.java
+++
b/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/spring/ApplicationContextTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.cxf.transport.http.netty.server.spring;
+import java.util.Arrays;
+
import javax.xml.namespace.QName;
import org.xml.sax.SAXParseException;
@@ -145,6 +147,7 @@ public class ApplicationContextTest {
engine = (NettyHttpServerEngine)jd3.getEngine();
assertTrue(engine.getTlsServerParameters().getClientAuthentication().isWant());
assertTrue(engine.getTlsServerParameters().getClientAuthentication().isRequired());
+ assertEquals(Arrays.asList("x25519", "secp384r1"),
engine.getTlsServerParameters().getNamedGroups());
NettyHttpDestination jd4 =
(NettyHttpDestination)factory.getDestination(
diff --git
a/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans-props.xml
b/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans-props.xml
index b04918e0970..c6d9f082db3 100644
---
a/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans-props.xml
+++
b/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans-props.xml
@@ -65,6 +65,10 @@
<hn:engine port="${engine.port.nine.two}">
<hn:tlsServerParameters>
<sec:clientAuthentication want="true" required="true"/>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</hn:tlsServerParameters>
</hn:engine>
<hn:engine port="${engine.port.nine.three}">
diff --git
a/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans.xml
b/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans.xml
index bec9330f29f..5bd426b5a34 100644
---
a/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans.xml
+++
b/rt/transports/http-netty/netty-server/src/test/resources/org/apache/cxf/transport/http/netty/server/spring/beans.xml
@@ -55,6 +55,10 @@
<hn:engine port="9002">
<hn:tlsServerParameters>
<sec:clientAuthentication want="true" required="true"/>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</hn:tlsServerParameters>
</hn:engine>
<hn:engine port="9003">
diff --git
a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/NamedGroupsSSLContext.java
b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/NamedGroupsSSLContext.java
new file mode 100644
index 00000000000..f44c2667a78
--- /dev/null
+++
b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/NamedGroupsSSLContext.java
@@ -0,0 +1,117 @@
+/**
+ * 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.cxf.transport.http_undertow;
+
+import java.security.KeyManagementException;
+import java.security.SecureRandom;
+import java.util.List;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLContextSpi;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSessionContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+import org.apache.cxf.transport.https.SSLUtils;
+
+/**
+ * An SSLContext that applies the configured TLS named groups to every
SSLEngine it creates.
+ * Undertow only accepts an SSLContext for an HTTPS listener and has no option
for named groups.
+ */
+final class NamedGroupsSSLContext extends SSLContext {
+
+ private NamedGroupsSSLContext(SSLContext delegate, List<String>
namedGroups) {
+ super(new Spi(delegate, namedGroups), delegate.getProvider(),
delegate.getProtocol());
+ }
+
+ /**
+ * Returns the context itself when no named groups are configured, else a
wrapper that applies them.
+ */
+ static SSLContext wrap(SSLContext context, List<String> namedGroups) {
+ if (context == null || namedGroups == null || namedGroups.isEmpty()) {
+ return context;
+ }
+ return new NamedGroupsSSLContext(context, namedGroups);
+ }
+
+ private static final class Spi extends SSLContextSpi {
+ private final SSLContext delegate;
+ private final List<String> namedGroups;
+
+ Spi(SSLContext delegate, List<String> namedGroups) {
+ this.delegate = delegate;
+ this.namedGroups = namedGroups;
+ }
+
+ @Override
+ protected void engineInit(KeyManager[] km, TrustManager[] tm,
SecureRandom sr)
+ throws KeyManagementException {
+ delegate.init(km, tm, sr);
+ }
+
+ @Override
+ protected SSLSocketFactory engineGetSocketFactory() {
+ return delegate.getSocketFactory();
+ }
+
+ @Override
+ protected SSLServerSocketFactory engineGetServerSocketFactory() {
+ return delegate.getServerSocketFactory();
+ }
+
+ @Override
+ protected SSLEngine engineCreateSSLEngine() {
+ SSLEngine engine = delegate.createSSLEngine();
+ SSLUtils.applyNamedGroups(engine, namedGroups);
+ return engine;
+ }
+
+ @Override
+ protected SSLEngine engineCreateSSLEngine(String host, int port) {
+ SSLEngine engine = delegate.createSSLEngine(host, port);
+ SSLUtils.applyNamedGroups(engine, namedGroups);
+ return engine;
+ }
+
+ @Override
+ protected SSLSessionContext engineGetServerSessionContext() {
+ return delegate.getServerSessionContext();
+ }
+
+ @Override
+ protected SSLSessionContext engineGetClientSessionContext() {
+ return delegate.getClientSessionContext();
+ }
+
+ @Override
+ protected SSLParameters engineGetDefaultSSLParameters() {
+ return delegate.getDefaultSSLParameters();
+ }
+
+ @Override
+ protected SSLParameters engineGetSupportedSSLParameters() {
+ return delegate.getSupportedSSLParameters();
+ }
+ }
+}
diff --git
a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngine.java
b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngine.java
index 9e5ad7e4925..190d2cfd1b8 100644
---
a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngine.java
+++
b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngine.java
@@ -241,7 +241,8 @@ public class UndertowHTTPServerEngine implements
ServerEngine, HttpServerEngineS
if (this.sslContext == null) {
this.sslContext = createSSLContext();
}
- result = result.addHttpsListener(getPort(), getHost(),
this.sslContext);
+ result = result.addHttpsListener(getPort(), getHost(),
+ NamedGroupsSSLContext.wrap(this.sslContext,
tlsServerParameters.getNamedGroups()));
} else {
result = result.addHttpListener(getPort(), getHost());
}
diff --git
a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/spring/UndertowHTTPServerEngineBeanDefinitionParser.java
b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/spring/UndertowHTTPServerEngineBeanDefinitionParser.java
index bc602ee56fe..4170cf34901 100644
---
a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/spring/UndertowHTTPServerEngineBeanDefinitionParser.java
+++
b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/spring/UndertowHTTPServerEngineBeanDefinitionParser.java
@@ -42,6 +42,7 @@ import org.apache.cxf.configuration.security.ExcludeProtocols;
import org.apache.cxf.configuration.security.FiltersType;
import org.apache.cxf.configuration.security.IncludeProtocols;
import org.apache.cxf.configuration.security.KeyManagersType;
+import org.apache.cxf.configuration.security.NamedGroups;
import org.apache.cxf.configuration.security.SecureRandomParameters;
import org.apache.cxf.configuration.security.TLSServerParametersType;
import org.apache.cxf.configuration.security.TrustManagersType;
@@ -199,6 +200,9 @@ public class UndertowHTTPServerEngineBeanDefinitionParser
extends AbstractBeanDe
} else if ("certConstraints".equals(ename)) {
mapElementToJaxbProperty((Element)n, paramsbean, ename,
CertificateConstraintsType.class);
+ } else if ("namedGroups".equals(ename)) {
+ mapElementToJaxbProperty((Element)n, paramsbean, ename,
+ NamedGroups.class);
} else if ("certAlias".equals(ename)) {
paramsbean.addPropertyValue(ename, n.getTextContent());
}
diff --git
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/NamedGroupsSSLContextTest.java
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/NamedGroupsSSLContextTest.java
new file mode 100644
index 00000000000..41c2fb4a44e
--- /dev/null
+++
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/NamedGroupsSSLContextTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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.cxf.transport.http_undertow;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLParameters;
+
+import org.apache.cxf.transport.https.SSLUtils;
+
+import org.junit.Assume;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+public class NamedGroupsSSLContextTest {
+ private static final List<String> GROUPS = Arrays.asList("secp384r1",
"x25519");
+
+ @Test
+ public void testEnginesGetTheNamedGroups() throws Exception {
+ Assume.assumeTrue("SSLParameters.setNamedGroups() requires JDK 20+",
hasNamedGroupsApi());
+ SSLContext delegate = SSLContext.getDefault();
+ SSLContext context = NamedGroupsSSLContext.wrap(delegate, GROUPS);
+ assertEquals(delegate.getProtocol(), context.getProtocol());
+ assertEquals(delegate.getProvider(), context.getProvider());
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(context.createSSLEngine().getSSLParameters()));
+ assertArrayEquals(GROUPS.toArray(),
+ SSLUtils.getNamedGroups(context.createSSLEngine("localhost",
8443).getSSLParameters()));
+ }
+
+ @Test
+ public void testNoNamedGroupsKeepsTheContext() throws Exception {
+ SSLContext delegate = SSLContext.getDefault();
+ assertSame(delegate, NamedGroupsSSLContext.wrap(delegate, null));
+ assertSame(delegate, NamedGroupsSSLContext.wrap(delegate, List.of()));
+ }
+
+ private static boolean hasNamedGroupsApi() {
+ try {
+ SSLParameters.class.getMethod("setNamedGroups", String[].class);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+}
diff --git
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/ApplicationContextTest.java
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/ApplicationContextTest.java
index 83c752e3850..ba43a0f8a9c 100644
---
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/ApplicationContextTest.java
+++
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/ApplicationContextTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.cxf.transport.http_undertow.spring;
+import java.util.Arrays;
+
import javax.xml.namespace.QName;
import org.xml.sax.SAXParseException;
@@ -152,6 +154,7 @@ public class ApplicationContextTest {
assertTrue(engine.getTlsServerParameters().getClientAuthentication().isWant());
assertTrue(engine.getTlsServerParameters().getClientAuthentication().isRequired());
+ assertEquals(Arrays.asList("x25519", "secp384r1"),
engine.getTlsServerParameters().getNamedGroups());
UndertowHTTPDestination jd4 =
(UndertowHTTPDestination)factory.getDestination(
diff --git
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans-props.xml
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans-props.xml
index 83b6d93102a..d73e06f4bc0 100644
---
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans-props.xml
+++
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans-props.xml
@@ -70,6 +70,10 @@
<hj:engine port="${engine.port.nine.two}">
<hj:tlsServerParameters>
<sec:clientAuthentication want="true" required="true"/>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</hj:tlsServerParameters>
<hj:threadingParametersRef id="sampleThreading1"/>
</hj:engine>
diff --git
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans.xml
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans.xml
index b4a550e18b9..9c57373c760 100644
---
a/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans.xml
+++
b/rt/transports/http-undertow/src/test/java/org/apache/cxf/transport/http_undertow/spring/beans.xml
@@ -57,6 +57,10 @@
<hj:engine port="9002">
<hj:tlsServerParameters>
<sec:clientAuthentication want="true" required="true"/>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</hj:tlsServerParameters>
<hj:threadingParametersRef id="sampleThreading1"/>
</hj:engine>
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
index 3e46881d098..b2ba6e91061 100644
---
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
@@ -74,6 +74,7 @@ import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
@@ -106,6 +107,8 @@ public class HttpClientHTTPConduit extends
URLConnectionHTTPConduit {
private static final Set<String> RESTRICTED_HEADERS =
getRestrictedHeaders();
private static final HttpClientCache CLIENTS_CACHE = new HttpClientCache();
+ // Ensures the "HttpClient drops the configured named groups" warning is
logged at most once per JVM.
+ private static final AtomicBoolean NAMED_GROUPS_DROPPED_WARNED = new
AtomicBoolean();
volatile RefCount<HttpClient> clientRef;
volatile URI sslURL;
private final ReentrantLock initializationLock = new ReentrantLock();
@@ -294,6 +297,24 @@ public class HttpClientHTTPConduit extends
URLConnectionHTTPConduit {
return copy;
}
+ /**
+ * The JDK HttpClient only keeps the named groups of the SSLParameters it
is given from JDK 26 on.
+ * Warn once when the configured groups were dropped despite this JDK
supporting them on
+ * {@code SSLParameters} (JDK 20-25), since the JVM-wide
jdk.tls.namedGroups apply instead. On
+ * JDK < 20 the groups never reach the parameters and SSLUtils already
warns about that, so this
+ * is gated on {@link SSLUtils#isNamedGroupsSupported()} to avoid a
second, mis-attributed warning.
+ * Called for every resolved client, including shared ones reused from the
cache.
+ */
+ private static void checkNamedGroups(HttpClient client, List<String>
namedGroups) {
+ if (namedGroups != null && !namedGroups.isEmpty()
+ && SSLUtils.isNamedGroupsSupported()
+ && SSLUtils.getNamedGroups(client.sslParameters()) == null
+ && NAMED_GROUPS_DROPPED_WARNED.compareAndSet(false, true)) {
+ LOG.warning("The TLS named groups " + namedGroups + " are not
retained by the JDK HttpClient"
+ + " before JDK 26 and are ignored; the JVM-wide
jdk.tls.namedGroups setting applies instead");
+ }
+ }
+
private static TLSClientParameters copyOf(TLSClientParameters params) {
final TLSClientParameters copy = params.copy();
// the certificate constraints are left out: the client is not built
from them, they are
@@ -537,6 +558,8 @@ public class HttpClientHTTPConduit extends
URLConnectionHTTPConduit {
cb.version(Version.HTTP_1_1);
}
+ final List<String> namedGroups = "https".equals(uri.getScheme())
+ ? clientParameters.getNamedGroups() : null;
// make sure the conduit is not yet initialized
initializationLock.lock();
try {
@@ -545,7 +568,10 @@ public class HttpClientHTTPConduit extends
URLConnectionHTTPConduit {
final boolean shareHttpClient =
MessageUtils.getContextualBoolean(message,
SHARE_HTTPCLIENT_CONDUIT, true);
cl = CLIENTS_CACHE.computeIfAbsent(shareHttpClient,
clientPolicy, clientParametersCopy,
- () -> cb.build());
+ cb::build);
+ // run for every resolved client, so a shared client
reused from the cache (where the
+ // supplier above does not run) still reports dropped
named groups
+ checkNamedGroups(cl.client(), namedGroups);
// the cache may hand back a shared client this conduit
has stopped using, when it
// switches back to its settings or its HTTPS address
changes. Keep a single reference
if (deferredClientRefs.remove(cl)) {
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpConduitBeanDefinitionParser.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpConduitBeanDefinitionParser.java
index 994b29a343b..5de44b1ee82 100644
---
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpConduitBeanDefinitionParser.java
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpConduitBeanDefinitionParser.java
@@ -34,6 +34,7 @@ import
org.apache.cxf.configuration.security.CertificateConstraintsType;
import org.apache.cxf.configuration.security.CipherSuites;
import org.apache.cxf.configuration.security.FiltersType;
import org.apache.cxf.configuration.security.KeyManagersType;
+import org.apache.cxf.configuration.security.NamedGroups;
import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
import org.apache.cxf.configuration.security.SecureRandomParameters;
import org.apache.cxf.configuration.security.ServerNames;
@@ -174,6 +175,8 @@ public class HttpConduitBeanDefinitionParser
paramsbean.addPropertyValue(ename, n.getTextContent());
} else if ("serverNames".equals(ename)) {
mapElementToJaxbProperty((Element)n, paramsbean, ename,
ServerNames.class);
+ } else if ("namedGroups".equals(ename)) {
+ mapElementToJaxbProperty((Element)n, paramsbean, ename,
NamedGroups.class);
}
n = n.getNextSibling();
}
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
index d42549de501..a7e5c47ae9d 100644
---
a/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
@@ -155,7 +155,7 @@ public class HttpsURLConnectionFactory {
String protocol = tlsClientParameters.getSecureSocketProtocol() !=
null ? tlsClientParameters
.getSecureSocketProtocol() : ctx.getProtocol();
socketFactory = new
SSLSocketFactoryWrapper(ctx.getSocketFactory(), cipherSuites,
- protocol);
+ protocol,
tlsClientParameters.getNamedGroups());
//recalc the hashcode since some of the above MAY have changed the
tlsClientParameters
lastTlsHash = tlsClientParameters.hashCode();
} else {
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java
index 235f7e56147..b978fc67cc9 100644
---
a/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java
@@ -41,15 +41,26 @@ class SSLSocketFactoryWrapper extends SSLSocketFactory {
private SSLSocketFactory sslSocketFactory;
private String[] ciphers;
private String protocol;
+ private List<String> namedGroups;
SSLSocketFactoryWrapper(
SSLSocketFactory sslSocketFactoryParam,
String[] ciphersParam,
String protocolParam
+ ) {
+ this(sslSocketFactoryParam, ciphersParam, protocolParam, null);
+ }
+
+ SSLSocketFactoryWrapper(
+ SSLSocketFactory sslSocketFactoryParam,
+ String[] ciphersParam,
+ String protocolParam,
+ List<String> namedGroupsParam
) {
sslSocketFactory = sslSocketFactoryParam;
ciphers = ciphersParam;
protocol = protocolParam;
+ namedGroups = namedGroupsParam;
}
public String[] getDefaultCipherSuites() {
@@ -112,6 +123,7 @@ class SSLSocketFactoryWrapper extends SSLSocketFactory {
if (ciphers != null) {
socket.setEnabledCipherSuites(ciphers);
}
+ SSLUtils.applyNamedGroups(socket, namedGroups);
return socket;
}
diff --git
a/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java
index ba79f4d8344..f25ba7eff1f 100644
---
a/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java
+++
b/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java
@@ -28,7 +28,10 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.net.ssl.ExtendedSSLSession;
@@ -65,10 +68,39 @@ public final class SSLUtils {
private static final Logger LOG = LogUtils.getL7dLogger(SSLUtils.class);
+ // Cached reflection for SSLParameters.setNamedGroups/getNamedGroups (JDK
20+), resolved once.
+ private static final Method SSL_PARAMS_SET_NAMED_GROUPS =
+ findMethod(SSLParameters.class, "setNamedGroups", String[].class);
+ private static final Method SSL_PARAMS_GET_NAMED_GROUPS =
+ findMethod(SSLParameters.class, "getNamedGroups");
+
+ // BC JSSE reflection handles per engine or socket class, found through
the class's own interfaces so that
+ // BC JSSE is recognised whichever class loader loaded it (such as a
separate bundle in OSGi). ClassValue
+ // does not keep the class, or its class loader, reachable.
+ private static final ClassValue<BCHandle> BC_HANDLES = new
ClassValue<BCHandle>() {
+ @Override
+ protected BCHandle computeValue(Class<?> type) {
+ return resolveBCHandle(type);
+ }
+ };
+ private static final Set<String> BC_TYPES =
+ new HashSet<>(Arrays.asList("org.bouncycastle.jsse.BCSSLEngine",
"org.bouncycastle.jsse.BCSSLSocket"));
+
+ // Ensures the "named groups ignored on JDK < 20" warning is logged at
most once per JVM.
+ private static final AtomicBoolean NAMED_GROUPS_UNSUPPORTED_WARNED = new
AtomicBoolean();
+
private SSLUtils() {
//Helper class
}
+ private static Method findMethod(Class<?> type, String name, Class<?>...
paramTypes) {
+ try {
+ return type.getMethod(name, paramTypes);
+ } catch (NoSuchMethodException e) {
+ return null;
+ }
+ }
+
public static String[] getProtocolsToInclude(List<String> includeProtocols,
List<String> excludeProtocols,
String[] defaultProtocols,
@@ -243,6 +275,7 @@ public final class SSLUtils {
serverEngine.setNeedClientAuth(clientAuth.isRequired());
}
}
+ applyNamedGroups(serverEngine, parameters.getNamedGroups());
return serverEngine;
}
@@ -254,6 +287,7 @@ public final class SSLUtils {
SSLContext sslContext = getSSLContext(parameters);
SSLEngine clientEngine = sslContext.createSSLEngine();
clientEngine.setUseClientMode(true);
+ applyNamedGroups(clientEngine, parameters.getNamedGroups());
return clientEngine;
}
@@ -262,6 +296,7 @@ public final class SSLUtils {
SSLContext sslContext = getSSLContext(parameters, true);
SSLEngine clientEngine = sslContext.createSSLEngine(peerHost,
peerPort);
clientEngine.setUseClientMode(true);
+ applyNamedGroups(clientEngine, parameters.getNamedGroups());
return clientEngine;
}
@@ -631,42 +666,154 @@ public final class SSLUtils {
}
}
+ /**
+ * Whether this JDK exposes {@code SSLParameters.setNamedGroups()} (JDK
20+). When it does not,
+ * named groups configured for a non-BouncyCastle provider cannot be
applied and are ignored.
+ */
+ public static boolean isNamedGroupsSupported() {
+ return SSL_PARAMS_SET_NAMED_GROUPS != null;
+ }
+
/**
* Applies the given named groups to {@code SSLParameters} via reflection.
- * {@code SSLParameters.setNamedGroups()} requires JDK 20+; this method
- * silently skips the call on older JDKs.
+ * {@code SSLParameters.setNamedGroups()} requires JDK 20+; on older JDKs
the groups are
+ * ignored and a single warning is logged so the inert setting is not
silently dropped.
*/
public static void applyNamedGroups(SSLParameters params, List<String>
namedGroups) {
if (namedGroups == null || namedGroups.isEmpty()) {
return;
}
+ if (SSL_PARAMS_SET_NAMED_GROUPS == null) {
+ warnNamedGroupsUnsupported(namedGroups);
+ return;
+ }
try {
- Method m = SSLParameters.class.getMethod("setNamedGroups",
String[].class);
- m.invoke(params, (Object) namedGroups.toArray(new String[0]));
- } catch (NoSuchMethodException e) {
- LOG.fine("SSLParameters.setNamedGroups() not available on this
JDK; namedGroups ignored");
+ SSL_PARAMS_SET_NAMED_GROUPS.invoke(params, (Object)
namedGroups.toArray(new String[0]));
} catch (ReflectiveOperationException e) {
LOG.warning("Failed to apply TLS namedGroups: " + e.getMessage());
}
}
- // Reflection-based BC JSSE path: avoids a compile-time dependency on
bctls-jdk18on.
- public static void applyNamedGroupsBC(SSLEngine sslEngine, List<String>
namedGroups) {
- if (namedGroups == null || namedGroups.isEmpty()) {
+ /**
+ * Returns the named groups of {@code SSLParameters} via reflection, or
null when none are set
+ * or {@code SSLParameters.getNamedGroups()} is not available (JDK 20+).
+ */
+ public static String[] getNamedGroups(SSLParameters params) {
+ if (SSL_PARAMS_GET_NAMED_GROUPS == null) {
+ return null;
+ }
+ try {
+ return (String[]) SSL_PARAMS_GET_NAMED_GROUPS.invoke(params);
+ } catch (ReflectiveOperationException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Applies the given named groups to an {@code SSLEngine}: through {@code
BCSSLParameters}
+ * for a BC JSSE engine, otherwise through {@code SSLParameters} (JDK 20+).
+ */
+ public static void applyNamedGroups(SSLEngine sslEngine, List<String>
namedGroups) {
+ if (namedGroups == null || namedGroups.isEmpty() ||
applyNamedGroupsBC(sslEngine, namedGroups)) {
+ return;
+ }
+ if (!isNamedGroupsSupported()) {
+ warnNamedGroupsUnsupported(namedGroups);
+ return;
+ }
+ SSLParameters params = sslEngine.getSSLParameters();
+ applyNamedGroups(params, namedGroups);
+ sslEngine.setSSLParameters(params);
+ }
+
+ /**
+ * Applies the given named groups to an {@code SSLSocket}: through {@code
BCSSLParameters}
+ * for a BC JSSE socket, otherwise through {@code SSLParameters} (JDK 20+).
+ */
+ public static void applyNamedGroups(SSLSocket socket, List<String>
namedGroups) {
+ if (namedGroups == null || namedGroups.isEmpty() ||
applyNamedGroupsBC(socket, namedGroups)) {
+ return;
+ }
+ if (!isNamedGroupsSupported()) {
+ warnNamedGroupsUnsupported(namedGroups);
return;
}
+ SSLParameters params = socket.getSSLParameters();
+ applyNamedGroups(params, namedGroups);
+ socket.setSSLParameters(params);
+ }
+
+ private static void warnNamedGroupsUnsupported(List<String> namedGroups) {
+ if (NAMED_GROUPS_UNSUPPORTED_WARNED.compareAndSet(false, true)) {
+ LOG.warning("The configured TLS named groups " + namedGroups + "
are ignored:"
+ + " SSLParameters.setNamedGroups() requires JDK 20 or later."
+ + " The JVM-wide jdk.tls.namedGroups setting applies
instead.");
+ }
+ }
+
+ /**
+ * Sets the named groups through BCSSLParameters if the engine or socket
is a BC JSSE one (BCSSLEngine or
+ * BCSSLSocket), by reflection, to avoid a compile-time dependency on
bctls. Returns false if it is not, or
+ * if setting them failed, so the caller falls back to the standard {@code
SSLParameters} path.
+ */
+ private static boolean applyNamedGroupsBC(Object engineOrSocket,
List<String> namedGroups) {
+ BCHandle handle = BC_HANDLES.get(engineOrSocket.getClass());
+ if (handle == BCHandle.NONE) {
+ return false;
+ }
+ try {
+ Object bcParams = handle.getParameters.invoke(engineOrSocket);
+ handle.setNamedGroups.invoke(bcParams, (Object)
namedGroups.toArray(new String[0]));
+ handle.setParameters.invoke(engineOrSocket, bcParams);
+ return true;
+ } catch (ReflectiveOperationException | RuntimeException e) {
+ LOG.warning("Could not apply the TLS named groups " + namedGroups
+ " through BC JSSE, trying"
+ + " SSLParameters instead: " + e);
+ return false;
+ }
+ }
+
+ private static BCHandle resolveBCHandle(Class<?> type) {
+ Class<?> bcType = findBCType(type);
+ if (bcType == null) {
+ return BCHandle.NONE;
+ }
try {
- Class<?> bcEngineClass =
Class.forName("org.bouncycastle.jsse.BCSSLEngine");
- if (!bcEngineClass.isInstance(sslEngine)) {
- return;
+ Method getParameters = bcType.getMethod("getParameters");
+ Class<?> bcParamsClass = getParameters.getReturnType();
+ return new BCHandle(getParameters,
bcType.getMethod("setParameters", bcParamsClass),
+ bcParamsClass.getMethod("setNamedGroups", String[].class));
+ } catch (ReflectiveOperationException | LinkageError e) {
+ LOG.fine("BC JSSE " + bcType.getName() + " does not support named
groups: " + e);
+ return BCHandle.NONE;
+ }
+ }
+
+ // the BCSSLEngine or BCSSLSocket interface that the class implements, or
null
+ private static Class<?> findBCType(Class<?> type) {
+ for (Class<?> c = type; c != null; c = c.getSuperclass()) {
+ for (Class<?> i : c.getInterfaces()) {
+ Class<?> found = BC_TYPES.contains(i.getName()) ? i :
findBCType(i);
+ if (found != null) {
+ return found;
+ }
}
- Class<?> bcParamsClass =
Class.forName("org.bouncycastle.jsse.BCSSLParameters");
- Object bcParams =
bcEngineClass.getMethod("getParameters").invoke(sslEngine);
- bcParamsClass.getMethod("setNamedGroups", String[].class)
- .invoke(bcParams, (Object) namedGroups.toArray(new String[0]));
- bcEngineClass.getMethod("setParameters",
bcParamsClass).invoke(sslEngine, bcParams);
- } catch (ReflectiveOperationException e) {
- LOG.fine("Could not apply named groups via BC JSSE engine: " +
e.getMessage());
+ }
+ return null;
+ }
+
+ /** BC JSSE reflection handles for one engine or socket class, or {@link
#NONE} if it is not a BC JSSE one. */
+ private static final class BCHandle {
+ static final BCHandle NONE = new BCHandle(null, null, null);
+
+ private final Method getParameters;
+ private final Method setParameters;
+ private final Method setNamedGroups;
+
+ BCHandle(Method getParameters, Method setParameters, Method
setNamedGroups) {
+ this.getParameters = getParameters;
+ this.setParameters = setParameters;
+ this.setNamedGroups = setNamedGroups;
}
}
diff --git
a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/HttpConduitConfigurationTest.java
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/HttpConduitConfigurationTest.java
index f652dfac3e4..e887e8f7b6b 100644
---
a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/HttpConduitConfigurationTest.java
+++
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/HttpConduitConfigurationTest.java
@@ -19,6 +19,8 @@
package org.apache.cxf.transport.http.spring;
+import java.util.Arrays;
+
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509KeyManager;
@@ -97,6 +99,7 @@ public class HttpConduitConfigurationTest {
assertNotNull(tlscps);
assertTrue(tlscps.isDisableCNCheck());
assertEquals(3600000, tlscps.getSslCacheTimeout());
+ assertEquals(Arrays.asList("x25519", "secp384r1"),
tlscps.getNamedGroups());
KeyManager[] kms = tlscps.getKeyManagers();
assertTrue(kms != null && kms.length == 1);
diff --git
a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-bean.xml
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-bean.xml
index fffb48fcc94..de70bebc3c8 100644
---
a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-bean.xml
+++
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-bean.xml
@@ -35,6 +35,10 @@
<sec:include>.*_WITH_AES_.*</sec:include>
<sec:exclude>.*_CBC_.*</sec:exclude>
</sec:cipherSuitesFilter>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</http:tlsClientParameters>
<http:authorization>
<sec:UserName>Betty</sec:UserName>
diff --git
a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-tlsrefs-bean.xml
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-tlsrefs-bean.xml
index 1ef03230335..8a74e53d217 100644
---
a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-tlsrefs-bean.xml
+++
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/spring/conduit-tlsrefs-bean.xml
@@ -33,6 +33,10 @@
<sec:include>.*_WITH_AES_.*</sec:include>
<sec:exclude>.*_CBC_.*</sec:exclude>
</sec:cipherSuitesFilter>
+ <sec:namedGroups>
+ <sec:namedGroup>x25519</sec:namedGroup>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
</http:tlsClientParameters>
<http:authorization>
<sec:UserName>Betty</sec:UserName>
diff --git
a/rt/transports/http/src/test/java/org/apache/cxf/transport/https/SSLUtilsNamedGroupsTest.java
b/rt/transports/http/src/test/java/org/apache/cxf/transport/https/SSLUtilsNamedGroupsTest.java
new file mode 100644
index 00000000000..1fd3252c952
--- /dev/null
+++
b/rt/transports/http/src/test/java/org/apache/cxf/transport/https/SSLUtilsNamedGroupsTest.java
@@ -0,0 +1,112 @@
+/**
+ * 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.cxf.transport.https;
+
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLSocket;
+
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
+import org.apache.cxf.configuration.jsse.TLSServerParameters;
+
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * The configured TLS named groups reach the SSLEngine / SSLSocket that CXF
creates (SunJSSE, JDK 20+).
+ */
+public class SSLUtilsNamedGroupsTest {
+ private static final List<String> GROUPS = Arrays.asList("secp384r1",
"x25519");
+
+ @BeforeClass
+ public static void requireNamedGroupsApi() {
+ Assume.assumeTrue("SSLParameters.setNamedGroups() requires JDK 20+",
hasNamedGroupsApi());
+ }
+
+ private static boolean hasNamedGroupsApi() {
+ try {
+ SSLParameters.class.getMethod("setNamedGroups", String[].class);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+
+ @Test
+ public void testApplyToEngine() throws Exception {
+ SSLEngine engine = SSLContext.getDefault().createSSLEngine();
+ SSLUtils.applyNamedGroups(engine, GROUPS);
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(engine.getSSLParameters()));
+ }
+
+ @Test
+ public void testNothingConfiguredLeavesEngineUnchanged() throws Exception {
+ SSLEngine engine = SSLContext.getDefault().createSSLEngine();
+ String[] before = SSLUtils.getNamedGroups(engine.getSSLParameters());
+ SSLUtils.applyNamedGroups(engine, null);
+ SSLUtils.applyNamedGroups(engine, List.of());
+ assertArrayEquals(before,
SSLUtils.getNamedGroups(engine.getSSLParameters()));
+ }
+
+ @Test
+ public void testApplyToSocket() throws Exception {
+ try (SSLSocket socket = (SSLSocket)
SSLContext.getDefault().getSocketFactory().createSocket()) {
+ SSLUtils.applyNamedGroups(socket, GROUPS);
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(socket.getSSLParameters()));
+ }
+ }
+
+ @Test
+ public void testServerEngine() throws Exception {
+ TLSServerParameters params = new TLSServerParameters();
+ params.setNamedGroups(GROUPS);
+ SSLEngine engine = SSLUtils.createServerSSLEngine(params);
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(engine.getSSLParameters()));
+ }
+
+ @Test
+ public void testClientEngine() throws Exception {
+ TLSClientParameters params = new TLSClientParameters();
+ params.setNamedGroups(GROUPS);
+ SSLEngine engine = SSLUtils.createClientSSLEngine(params, "localhost",
443);
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(engine.getSSLParameters()));
+ }
+
+ @Test
+ public void testSocketFactoryWrapper() throws Exception {
+ SSLSocketFactoryWrapper factory = new SSLSocketFactoryWrapper(
+ SSLContext.getDefault().getSocketFactory(), null, null, GROUPS);
+ try (ServerSocket server = new ServerSocket(0, 1,
InetAddress.getLoopbackAddress());
+ Socket plain = new Socket(InetAddress.getLoopbackAddress(),
server.getLocalPort());
+ SSLSocket socket = (SSLSocket) factory.createSocket(plain,
"localhost", server.getLocalPort(), true)) {
+ assertArrayEquals(GROUPS.toArray(),
SSLUtils.getNamedGroups(socket.getSSLParameters()));
+ }
+ }
+}
diff --git
a/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/http2/NamedGroupsBookServer.java
b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/http2/NamedGroupsBookServer.java
new file mode 100644
index 00000000000..d2bc25a64b2
--- /dev/null
+++
b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/http2/NamedGroupsBookServer.java
@@ -0,0 +1,32 @@
+/**
+ * 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.cxf.systest.http_undertow.http2;
+
+public class NamedGroupsBookServer extends AbstractBookServerHttp2 {
+ public static final String PORT =
allocatePort(NamedGroupsBookServer.class);
+
+ public NamedGroupsBookServer() {
+ this(PORT);
+ }
+
+ public NamedGroupsBookServer(String port) {
+ super(port,
"org/apache/cxf/systest/http_undertow/http2/server-named-groups.xml", "https");
+ }
+}
diff --git
a/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/http2/UndertowNamedGroupsTest.java
b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/http2/UndertowNamedGroupsTest.java
new file mode 100644
index 00000000000..a37befc0778
--- /dev/null
+++
b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/http2/UndertowNamedGroupsTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.cxf.systest.http_undertow.http2;
+
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.util.List;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.transport.https.SSLUtils;
+
+import org.junit.AfterClass;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * The TLS named groups configured for an Undertow server endpoint are used in
the handshake. The test JVM
+ * offers both secp256r1 and secp384r1 (jdk.tls.namedGroups); the endpoint
accepts only secp384r1.
+ */
+public class UndertowNamedGroupsTest extends AbstractBusClientServerTestBase {
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ Assume.assumeTrue("SSLParameters.setNamedGroups() requires JDK 20+",
hasNamedGroupsApi());
+ assertTrue("Server failed to launch",
launchServer(NamedGroupsBookServer.class, true));
+ }
+
+ @AfterClass
+ public static void cleanup() throws Exception {
+ stopAllServers();
+ }
+
+ @Test
+ public void testServerAcceptsOnlyConfiguredGroups() throws Exception {
+ int port = Integer.parseInt(NamedGroupsBookServer.PORT);
+ assertTrue(handshake(port, "secp384r1"));
+ assertFalse(handshake(port, "secp256r1"));
+ }
+
+ private static boolean handshake(int port, String group) throws Exception {
+ KeyStore ts = KeyStore.getInstance("JKS");
+ try (InputStream is = UndertowNamedGroupsTest.class.getClassLoader()
+ .getResourceAsStream("keys/Truststore.jks")) {
+ ts.load(is, "password".toCharArray());
+ }
+ TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(ts);
+ SSLContext ctx = SSLContext.getInstance("TLS");
+ ctx.init(null, tmf.getTrustManagers(), null);
+ try (SSLSocket socket = (SSLSocket)
ctx.getSocketFactory().createSocket("localhost", port)) {
+ socket.setSoTimeout(10000);
+ SSLUtils.applyNamedGroups(socket, List.of(group));
+ socket.startHandshake();
+ return true;
+ } catch (java.io.IOException e) {
+ return false;
+ }
+ }
+
+ private static boolean hasNamedGroupsApi() {
+ try {
+ SSLParameters.class.getMethod("setNamedGroups", String[].class);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+}
diff --git
a/systests/transport-undertow/src/test/resources/org/apache/cxf/systest/http_undertow/http2/server-named-groups.xml
b/systests/transport-undertow/src/test/resources/org/apache/cxf/systest/http_undertow/http2/server-named-groups.xml
new file mode 100644
index 00000000000..14476457ffa
--- /dev/null
+++
b/systests/transport-undertow/src/test/resources/org/apache/cxf/systest/http_undertow/http2/server-named-groups.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xmlns:http-undertow="http://cxf.apache.org/transports/http-undertow/configuration"
+ xmlns:sec="http://cxf.apache.org/configuration/security"
+
xsi:schemaLocation="http://cxf.apache.org/transports/http-undertow/configuration
+ http://cxf.apache.org/schemas/configuration/http-undertow.xsd
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://cxf.apache.org/configuration/security
+ http://cxf.apache.org/schemas/configuration/security.xsd">
+ <bean
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"/>
+ <http-undertow:engine-factory bus="cxf">
+ <http-undertow:engine
port="${testutil.ports.org.apache.cxf.systest.http_undertow.http2.NamedGroupsBookServer}">
+ <http-undertow:tlsServerParameters>
+ <sec:keyManagers keyPassword="password">
+ <sec:keyStore type="jks" password="password"
resource="keys/Bethal.jks"/>
+ </sec:keyManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ <sec:namedGroups>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
+ </http-undertow:tlsServerParameters>
+ </http-undertow:engine>
+ </http-undertow:engine-factory>
+</beans>
\ No newline at end of file
diff --git
a/systests/transports/src/test/java/org/apache/cxf/systest/https/namedgroups/NamedGroupsTest.java
b/systests/transports/src/test/java/org/apache/cxf/systest/https/namedgroups/NamedGroupsTest.java
new file mode 100644
index 00000000000..52cfdf5a57a
--- /dev/null
+++
b/systests/transports/src/test/java/org/apache/cxf/systest/https/namedgroups/NamedGroupsTest.java
@@ -0,0 +1,256 @@
+/**
+ * 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.cxf.systest.https.namedgroups;
+
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.http.HttpClient;
+import java.security.KeyStore;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManagerFactory;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.https.SSLUtils;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.hello_world.Greeter;
+import org.apache.hello_world.services.SOAPService;
+
+import org.junit.AfterClass;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * The TLS named groups configured for a server endpoint (Spring XML) and for
a client conduit are used in
+ * the handshake. The test JVM offers both secp256r1 and secp384r1
(jdk.tls.namedGroups), so a handshake
+ * only fails when the per-endpoint setting is applied.
+ */
+public class NamedGroupsTest extends AbstractBusClientServerTestBase {
+ static final String PORT = allocatePort(NamedGroupsServer.class);
+
+ public static class NamedGroupsServer extends AbstractBusTestServerBase {
+ @Override
+ protected void run() {
+ URL busFile =
NamedGroupsServer.class.getResource("named-groups-server.xml");
+ Bus busLocal = new SpringBusFactory().createBus(busFile);
+ BusFactory.setDefaultBus(busLocal);
+ setBus(busLocal);
+ }
+ }
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ Assume.assumeTrue("SSLParameters.setNamedGroups() requires JDK 20+",
hasNamedGroupsApi());
+ assertTrue("Server failed to launch",
launchServer(NamedGroupsServer.class, true));
+ }
+
+ @AfterClass
+ public static void cleanup() throws Exception {
+ stopAllServers();
+ }
+
+ @Test
+ public void testServerAcceptsOnlyConfiguredGroups() throws Exception {
+ assertTrue(handshake(Integer.parseInt(PORT), "secp384r1"));
+ assertFalse(handshake(Integer.parseInt(PORT), "secp256r1"));
+ }
+
+ @Test
+ public void testServerEndpointCall() throws Exception {
+ assertEquals("Hello Kitty", greetMe(PORT, null));
+ assertEquals("Hello Kitty", greetMe(PORT, Arrays.asList("secp384r1")));
+ }
+
+ @Test
+ public void testClientOffersOnlyConfiguredGroups() throws Exception {
+ Assume.assumeTrue("the HttpClient of this JDK ignores named groups
(JDK 26+ required)",
+ isForceURLConnection() || httpClientKeepsNamedGroups());
+ try (SingleGroupServer server = new SingleGroupServer("secp256r1")) {
+ callIgnoringResponse(server.getPort(), Arrays.asList("secp384r1"));
+ assertFalse("a client restricted to secp384r1 must not complete a
handshake with a secp256r1-only server",
+ server.handshakeResult());
+ }
+ try (SingleGroupServer server = new SingleGroupServer("secp256r1")) {
+ callIgnoringResponse(server.getPort(), Arrays.asList("secp256r1",
"secp384r1"));
+ assertTrue(server.handshakeResult());
+ }
+ }
+
+ private String greetMe(String port, List<String> groups) throws Exception {
+ Bus bus = BusFactory.newInstance().createBus();
+ BusFactory.setThreadDefaultBus(bus);
+ try {
+ Greeter greeter = greeter(port, groups);
+ String result = greeter.greetMe("Kitty");
+ ((java.io.Closeable) greeter).close();
+ return result;
+ } finally {
+ bus.shutdown(true);
+ }
+ }
+
+ private void callIgnoringResponse(int port, List<String> groups) throws
Exception {
+ Bus bus = BusFactory.newInstance().createBus();
+ BusFactory.setThreadDefaultBus(bus);
+ try {
+ Greeter greeter = greeter(String.valueOf(port), groups);
+ try {
+ greeter.greetMe("Kitty");
+ fail("the test server does not speak HTTP");
+ } catch (Exception expected) {
+ // the server only does the handshake
+ }
+ ((java.io.Closeable) greeter).close();
+ } finally {
+ bus.shutdown(true);
+ }
+ }
+
+ private Greeter greeter(String port, List<String> groups) throws Exception
{
+ SOAPService service = new SOAPService(SOAPService.WSDL_LOCATION,
+ new QName("http://apache.org/hello_world/services",
"SOAPService"));
+ Greeter greeter = service.getHttpsPort();
+ updateAddressPort(greeter, port);
+ HTTPConduit conduit = (HTTPConduit)
ClientProxy.getClient(greeter).getConduit();
+ TLSClientParameters tls = new TLSClientParameters();
+ tls.setDisableCNCheck(true);
+ tls.setTrustManagers(trustManagerFactory().getTrustManagers());
+ if (groups != null) {
+ tls.setNamedGroups(groups);
+ }
+ conduit.setTlsClientParameters(tls);
+ HTTPClientPolicy policy = new HTTPClientPolicy();
+ policy.setConnectionTimeout(10000);
+ policy.setReceiveTimeout(10000);
+ conduit.setClient(policy);
+ return greeter;
+ }
+
+ /** A raw TLS handshake offering only the given group. */
+ private static boolean handshake(int port, String group) throws Exception {
+ SSLContext ctx = SSLContext.getInstance("TLS");
+ ctx.init(null, trustManagerFactory().getTrustManagers(), null);
+ try (SSLSocket socket = (SSLSocket)
ctx.getSocketFactory().createSocket("localhost", port)) {
+ socket.setSoTimeout(10000);
+ SSLUtils.applyNamedGroups(socket, List.of(group));
+ socket.startHandshake();
+ return true;
+ } catch (java.io.IOException e) {
+ return false;
+ }
+ }
+
+ private static TrustManagerFactory trustManagerFactory() throws Exception {
+ KeyStore ts = KeyStore.getInstance("JKS");
+ try (InputStream is =
NamedGroupsTest.class.getClassLoader().getResourceAsStream("keys/Truststore.jks"))
{
+ ts.load(is, "password".toCharArray());
+ }
+ TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(ts);
+ return tmf;
+ }
+
+ private static boolean hasNamedGroupsApi() {
+ try {
+ SSLParameters.class.getMethod("setNamedGroups", String[].class);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+
+ private static boolean isForceURLConnection() {
+ return
Boolean.getBoolean("org.apache.cxf.transport.http.forceURLConnection");
+ }
+
+ private static boolean httpClientKeepsNamedGroups() throws Exception {
+ SSLParameters params = new SSLParameters();
+ SSLUtils.applyNamedGroups(params, List.of("secp384r1"));
+ HttpClient client =
HttpClient.newBuilder().sslContext(SSLContext.getDefault()).sslParameters(params).build();
+ return SSLUtils.getNamedGroups(client.sslParameters()) != null;
+ }
+
+ /** A TLS server that accepts a single named group and reports whether the
first handshake completed. */
+ private static final class SingleGroupServer implements AutoCloseable {
+ private final SSLServerSocket serverSocket;
+ private final CompletableFuture<Boolean> result = new
CompletableFuture<>();
+
+ SingleGroupServer(String group) throws Exception {
+ KeyStore ks = KeyStore.getInstance("JKS");
+ try (InputStream is =
NamedGroupsTest.class.getClassLoader().getResourceAsStream("keys/Bethal.jks")) {
+ ks.load(is, "password".toCharArray());
+ }
+ KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmf.init(ks, "password".toCharArray());
+ SSLContext ctx = SSLContext.getInstance("TLS");
+ ctx.init(kmf.getKeyManagers(), null, null);
+ serverSocket = (SSLServerSocket) ctx.getServerSocketFactory()
+ .createServerSocket(0, 1, InetAddress.getLoopbackAddress());
+ Thread t = new Thread(() -> {
+ try (SSLSocket s = (SSLSocket) serverSocket.accept()) {
+ s.setSoTimeout(10000);
+ SSLUtils.applyNamedGroups(s, List.of(group));
+ s.startHandshake();
+ result.complete(true);
+ } catch (Exception e) {
+ result.complete(false);
+ }
+ }, "single-group-tls-server");
+ t.setDaemon(true);
+ t.start();
+ }
+
+ int getPort() {
+ return serverSocket.getLocalPort();
+ }
+
+ boolean handshakeResult() throws Exception {
+ return result.get(30, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void close() throws Exception {
+ serverSocket.close();
+ }
+ }
+}
diff --git
a/systests/transports/src/test/resources/org/apache/cxf/systest/https/namedgroups/named-groups-server.xml
b/systests/transports/src/test/resources/org/apache/cxf/systest/https/namedgroups/named-groups-server.xml
new file mode 100644
index 00000000000..4be55955bd6
--- /dev/null
+++
b/systests/transports/src/test/resources/org/apache/cxf/systest/https/namedgroups/named-groups-server.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
+ xmlns:sec="http://cxf.apache.org/configuration/security"
+ xmlns:cxf="http://cxf.apache.org/core"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://cxf.apache.org/jaxws
+ http://cxf.apache.org/schemas/jaxws.xsd
+ http://cxf.apache.org/core
+ http://cxf.apache.org/schemas/core.xsd
+ http://cxf.apache.org/transports/http-jetty/configuration
+ http://cxf.apache.org/schemas/configuration/http-jetty.xsd
+ http://cxf.apache.org/configuration/security
+ http://cxf.apache.org/schemas/configuration/security.xsd">
+
+ <bean
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"/>
+
+ <cxf:bus>
+ <cxf:features>
+ <bean class="org.apache.cxf.ext.logging.LoggingFeature"/>
+ </cxf:features>
+ </cxf:bus>
+
+ <httpj:engine-factory id="named-groups-tls-settings">
+ <httpj:engine port="${testutil.ports.NamedGroupsServer}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="password">
+ <sec:keyStore type="JKS" password="password"
resource="keys/Bethal.jks"/>
+ </sec:keyManagers>
+ <sec:trustManagers>
+ <sec:keyStore type="JKS" password="password"
resource="keys/Truststore.jks"/>
+ </sec:trustManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ <sec:namedGroups>
+ <sec:namedGroup>secp384r1</sec:namedGroup>
+ </sec:namedGroups>
+ </httpj:tlsServerParameters>
+ </httpj:engine>
+ </httpj:engine-factory>
+
+ <jaxws:endpoint xmlns:e="http://apache.org/hello_world/services"
+ xmlns:s="http://apache.org/hello_world/services"
+ id="NamedGroupsServer"
+ implementor="org.apache.cxf.systest.http.GreeterImpl"
+
address="https://localhost:${testutil.ports.NamedGroupsServer}/SoapContext/HttpsPort"
+ serviceName="s:SOAPService"
+ endpointName="e:HttpsPort"
+ depends-on="named-groups-tls-settings"/>
+
+</beans>