Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 45a9a47a9 -> a78d9adb1
Enable protocol support for async http clients Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a78d9adb Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a78d9adb Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a78d9adb Branch: refs/heads/3.0.x-fixes Commit: a78d9adb1ee3dd63878313f3880800a7f5b579cf Parents: 45a9a47 Author: Colm O hEigeartaigh <[email protected]> Authored: Fri Dec 19 11:28:58 2014 +0000 Committer: Colm O hEigeartaigh <[email protected]> Committed: Fri Dec 19 12:08:27 2014 +0000 ---------------------------------------------------------------------- .../http/asyncclient/AsyncHTTPConduit.java | 23 ++++++++ .../cxf/systest/https/ssl3/SSLv3Test.java | 58 ++++++++++++++++++++ 2 files changed, 81 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a78d9adb/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java ---------------------------------------------------------------------- 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 57c9a42..56a677b 100644 --- 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 @@ -877,6 +877,29 @@ public class AsyncHTTPConduit extends URLConnectionHTTPConduit { SSLUtils.getSupportedCipherSuites(sslcontext), tlsClientParameters.getCipherSuitesFilter(), LOG, false); sslengine.setEnabledCipherSuites(cipherSuites); + + String protocol = tlsClientParameters.getSecureSocketProtocol() != null ? tlsClientParameters + .getSecureSocketProtocol() : "TLS"; + + String p[] = findProtocols(protocol, sslengine.getSupportedProtocols()); + if (p != null) { + sslengine.setEnabledProtocols(p); + } + } + + private String[] findProtocols(String p, String[] options) { + List<String> list = new ArrayList<String>(); + for (String s : options) { + if (s.equals(p)) { + return new String[] {p}; + } else if (s.startsWith(p)) { + list.add(s); + } + } + if (list.isEmpty()) { + return null; + } + return list.toArray(new String[list.size()]); } protected static KeyManager[] getKeyManagersWithCertAlias(TLSClientParameters tlsClientParameters, http://git-wip-us.apache.org/repos/asf/cxf/blob/a78d9adb/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java ---------------------------------------------------------------------- diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java b/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java index 834ff50..169a13d 100644 --- a/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java +++ b/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java @@ -27,6 +27,7 @@ import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; +import javax.xml.ws.BindingProvider; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBusFactory; @@ -164,6 +165,37 @@ public class SSLv3Test extends AbstractBusClientServerTestBase { } @org.junit.Test + public void testAsyncClientSSL3NotAllowed() throws Exception { + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = SSLv3Test.class.getResource("sslv3-client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL url = SOAPService.WSDL_LOCATION; + SOAPService service = new SOAPService(url, SOAPService.SERVICE); + assertNotNull("Service is null", service); + final Greeter port = service.getHttpsPort(); + assertNotNull("Port is null", port); + + // Enable Async + ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); + + updateAddressPort(port, PORT3); + + try { + port.greetMe("Kitty"); + fail("Failure expected on the client not supporting SSLv3 by default"); + } catch (Exception ex) { + // expected + } + + ((java.io.Closeable)port).close(); + bus.shutdown(true); + } + + @org.junit.Test public void testClientSSL3Allowed() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = SSLv3Test.class.getResource("sslv3-client-allow.xml"); @@ -186,6 +218,32 @@ public class SSLv3Test extends AbstractBusClientServerTestBase { bus.shutdown(true); } + @org.junit.Test + public void testAsyncClientSSL3Allowed() throws Exception { + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = SSLv3Test.class.getResource("sslv3-client-allow.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL url = SOAPService.WSDL_LOCATION; + SOAPService service = new SOAPService(url, SOAPService.SERVICE); + assertNotNull("Service is null", service); + final Greeter port = service.getHttpsPort(); + assertNotNull("Port is null", port); + + // Enable Async + ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); + + updateAddressPort(port, PORT3); + + assertEquals(port.greetMe("Kitty"), "Hello Kitty"); + + ((java.io.Closeable)port).close(); + bus.shutdown(true); + } + private static final class DisableCNCheckVerifier implements HostnameVerifier { @Override
