You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2014/12/18 15:43:37 UTC
cxf git commit: Added some hostname verification tests
Repository: cxf
Updated Branches:
refs/heads/master 9d1aad519 -> 33fcf44d3
Added some hostname verification tests
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/33fcf44d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/33fcf44d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/33fcf44d
Branch: refs/heads/master
Commit: 33fcf44d3dbaa1d2d1162169f6004dfccf89d2fe
Parents: 9d1aad5
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Thu Dec 18 14:42:56 2014 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Thu Dec 18 14:43:07 2014 +0000
----------------------------------------------------------------------
.../hostname/HostnameVerificationServer.java | 47 ++++++
.../hostname/HostnameVerificationTest.java | 167 +++++++++++++++++++
.../src/test/resources/keys/subjalt.jks | Bin 0 -> 8891 bytes
.../systest/https/hostname/hostname-client.xml | 34 ++++
.../systest/https/hostname/hostname-server.xml | 109 ++++++++++++
5 files changed, 357 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/33fcf44d/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationServer.java
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationServer.java b/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationServer.java
new file mode 100644
index 0000000..426cb04
--- /dev/null
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationServer.java
@@ -0,0 +1,47 @@
+/**
+ * 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.hostname;
+
+import java.net.URL;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class HostnameVerificationServer extends AbstractBusTestServerBase {
+
+ public HostnameVerificationServer() {
+
+ }
+
+ protected void run() {
+ URL busFile = HostnameVerificationServer.class.getResource("hostname-server.xml");
+ Bus busLocal = new SpringBusFactory().createBus(busFile);
+ BusFactory.setDefaultBus(busLocal);
+ setBus(busLocal);
+
+ try {
+ new HostnameVerificationServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/33fcf44d/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationTest.java
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationTest.java
new file mode 100644
index 0000000..3769ecb
--- /dev/null
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/https/hostname/HostnameVerificationTest.java
@@ -0,0 +1,167 @@
+/**
+ * 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.hostname;
+
+import java.net.URL;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.hello_world.Greeter;
+import org.apache.hello_world.services.SOAPService;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * A set of tests for hostname verification, where the hostname in question is "localhost".
+ *
+ * Keys created via something like:
+ * keytool -genkey -validity 3650 -alias subjalt -keyalg RSA -keystore subjalt.jks
+ * -dname "CN=Colm,OU=WSS4J,O=Apache,L=Dublin,ST=Leinster,C=IE" -ext SAN=DNS:localhost
+ */
+public class HostnameVerificationTest extends AbstractBusClientServerTestBase {
+ static final String PORT = allocatePort(HostnameVerificationServer.class);
+ static final String PORT2 = allocatePort(HostnameVerificationServer.class, 2);
+ static final String PORT3 = allocatePort(HostnameVerificationServer.class, 3);
+ static final String PORT4 = allocatePort(HostnameVerificationServer.class, 4);
+ static final String PORT5 = allocatePort(HostnameVerificationServer.class, 5);
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue(
+ "Server failed to launch",
+ // run the server in the same process
+ // set this to false to fork
+ launchServer(HostnameVerificationServer.class, true)
+ );
+ }
+
+ @AfterClass
+ public static void cleanup() throws Exception {
+ stopAllServers();
+ }
+
+ // Subject Alternative Name matches (but not the CN)
+ @org.junit.Test
+ public void testSubjectAlternativeNameMatch() throws Exception {
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = HostnameVerificationTest.class.getResource("hostname-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);
+
+ updateAddressPort(port, PORT);
+
+ assertEquals(port.greetMe("Kitty"), "Hello Kitty");
+
+ ((java.io.Closeable)port).close();
+ bus.shutdown(true);
+ }
+
+ // Subject Alternative Name does not match (but the CN does - still an error)
+ @org.junit.Test
+ public void testSubjectAlternativeNameNoMatch() throws Exception {
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = HostnameVerificationTest.class.getResource("hostname-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);
+
+ updateAddressPort(port, PORT2);
+
+ try {
+ port.greetMe("Kitty");
+ fail("Failure expected on a non-matching subject alternative name");
+ } catch (Exception ex) {
+ // expected
+ }
+
+ ((java.io.Closeable)port).close();
+ bus.shutdown(true);
+ }
+
+ // No Subject Alternative Name, but the CN matches
+ @org.junit.Test
+ public void testNoSubjectAlternativeNameCNMatch() throws Exception {
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = HostnameVerificationTest.class.getResource("hostname-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);
+
+ updateAddressPort(port, PORT3);
+
+ assertEquals(port.greetMe("Kitty"), "Hello Kitty");
+
+ ((java.io.Closeable)port).close();
+ bus.shutdown(true);
+ }
+
+ // No Subject Alternative Name, no matching CN
+ @org.junit.Test
+ public void testNoSubjectAlternativeNameNoCNMatch() throws Exception {
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = HostnameVerificationTest.class.getResource("hostname-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);
+
+ updateAddressPort(port, PORT4);
+
+ try {
+ port.greetMe("Kitty");
+ fail("Failure expected with no matching Subject Alt Name or CN");
+ } catch (Exception ex) {
+ // expected
+ }
+
+ ((java.io.Closeable)port).close();
+ bus.shutdown(true);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/33fcf44d/systests/transports/src/test/resources/keys/subjalt.jks
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/resources/keys/subjalt.jks b/systests/transports/src/test/resources/keys/subjalt.jks
new file mode 100644
index 0000000..fefac18
Binary files /dev/null and b/systests/transports/src/test/resources/keys/subjalt.jks differ
http://git-wip-us.apache.org/repos/asf/cxf/blob/33fcf44d/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-client.xml
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-client.xml b/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-client.xml
new file mode 100644
index 0000000..6776a6a
--- /dev/null
+++ b/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-client.xml
@@ -0,0 +1,34 @@
+<?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="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xmlns:p="http://cxf.apache.org/policy" xmlns:sec="http://cxf.apache.org/configuration/security" 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/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/policy http://cxf.apache.org/schemas/poli
cy.xsd">
+
+ <cxf:bus>
+ <cxf:features>
+ <cxf:logging/>
+ </cxf:features>
+ </cxf:bus>
+ <http:conduit name="https://localhost:.*">
+ <http:tlsClientParameters>
+ <sec:trustManagers>
+ <sec:keyStore type="jks" password="security" resource="keys/subjalt.jks"/>
+ </sec:trustManagers>
+ </http:tlsClientParameters>
+ </http:conduit>
+</beans>
http://git-wip-us.apache.org/repos/asf/cxf/blob/33fcf44d/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-server.xml
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-server.xml b/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-server.xml
new file mode 100644
index 0000000..21101e0
--- /dev/null
+++ b/systests/transports/src/test/resources/org/apache/cxf/systest/https/hostname/hostname-server.xml
@@ -0,0 +1,109 @@
+<?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:http="http://cxf.apache.org/transports/http/configuration" 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" xmlns:p="http://cxf.apache.org/policy" 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/policy http://cxf.apache.org/schemas/policy.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apa
che.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.beans.factory.config.PropertyPlaceholderConfigurer"/>
+ <cxf:bus>
+ <cxf:features>
+ <cxf:logging/>
+ </cxf:features>
+ </cxf:bus>
+
+ <httpj:engine-factory id="subject-alt-match-settings">
+ <httpj:engine port="${testutil.ports.HostnameVerificationServer}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="security">
+ <sec:keyStore type="jks" password="security" resource="keys/subjalt.jks"/>
+ </sec:keyManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ <sec:certAlias>subjaltmatch</sec:certAlias>
+ </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="SubjectAltMatch"
+ implementor="org.apache.cxf.systest.http.GreeterImpl"
+ address="https://localhost:${testutil.ports.HostnameVerificationServer}/SoapContext/HttpsPort"
+ serviceName="s:SOAPService"
+ endpointName="e:HttpsPort" depends-on="subject-alt-match-settings"/>
+
+
+ <httpj:engine-factory id="subject-alt-nomatch-settings">
+ <httpj:engine port="${testutil.ports.HostnameVerificationServer.2}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="security">
+ <sec:keyStore type="jks" password="security" resource="keys/subjalt.jks"/>
+ </sec:keyManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ <sec:certAlias>subjaltnomatch</sec:certAlias>
+ </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="SubjectAltNoMatch"
+ implementor="org.apache.cxf.systest.http.GreeterImpl"
+ address="https://localhost:${testutil.ports.HostnameVerificationServer.2}/SoapContext/HttpsPort"
+ serviceName="s:SOAPService"
+ endpointName="e:HttpsPort" depends-on="subject-alt-nomatch-settings"/>
+
+
+ <httpj:engine-factory id="no-subject-alt-cn-match-settings">
+ <httpj:engine port="${testutil.ports.HostnameVerificationServer.3}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="security">
+ <sec:keyStore type="jks" password="security" resource="keys/subjalt.jks"/>
+ </sec:keyManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ <sec:certAlias>nosubjaltcnmatch</sec:certAlias>
+ </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="NoSubjectAltCNMatch"
+ implementor="org.apache.cxf.systest.http.GreeterImpl"
+ address="https://localhost:${testutil.ports.HostnameVerificationServer.3}/SoapContext/HttpsPort"
+ serviceName="s:SOAPService"
+ endpointName="e:HttpsPort" depends-on="no-subject-alt-cn-match-settings"/>
+
+ <httpj:engine-factory id="no-subject-alt-no-cn-match-settings">
+ <httpj:engine port="${testutil.ports.HostnameVerificationServer.4}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="security">
+ <sec:keyStore type="jks" password="security" resource="keys/subjalt.jks"/>
+ </sec:keyManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ <sec:certAlias>nosubjaltnocnmatch</sec:certAlias>
+ </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="NoSubjectAltNoCNMatch"
+ implementor="org.apache.cxf.systest.http.GreeterImpl"
+ address="https://localhost:${testutil.ports.HostnameVerificationServer.4}/SoapContext/HttpsPort"
+ serviceName="s:SOAPService"
+ endpointName="e:HttpsPort" depends-on="no-subject-alt-no-cn-match-settings"/>
+</beans>