Author: markt
Date: Fri Feb 11 12:08:55 2011
New Revision: 1069766
URL: http://svn.apache.org/viewvc?rev=1069766&view=rev
Log:
Add unit test that demonstrates use of a custom SSL implementation that extends
the default JSSE implementation.
Added:
tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java
tomcat/trunk/test/org/apache/tomcat/util/net/jsse/
tomcat/trunk/test/org/apache/tomcat/util/net/jsse/TesterBug50640SslImpl.java
Added: tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java?rev=1069766&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java Fri Feb 11
12:08:55 2011
@@ -0,0 +1,82 @@
+/*
+ * 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.tomcat.util.net;
+
+import java.io.File;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.net.jsse.TesterBug50640SslImpl;
+
+/**
+ * Requires test.keystore (checked in), generated with:
+ * keytool -genkey -alias tomcat -keyalg RSA
+ * pass: changeit
+ * CN: localhost ( for hostname validation )
+ */
+public class TestCustomSsl extends TomcatBaseTest {
+
+ public void testSimpleSsl() throws Exception {
+ // Install the all-trusting trust manager so https:// works
+ // with unsigned certs.
+
+ try {
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, TesterSupport.TRUST_ALL_CERTS,
+ new java.security.SecureRandom());
+ javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(
+ sc.getSocketFactory());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Tomcat tomcat = getTomcatInstance();
+ Connector connector = tomcat.getConnector();
+ if (connector.getProtocol().indexOf("Apr") > -1) {
+ // This test is only for JSSE based SSL connectors
+ return;
+ }
+
+ connector.setProperty("sslImplemenationName",
+ "org.apache.tomcat.util.net.jsse.TesterBug50640SslImpl");
+ connector.setProperty(TesterBug50640SslImpl.PROPERTY_NAME,
+ TesterBug50640SslImpl.PROPERTY_VALUE);
+
+ connector.setProperty("sslProtocol", "tls");
+
+ File keystoreFile =
+ new File("test/org/apache/catalina/startup/test.keystore");
+ connector.setAttribute(
+ "keystoreFile", keystoreFile.getAbsolutePath());
+
+ connector.setSecure(true);
+ connector.setProperty("SSLEnabled", "true");
+
+ File appDir = new File(getBuildDirectory(), "webapps/examples");
+ tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
+
+ tomcat.start();
+ ByteChunk res = getUrl("https://localhost:" + getPort() +
+ "/examples/servlets/servlet/HelloWorldExample");
+ assertTrue(res.toString().indexOf("<h1>Hello World!</h1>") > 0);
+ }
+
+}
Added:
tomcat/trunk/test/org/apache/tomcat/util/net/jsse/TesterBug50640SslImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/jsse/TesterBug50640SslImpl.java?rev=1069766&view=auto
==============================================================================
---
tomcat/trunk/test/org/apache/tomcat/util/net/jsse/TesterBug50640SslImpl.java
(added)
+++
tomcat/trunk/test/org/apache/tomcat/util/net/jsse/TesterBug50640SslImpl.java
Fri Feb 11 12:08:55 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.tomcat.util.net.jsse;
+
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.ServerSocketFactory;
+
+public class TesterBug50640SslImpl extends JSSEImplementation {
+
+ public static final String PROPERTY_NAME = "bug50640";
+ public static final String PROPERTY_VALUE = "pass";
+
+ @Override
+ public ServerSocketFactory getServerSocketFactory(
+ AbstractEndpoint endpoint) {
+
+ // Check the custom attribute is visible & correcly set
+ String flag = endpoint.getProperty(PROPERTY_NAME);
+ if (PROPERTY_VALUE.equals(flag)) {
+ return super.getServerSocketFactory(endpoint);
+ } else {
+ return null;
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]