You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2024/08/15 17:57:58 UTC

(cxf) branch 3.5.x-fixes updated: [CXF-9047]http-undertow transport: enable to specify CipherSuites

This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.5.x-fixes by this push:
     new 10e8b60278 [CXF-9047]http-undertow transport: enable to specify CipherSuites
10e8b60278 is described below

commit 10e8b602787e478c2ef207e80305a1e43138fe68
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Thu Aug 15 13:54:17 2024 -0400

    [CXF-9047]http-undertow transport: enable to specify CipherSuites
    
    (cherry picked from commit d8f989cb55a66362b8d969823d7f2f84b88d2d18)
    (cherry picked from commit 26f0794116384012555f9a81276e31b9dff985c2)
    (cherry picked from commit 2491e5b909a9895ab35a2d5d3d394c989c5e9449)
---
 .../http_undertow/UndertowHTTPDestination.java     | 13 ++++++++++-
 .../http_undertow/UndertowHTTPServerEngine.java    | 27 +++++++++++++++++++++-
 .../UndertowHTTPServerEngineFactory.java           | 17 ++++++++++++--
 3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPDestination.java b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPDestination.java
index 63256dd012..2b45323f14 100644
--- a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPDestination.java
+++ b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPDestination.java
@@ -35,9 +35,12 @@ import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.jsse.TLSServerParameters;
+import org.apache.cxf.configuration.security.CertificateConstraintsType;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
 import org.apache.cxf.transport.servlet.ServletDestination;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 
@@ -104,7 +107,15 @@ public class UndertowHTTPDestination extends ServletDestination {
             engine = serverEngineFactory.
                 createUndertowHTTPServerEngine(nurl.getHost(), nurl.getPort(), nurl.getProtocol());
         }
-
+        assert engine != null;
+        TLSServerParameters serverParameters = engine.getTlsServerParameters();
+        if (serverParameters != null && serverParameters.getCertConstraints() != null) {
+            CertificateConstraintsType constraints = serverParameters.getCertConstraints();
+            if (constraints != null) {
+                certConstraints = CertConstraintsJaxBUtils.createCertConstraints(constraints);
+            }
+        }
+        
         // When configuring for "http", however, it is still possible that
         // Spring configuration has configured the port for https.
         if (!nurl.getProtocol().equals(engine.getProtocol())) {
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 d9c375e04a..42eb0ce12c 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
@@ -40,6 +40,7 @@ import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.common.util.SystemPropertyAction;
+import org.apache.cxf.configuration.jsse.SSLUtils;
 import org.apache.cxf.configuration.jsse.TLSServerParameters;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.transport.HttpUriMapper;
@@ -129,6 +130,8 @@ public class UndertowHTTPServerEngine implements ServerEngine, HttpServerEngineS
     private org.apache.cxf.transport.http_undertow.ThreadingParameters threadingParameters;
 
     private List<CXFUndertowHttpHandler> handlers;
+    
+    private String[] includedCipherSuites;
 
     public UndertowHTTPServerEngine(String host, int port) {
         this.host = host;
@@ -177,7 +180,12 @@ public class UndertowHTTPServerEngine implements ServerEngine, HttpServerEngineS
             if (handler.isContextMatchExact()) {
                 path.addExactPath(url.getPath(), handler);
             } else {
-                path.addPrefixPath(url.getPath(), handler);
+                String urlPath = url.getPath();
+                if (urlPath.isEmpty()) {
+                    urlPath = "/";
+                }
+                
+                path.addPrefixPath(urlPath, handler);
             }
 
         }
@@ -312,10 +320,15 @@ public class UndertowHTTPServerEngine implements ServerEngine, HttpServerEngineS
             builder = builder.setSocketOption(Options.SSL_CLIENT_AUTH_MODE, SslClientAuthMode.REQUIRED);
         }
         if (this.tlsServerParameters != null && this.tlsServerParameters.getClientAuthentication() != null
+            && this.tlsServerParameters.getClientAuthentication().isSetWant()
             && this.tlsServerParameters.getClientAuthentication().isWant()
             && !this.tlsServerParameters.getClientAuthentication().isRequired()) {
             builder = builder.setSocketOption(Options.SSL_CLIENT_AUTH_MODE, SslClientAuthMode.REQUESTED);
         }
+        if (includedCipherSuites != null) {
+            builder = builder.setSocketOption(Options.SSL_ENABLED_CIPHER_SUITES, 
+                                              Sequence.of(includedCipherSuites));
+        }
         return builder;
     }
 
@@ -513,6 +526,18 @@ public class UndertowHTTPServerEngine implements ServerEngine, HttpServerEngineS
         context.init(keyManagers,
                      tlsServerParameters.getTrustManagers(),
                      tlsServerParameters.getSecureRandom());
+        
+        // Set the CipherSuites
+        final String[] supportedCipherSuites =
+            SSLUtils.getServerSupportedCipherSuites(context);
+
+        
+        includedCipherSuites =
+            SSLUtils.getCiphersuitesToInclude(tlsServerParameters.getCipherSuites(),
+                                              tlsServerParameters.getCipherSuitesFilter(),
+                                              context.getServerSocketFactory().getDefaultCipherSuites(),
+                                              supportedCipherSuites,
+                                              LOG);
 
         return context;
     }
diff --git a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngineFactory.java b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngineFactory.java
index ebc1d28fc1..a1ce2d00d5 100644
--- a/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngineFactory.java
+++ b/rt/transports/http-undertow/src/main/java/org/apache/cxf/transport/http_undertow/UndertowHTTPServerEngineFactory.java
@@ -39,6 +39,7 @@ import org.apache.cxf.configuration.jsse.TLSServerParameters;
 import org.apache.cxf.management.InstrumentationManager;
 
 
+
 /**
  * This Bus Extension handles the configuration of network port
  * numbers for use with "http" or "https". This factory
@@ -250,14 +251,19 @@ public class UndertowHTTPServerEngineFactory {
      *        server will listen on all local addresses.
      * @param port listen port for server
      * @param protocol "http" or "https"
+     * @param id The key to reference into the tlsParametersMap. Can be null.
      * @return
      * @throws GeneralSecurityException
      * @throws IOException
      */
     public synchronized UndertowHTTPServerEngine createUndertowHTTPServerEngine(String host, int port,
-        String protocol) throws GeneralSecurityException, IOException {
+        String protocol, String id) throws GeneralSecurityException, IOException {
         LOG.fine("Creating Undertow HTTP Server Engine for port " + port + ".");
-        UndertowHTTPServerEngine ref = getOrCreate(this, host, port, null);
+        TLSServerParameters tlsParameters = null;
+        if (id != null && tlsParametersMap != null && tlsParametersMap.containsKey(id)) {
+            tlsParameters = tlsParametersMap.get(id);
+        }
+        UndertowHTTPServerEngine ref = getOrCreate(this, host, port, tlsParameters);
         // checking the protocol
         if (!protocol.equals(ref.getProtocol())) {
             throw new IOException("Protocol mismatch for port " + port + ": "
@@ -288,6 +294,13 @@ public class UndertowHTTPServerEngineFactory {
         String protocol) throws GeneralSecurityException, IOException {
         return createUndertowHTTPServerEngine(null, port, protocol);
     }
+    
+    
+    public synchronized UndertowHTTPServerEngine createUndertowHTTPServerEngine(String host, int port,
+                                                                          String protocol)
+        throws GeneralSecurityException, IOException {
+        return createUndertowHTTPServerEngine(host, port, protocol, null);
+    }
 
     /**
      * This method removes the Server Engine from the port map and stops it.