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 2017/03/01 15:30:41 UTC
cxf git commit: Adding OCSP test
Repository: cxf
Updated Branches:
refs/heads/master 6d7985f39 -> 3ce7f0046
Adding OCSP test
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3ce7f004
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3ce7f004
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3ce7f004
Branch: refs/heads/master
Commit: 3ce7f00461d9c868301003b5c16138c491a9ac0b
Parents: 6d7985f
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Wed Mar 1 15:30:26 2017 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Wed Mar 1 15:30:37 2017 +0000
----------------------------------------------------------------------
.../systest/https/trust/TrustManagerTest.java | 77 ++++++++++++++++++++
.../cxf/systest/https/trust/trust-server.xml | 16 ++++
2 files changed, 93 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/3ce7f004/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java
index 68a51bf..678b7af 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java
@@ -19,15 +19,28 @@
package org.apache.cxf.systest.https.trust;
+import java.io.InputStream;
+import java.net.URI;
import java.net.URL;
+import java.security.KeyStore;
+import java.security.Security;
+import java.security.cert.CertPathBuilder;
import java.security.cert.CertificateException;
+import java.security.cert.PKIXBuilderParameters;
+import java.security.cert.PKIXRevocationChecker;
+import java.security.cert.PKIXRevocationChecker.Option;
+import java.security.cert.X509CertSelector;
import java.security.cert.X509Certificate;
+import java.util.EnumSet;
+import javax.net.ssl.CertPathTrustManagerParameters;
import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
@@ -43,6 +56,7 @@ import org.junit.BeforeClass;
*/
public class TrustManagerTest extends AbstractBusClientServerTestBase {
static final String PORT = allocatePort(TrustServer.class);
+ static final String PORT2 = allocatePort(TrustServer.class, 2);
@BeforeClass
public static void startServers() throws Exception {
@@ -173,6 +187,69 @@ public class TrustManagerTest extends AbstractBusClientServerTestBase {
((java.io.Closeable)port).close();
bus.shutdown(true);
}
+
+ @org.junit.Test
+ public void testOSCPOverride() throws Exception {
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = TrustManagerTest.class.getResource("client-trust.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);
+
+ // Read truststore
+ KeyStore ts = KeyStore.getInstance("JKS");
+ try (InputStream trustStore =
+ ClassLoaderUtils.getResourceAsStream("keys/cxfca.jks", TrustManagerTest.class)) {
+ ts.load(trustStore, "password".toCharArray());
+ }
+
+ try {
+ Security.setProperty("ocsp.enable", "true");
+
+ CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
+ PKIXRevocationChecker rc = (PKIXRevocationChecker)cpb.getRevocationChecker();
+ rc.setOcspResponder(URI.create("http://localhost:12345"));
+ rc.setOptions(EnumSet.of(Option.NO_FALLBACK));
+
+ PKIXBuilderParameters param = new PKIXBuilderParameters(ts, new X509CertSelector());
+ param.setRevocationEnabled(true);
+ param.addCertPathChecker(rc);
+
+ TrustManagerFactory tmf =
+ TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(new CertPathTrustManagerParameters(param));
+
+ TLSClientParameters tlsParams = new TLSClientParameters();
+ tlsParams.setTrustManagers(tmf.getTrustManagers());
+ tlsParams.setDisableCNCheck(true);
+
+ Client client = ClientProxy.getClient(port);
+ HTTPConduit http = (HTTPConduit) client.getConduit();
+ http.setTlsClientParameters(tlsParams);
+
+ try {
+ port.greetMe("Kitty");
+ fail("Failure expected on an invalid OCSP responder URL");
+ } catch (Exception ex) {
+ // expected
+ }
+
+ } finally {
+ Security.setProperty("ocsp.enable", "false");
+ }
+
+ ((java.io.Closeable)port).close();
+ bus.shutdown(true);
+ }
public static class NoOpX509TrustManager implements X509TrustManager {
http://git-wip-us.apache.org/repos/asf/cxf/blob/3ce7f004/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/trust-server.xml
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/trust-server.xml b/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/trust-server.xml
index 436bb40..1231ee2 100644
--- a/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/trust-server.xml
+++ b/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/trust-server.xml
@@ -34,6 +34,14 @@
<sec:clientAuthentication want="false" required="false"/>
</httpj:tlsServerParameters>
</httpj:engine>
+ <httpj:engine port="${testutil.ports.TrustServer.2}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="password">
+ <sec:keyStore type="jks" password="password" resource="keys/alice.jks"/>
+ </sec:keyManagers>
+ <sec:clientAuthentication want="false" required="false"/>
+ </httpj:tlsServerParameters>
+ </httpj:engine>
</httpj:engine-factory>
<jaxws:endpoint xmlns:e="http://apache.org/hello_world/services"
@@ -43,6 +51,14 @@
address="https://localhost:${testutil.ports.TrustServer}/SoapContext/HttpsPort"
serviceName="s:SOAPService"
endpointName="e:HttpsPort" depends-on="tls-settings"/>
+
+ <jaxws:endpoint xmlns:e="http://apache.org/hello_world/services"
+ xmlns:s="http://apache.org/hello_world/services"
+ id="TrustServer2"
+ implementor="org.apache.cxf.systest.http.GreeterImpl"
+ address="https://localhost:${testutil.ports.TrustServer.2}/SoapContext/HttpsPort"
+ serviceName="s:SOAPService"
+ endpointName="e:HttpsPort" depends-on="tls-settings"/>
</beans>