From c2ac21e1e136b01493ffcd2fba8a35e8aa87d398 Mon Sep 17 00:00:00 2001
From: remm Implementation of a Valve that outputs HTML error pages. ");
sb.append(sm.getString("errorReportValve.exception"));
sb.append(" ");
@@ -229,8 +227,7 @@ public class ErrorReportValve
sb.append("
"); sb.append(sm.getString("errorReportValve.rootCause")); sb.append("
");
@@ -281,4 +278,29 @@ public class ErrorReportValve
}
+ /**
+ * Print out a partial servlet stack trace (truncating at the last
+ * occurrence of javax.servlet.).
+ */
+ protected String getPartialServletStackTrace(Throwable t) {
+ StringBuffer trace = new StringBuffer();
+ trace.append(t.toString()).append('\n');
+ StackTraceElement[] elements = t.getStackTrace();
+ int pos = elements.length;
+ for (int i = 0; i < elements.length; i++) {
+ if ((elements[i].getClassName().startsWith
+ ("org.apache.catalina.core.ApplicationFilterChain"))
+ && (elements[i].getMethodName().equals("internalDoFilter"))) {
+ pos = i;
+ }
+ }
+ for (int i = 0; i < pos; i++) {
+ if (!(elements[i].getClassName().startsWith
+ ("org.apache.catalina.core."))) {
+ trace.append('\t').append(elements[i].toString()).append('\n');
+ }
+ }
+ return trace.toString();
+ }
+
}
diff --git a/java/org/apache/catalina/valves/RequestFilterValve.java b/java/org/apache/catalina/valves/RequestFilterValve.java
index e1177b524..c34fb9f56 100644
--- a/java/org/apache/catalina/valves/RequestFilterValve.java
+++ b/java/org/apache/catalina/valves/RequestFilterValve.java
@@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.util.StringManager;
-import org.apache.tomcat.util.compat.JdkCompat;
/**
* Implementation of a Valve that performs filtering based on comparing the
@@ -73,12 +72,6 @@ public abstract class RequestFilterValve
/**
- * JDK compatibility support
- */
- private static final JdkCompat jdkCompat = JdkCompat.getJdkCompat();
-
-
- /**
* The descriptive information related to this implementation.
*/
private static final String info =
@@ -234,7 +227,7 @@ public abstract class RequestFilterValve
} catch (PatternSyntaxException e) {
IllegalArgumentException iae = new IllegalArgumentException
(sm.getString("requestFilterValve.syntax", pattern));
- jdkCompat.chainException(iae, e);
+ iae.initCause(e);
throw iae;
}
list = list.substring(comma + 1);
diff --git a/java/org/apache/tomcat/util/compat/Jdk14Compat.java b/java/org/apache/tomcat/util/compat/Jdk14Compat.java
deleted file mode 100644
index db9273031..000000000
--- a/java/org/apache/tomcat/util/compat/Jdk14Compat.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed 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.compat;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-
-
-/**
- * See JdkCompat. This is an extension of that class for Jdk1.4 support.
- *
- * @author Tim Funk
- * @author Remy Maucherat
- */
-public class Jdk14Compat extends JdkCompat {
- // -------------------------------------------------------------- Constants
-
- // ------------------------------------------------------- Static Variables
- //static Log logger = LogFactory.getLog(Jdk14Compat.class);
-
- // ----------------------------------------------------------- Constructors
- /**
- * Default no-arg constructor
- */
- protected Jdk14Compat() {
- }
-
-
- // --------------------------------------------------------- Public Methods
-
- /**
- * Return the URI for the given file. Originally created for
- * o.a.c.loader.WebappClassLoader
- *
- * @param file The file to wrap into URI
- * @return A URI as a URL
- * @throws MalformedURLException Doh ;)
- */
- public URL getURI(File file)
- throws MalformedURLException {
-
- File realFile = file;
- try {
- realFile = realFile.getCanonicalFile();
- } catch (IOException e) {
- // Ignore
- }
-
- return realFile.toURI().toURL();
- }
-
-
- /**
- * Return the maximum amount of memory the JVM will attempt to use.
- */
- public long getMaxMemory() {
- return Runtime.getRuntime().maxMemory();
- }
-
-
- /**
- * Print out a partial servlet stack trace (truncating at the last
- * occurrence of javax.servlet.).
- */
- public String getPartialServletStackTrace(Throwable t) {
- StringBuffer trace = new StringBuffer();
- trace.append(t.toString()).append('\n');
- StackTraceElement[] elements = t.getStackTrace();
- int pos = elements.length;
- for (int i = 0; i < elements.length; i++) {
- if ((elements[i].getClassName().startsWith
- ("org.apache.catalina.core.ApplicationFilterChain"))
- && (elements[i].getMethodName().equals("internalDoFilter"))) {
- pos = i;
- }
- }
- for (int i = 0; i < pos; i++) {
- if (!(elements[i].getClassName().startsWith
- ("org.apache.catalina.core."))) {
- trace.append('\t').append(elements[i].toString()).append('\n');
- }
- }
- return trace.toString();
- }
-
- public String [] split(String path, String pat) {
- return path.split(pat);
- }
-
-
- /**
- * Chains the wrapped throwable to the wrapper throwable.
- *
- * @param wrapper The wrapper throwable
- * @param wrapped The throwable to be wrapped
- */
- public void chainException(Throwable wrapper, Throwable wrapped) {
- wrapper.initCause(wrapped);
- }
-
- }
diff --git a/java/org/apache/tomcat/util/compat/JdkCompat.java b/java/org/apache/tomcat/util/compat/JdkCompat.java
deleted file mode 100644
index 7659ee50a..000000000
--- a/java/org/apache/tomcat/util/compat/JdkCompat.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed 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.compat;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Vector;
-
-
-/**
- * General-purpose utility to provide backward-compatibility and JDK
- * independence. This allow use of JDK1.3 ( or higher ) facilities if
- * available, while maintaining the code compatible with older VMs.
- *
- * The goal is to make backward-compatiblity reasonably easy.
- *
- * The base class supports JDK1.3 behavior.
- *
- * @author Tim Funk
- */
-public class JdkCompat {
-
- // ------------------------------------------------------- Static Variables
-
- /**
- * class providing java2 support
- */
- static final String JAVA14_SUPPORT =
- "org.apache.tomcat.util.compat.Jdk14Compat";
-
- /** Return java version as a string
- */
- public static String getJavaVersion() {
- return javaVersion;
- }
-
- public static boolean isJava2() {
- return java2;
- }
-
- public static boolean isJava14() {
- return java14;
- }
-
- public static boolean isJava15() {
- return java15;
- }
-
- // -------------------- Implementation --------------------
-
- // from ant
- public static final String JAVA_1_0 = "1.0";
- public static final String JAVA_1_1 = "1.1";
- public static final String JAVA_1_2 = "1.2";
- public static final String JAVA_1_3 = "1.3";
- public static final String JAVA_1_4 = "1.4";
- public static final String JAVA_1_5 = "1.5";
-
- static String javaVersion;
- static boolean java2=false;
- static boolean java14=false;
- static boolean java15=false;
- static JdkCompat jdkCompat;
-
- static {
- init();
- }
-
- private static void init() {
- try {
- javaVersion = JAVA_1_0;
- Class.forName("java.lang.Void");
- javaVersion = JAVA_1_1;
- Class.forName("java.lang.ThreadLocal");
- java2=true;
- javaVersion = JAVA_1_2;
- Class.forName("java.lang.StrictMath");
- javaVersion = JAVA_1_3;
- Class.forName("java.lang.CharSequence");
- javaVersion = JAVA_1_4;
- java14=true;
- Class.forName("java.lang.Appendable");
- javaVersion = JAVA_1_5;
- java15=true;
- } catch (ClassNotFoundException cnfe) {
- // swallow as we've hit the max class version that we have
- }
- if( java14 ) {
- try {
- Class c=Class.forName(JAVA14_SUPPORT);
- jdkCompat=(JdkCompat)c.newInstance();
- } catch( Exception ex ) {
- jdkCompat=new JdkCompat();
- }
- } else {
- jdkCompat=new JdkCompat();
- // Install jar handler if none installed
- }
- }
-
- // ----------------------------------------------------------- Constructors
- /**
- * Default no-arg constructor
- */
- protected JdkCompat() {
- }
-
-
- // --------------------------------------------------------- Public Methods
- /**
- * Get a compatibiliy helper class.
- */
- public static JdkCompat getJdkCompat() {
- return jdkCompat;
- }
-
- /**
- * Return the URI for the given file. Originally created for
- * o.a.c.loader.WebappClassLoader
- *
- * @param file The file to wrap into URI
- * @return A URI as a URL
- * @throws MalformedURLException Doh ;)
- */
- public URL getURI(File file)
- throws MalformedURLException {
-
- File realFile = file;
- try {
- realFile = realFile.getCanonicalFile();
- } catch (IOException e) {
- // Ignore
- }
-
- return realFile.toURL();
- }
-
-
- /**
- * Return the maximum amount of memory the JVM will attempt to use.
- */
- public long getMaxMemory() {
- return (-1L);
- }
-
-
- /**
- * Print out a partial servlet stack trace (truncating at the last
- * occurrence of javax.servlet.).
- */
- public String getPartialServletStackTrace(Throwable t) {
- StringWriter stackTrace = new StringWriter();
- t.printStackTrace(new PrintWriter(stackTrace));
- String st = stackTrace.toString();
- int i = st.lastIndexOf
- ("org.apache.catalina.core.ApplicationFilterChain.internalDoFilter");
- if (i > -1) {
- return st.substring(0, i - 4);
- } else {
- return st;
- }
- }
-
- /**
- * Splits a string into it's components.
- * @param path String to split
- * @param pat Pattern to split at
- * @return the components of the path
- */
- public String [] split(String path, String pat) {
- Vector comps = new Vector();
- int pos = path.indexOf(pat);
- int start = 0;
- while( pos >= 0 ) {
- if(pos > start ) {
- String comp = path.substring(start,pos);
- comps.add(comp);
- }
- start = pos + pat.length();
- pos = path.indexOf(pat,start);
- }
- if( start < path.length()) {
- comps.add(path.substring(start));
- }
- String [] result = new String[comps.size()];
- for(int i=0; i < comps.size(); i++) {
- result[i] = (String)comps.elementAt(i);
- }
- return result;
- }
-
-
- /**
- * Chains the wrapped throwable to the wrapper throwable.
- *
- * @param wrapper The wrapper throwable
- * @param wrapped The throwable to be wrapped
- */
- public void chainException(Throwable wrapper, Throwable wrapped) {
- // do nothing
- }
-
- }
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSE13Factory.java b/java/org/apache/tomcat/util/net/jsse/JSSE13Factory.java
deleted file mode 100644
index ae22fe34f..000000000
--- a/java/org/apache/tomcat/util/net/jsse/JSSE13Factory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed 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 java.net.Socket;
-import javax.net.ssl.SSLSocket;
-import org.apache.tomcat.util.net.SSLSupport;
-import org.apache.tomcat.util.net.ServerSocketFactory;
-
-/**
- * Implementation class for JSSEFactory for JSSE 1.0.x (that is an extension
- * to the 1.3 JVM).
- *
- * @author Bill Barker
- */
-
-class JSSE13Factory implements JSSEFactory {
-
- JSSE13Factory() {
- }
-
- public ServerSocketFactory getSocketFactory() {
- return new JSSE13SocketFactory();
- }
-
- public SSLSupport getSSLSupport(Socket socket) {
- return new JSSESupport((SSLSocket)socket);
- }
-}
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSE13SocketFactory.java b/java/org/apache/tomcat/util/net/jsse/JSSE13SocketFactory.java
deleted file mode 100644
index 89c813fc7..000000000
--- a/java/org/apache/tomcat/util/net/jsse/JSSE13SocketFactory.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed 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 java.io.IOException;
-import java.security.KeyStore;
-import java.security.SecureRandom;
-import java.security.Security;
-import java.security.Provider;
-
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLSocket;
-
-/*
- 1. Make the JSSE's jars available, either as an installed
- extension (copy them into jre/lib/ext) or by adding
- them to the Tomcat classpath.
- 2. keytool -genkey -alias tomcat -keyalg RSA
- Use "changeit" as password ( this is the default we use )
- */
-
-/**
- * SSL server socket factory. It _requires_ a valid RSA key and
- * JSSE.
- *
- * @author Harish Prabandham
- * @author Costin Manolache
- * @author Stefan Freyr Stefansson
- * @author EKR -- renamed to JSSESocketFactory
- * @author Bill Barker
- */
-public class JSSE13SocketFactory extends JSSESocketFactory
-{
- /**
- * Flag for client authentication
- */
- protected boolean clientAuth = false;
-
- public JSSE13SocketFactory () {
- super();
- }
-
- /**
- * Reads the keystore and initializes the SSL socket factory.
- *
- * NOTE: This method is identical in functionality to the method of the
- * same name in JSSE14SocketFactory, except that this method is used with
- * JSSE 1.0.x (which is an extension to the 1.3 JVM), whereas the other is
- * used with JSSE 1.1.x (which ships with the 1.4 JVM). Therefore, this
- * method uses classes in com.sun.net.ssl, which have since moved to
- * javax.net.ssl, and explicitly registers the required security providers,
- * which come standard in a 1.4 JVM.
- */
- void init() throws IOException {
- try {
- try {
- Class ssps = Class.forName("sun.security.provider.Sun");
- Security.addProvider ((Provider)ssps.newInstance());
- }catch(Exception cnfe) {
- //Ignore, since this is a non-Sun JVM
- }
- Security.addProvider (new com.sun.net.ssl.internal.ssl.Provider());
-
- String clientAuthStr = (String)attributes.get("clientauth");
- if("true".equalsIgnoreCase(clientAuthStr) ||
- "yes".equalsIgnoreCase(clientAuthStr) ||
- "want".equalsIgnoreCase(clientAuthStr)) {
- clientAuth = true;
- }
-
- // SSL protocol variant (e.g., TLS, SSL v3, etc.)
- String protocol = (String)attributes.get("protocol");
- if (protocol == null) protocol = defaultProtocol;
-
- // Certificate encoding algorithm (e.g., SunX509)
- String algorithm = (String)attributes.get("algorithm");
- if (algorithm == null) algorithm = defaultAlgorithm;
-
- // Set up KeyManager, which will extract server key
- com.sun.net.ssl.KeyManagerFactory kmf =
- com.sun.net.ssl.KeyManagerFactory.getInstance(algorithm);
- String keystoreType = (String)attributes.get("keystoreType");
- if (keystoreType == null) {
- keystoreType = defaultKeystoreType;
- }
- String keystorePass = getKeystorePassword();
- kmf.init(getKeystore(keystoreType, keystorePass),
- keystorePass.toCharArray());
-
- // Set up TrustManager
- com.sun.net.ssl.TrustManager[] tm = null;
- String truststoreType = (String)attributes.get("truststoreType");
- if(truststoreType == null) {
- truststoreType = keystoreType;
- }
- KeyStore trustStore = getTrustStore(truststoreType);
- if (trustStore != null) {
- com.sun.net.ssl.TrustManagerFactory tmf =
- com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509");
- tmf.init(trustStore);
- tm = tmf.getTrustManagers();
- }
-
- // Create and init SSLContext
- com.sun.net.ssl.SSLContext context =
- com.sun.net.ssl.SSLContext.getInstance(protocol);
- context.init(kmf.getKeyManagers(), tm, new SecureRandom());
-
- // Create proxy
- sslProxy = context.getServerSocketFactory();
-
- // Determine which cipher suites to enable
- String requestedCiphers = (String)attributes.get("ciphers");
- enabledCiphers = getEnabledCiphers(requestedCiphers,
- sslProxy.getSupportedCipherSuites());
-
- } catch(Exception e) {
- if( e instanceof IOException )
- throw (IOException)e;
- throw new IOException(e.getMessage());
- }
- }
- protected String[] getEnabledProtocols(SSLServerSocket socket,
- String requestedProtocols){
- return null;
- }
- protected void setEnabledProtocols(SSLServerSocket socket,
- String [] protocols){
- }
-
- protected void configureClientAuth(SSLServerSocket socket){
- socket.setNeedClientAuth(clientAuth);
- }
-
- protected void configureClientAuth(SSLSocket socket){
- // In JSSE 1.0.2 docs it does not explicitly
- // state whether SSLSockets returned from
- // SSLServerSocket.accept() inherit this setting.
- socket.setNeedClientAuth(clientAuth);
- }
-
-}
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSE14Factory.java b/java/org/apache/tomcat/util/net/jsse/JSSE14Factory.java
deleted file mode 100644
index 83cc2af5b..000000000
--- a/java/org/apache/tomcat/util/net/jsse/JSSE14Factory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed 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 java.net.Socket;
-import javax.net.ssl.SSLSocket;
-import org.apache.tomcat.util.net.SSLSupport;
-import org.apache.tomcat.util.net.ServerSocketFactory;
-
-/**
- * Implementation class for JSSEFactory for JSSE 1.1.x (that ships with the
- * 1.4 JVM).
- *
- * @author Bill Barker
- */
-
-class JSSE14Factory implements JSSEFactory {
-
- JSSE14Factory() {
- }
-
- public ServerSocketFactory getSocketFactory() {
- return new JSSE14SocketFactory();
- }
-
- public SSLSupport getSSLSupport(Socket socket) {
- return new JSSE14Support((SSLSocket)socket);
- }
-}
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSE14SocketFactory.java b/java/org/apache/tomcat/util/net/jsse/JSSE14SocketFactory.java
deleted file mode 100644
index 4e69cf95a..000000000
--- a/java/org/apache/tomcat/util/net/jsse/JSSE14SocketFactory.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed 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 java.io.IOException;
-import java.security.KeyStore;
-import java.security.SecureRandom;
-import java.util.Vector;
-
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.X509KeyManager;
-
-import org.apache.tomcat.util.res.StringManager;
-
-/*
- 1. Make the JSSE's jars available, either as an installed
- extension (copy them into jre/lib/ext) or by adding
- them to the Tomcat classpath.
- 2. keytool -genkey -alias tomcat -keyalg RSA
- Use "changeit" as password ( this is the default we use )
- */
-
-/**
- * SSL server socket factory. It _requires_ a valid RSA key and
- * JSSE.
- *
- * @author Harish Prabandham
- * @author Costin Manolache
- * @author Stefan Freyr Stefansson
- * @author EKR -- renamed to JSSESocketFactory
- * @author Jan Luehe
- */
-public class JSSE14SocketFactory extends JSSESocketFactory {
-
- private static StringManager sm =
- StringManager.getManager("org.apache.tomcat.util.net.jsse.res");
-
- /**
- * Flag to state that we require client authentication.
- */
- protected boolean requireClientAuth = false;
-
- /**
- * Flag to state that we would like client authentication.
- */
- protected boolean wantClientAuth = false;
-
- public JSSE14SocketFactory () {
- super();
- }
-
- /**
- * Reads the keystore and initializes the SSL socket factory.
- */
- void init() throws IOException {
- try {
-
- String clientAuthStr = (String) attributes.get("clientauth");
- if("true".equalsIgnoreCase(clientAuthStr) ||
- "yes".equalsIgnoreCase(clientAuthStr)) {
- requireClientAuth = true;
- } else if("want".equalsIgnoreCase(clientAuthStr)) {
- wantClientAuth = true;
- }
-
- // SSL protocol variant (e.g., TLS, SSL v3, etc.)
- String protocol = (String) attributes.get("protocol");
- if (protocol == null) {
- protocol = defaultProtocol;
- }
-
- // Certificate encoding algorithm (e.g., SunX509)
- String algorithm = (String) attributes.get("algorithm");
- if (algorithm == null) {
- algorithm = defaultAlgorithm;
- }
-
- String keystoreType = (String) attributes.get("keystoreType");
- if (keystoreType == null) {
- keystoreType = defaultKeystoreType;
- }
-
- String trustAlgorithm = (String)attributes.get("truststoreAlgorithm");
- if( trustAlgorithm == null ) {
- trustAlgorithm = algorithm;
- }
- // Create and init SSLContext
- SSLContext context = SSLContext.getInstance(protocol);
- context.init(getKeyManagers(keystoreType, algorithm,
- (String) attributes.get("keyAlias")),
- getTrustManagers(keystoreType, trustAlgorithm),
- new SecureRandom());
-
- // create proxy
- sslProxy = context.getServerSocketFactory();
-
- // Determine which cipher suites to enable
- String requestedCiphers = (String)attributes.get("ciphers");
- enabledCiphers = getEnabledCiphers(requestedCiphers,
- sslProxy.getSupportedCipherSuites());
-
- } catch(Exception e) {
- if( e instanceof IOException )
- throw (IOException)e;
- throw new IOException(e.getMessage());
- }
- }
-
- /**
- * Gets the initialized key managers.
- */
- protected KeyManager[] getKeyManagers(String keystoreType,
- String algorithm,
- String keyAlias)
- throws Exception {
-
- KeyManager[] kms = null;
-
- String keystorePass = getKeystorePassword();
-
- KeyStore ks = getKeystore(keystoreType, keystorePass);
- if (keyAlias != null && !ks.isKeyEntry(keyAlias)) {
- throw new IOException(sm.getString("jsse.alias_no_key_entry", keyAlias));
- }
-
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
- kmf.init(ks, keystorePass.toCharArray());
-
- kms = kmf.getKeyManagers();
- if (keyAlias != null) {
- if (JSSESocketFactory.defaultKeystoreType.equals(keystoreType)) {
- keyAlias = keyAlias.toLowerCase();
- }
- for(int i=0; i 0) {
- /*
- * Check to see if the requested protocol is among the
- * supported protocols, i.e., may be enabled
- */
- for (int i=0; supportedProtocols != null
- && i 0) {
- /*
- * Check to see if the requested protocol is among the
- * supported protocols, i.e., may be enabled
- */
- for (int i=0; supportedProtocols != null
- && iPKIX is supported.
- *
- * @param algorithm The algorithm to get parameters for.
- * @param crlf The path to the CRL file.
- * @param trustStore The configured TrustStore.
- * @return The parameters including the CRLs and TrustStore.
- */
- protected CertPathParameters getParameters(String algorithm,
- String crlf,
- KeyStore trustStore)
- throws Exception {
- CertPathParameters params = null;
- if("PKIX".equalsIgnoreCase(algorithm)) {
- PKIXBuilderParameters xparams = new PKIXBuilderParameters(trustStore,
- new X509CertSelector());
- Collection crls = getCRLs(crlf);
- CertStoreParameters csp = new CollectionCertStoreParameters(crls);
- CertStore store = CertStore.getInstance("Collection", csp);
- xparams.addCertStore(store);
- xparams.setRevocationEnabled(true);
- String trustLength = (String)attributes.get("trustMaxCertLength");
- if(trustLength != null) {
- try {
- xparams.setMaxPathLength(Integer.parseInt(trustLength));
- } catch(Exception ex) {
- log.warn("Bad maxCertLength: "+trustLength);
- }
- }
-
- params = xparams;
- } else {
- throw new CRLException("CRLs not supported for type: "+algorithm);
- }
- return params;
- }
-
-
- /**
- * Load the collection of CRLs.
- *
- */
- protected Collection extends CRL> getCRLs(String crlf)
- throws IOException, CRLException, CertificateException {
-
- File crlFile = new File(crlf);
- if( !crlFile.isAbsolute() ) {
- crlFile = new File(System.getProperty("catalina.base"), crlf);
- }
- Collection extends CRL> crls = null;
- InputStream is = null;
- try {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- is = new FileInputStream(crlFile);
- crls = cf.generateCRLs(is);
- } catch(IOException iex) {
- throw iex;
- } catch(CRLException crle) {
- throw crle;
- } catch(CertificateException ce) {
- throw ce;
- } finally {
- if(is != null) {
- try{
- is.close();
- } catch(Exception ex) {
- }
- }
- }
- return crls;
- }
-
-}
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSEFactory.java b/java/org/apache/tomcat/util/net/jsse/JSSEFactory.java
index e19f6231b..1d8aaf778 100644
--- a/java/org/apache/tomcat/util/net/jsse/JSSEFactory.java
+++ b/java/org/apache/tomcat/util/net/jsse/JSSEFactory.java
@@ -17,6 +17,9 @@
package org.apache.tomcat.util.net.jsse;
import java.net.Socket;
+
+import javax.net.ssl.SSLSocket;
+
import org.apache.tomcat.util.net.SSLSupport;
import org.apache.tomcat.util.net.ServerSocketFactory;
@@ -27,16 +30,20 @@ import org.apache.tomcat.util.net.ServerSocketFactory;
* @author Bill Barker
*/
-interface JSSEFactory {
+public class JSSEFactory {
/**
* Returns the ServerSocketFactory to use.
*/
- public ServerSocketFactory getSocketFactory();
+ public ServerSocketFactory getSocketFactory() {
+ return new JSSESocketFactory();
+ }
/**
* returns the SSLSupport attached to this socket.
*/
- public SSLSupport getSSLSupport(Socket socket);
+ public SSLSupport getSSLSupport(Socket socket) {
+ return new JSSESupport((SSLSocket)socket);
+ }
};
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSEImplementation.java b/java/org/apache/tomcat/util/net/jsse/JSSEImplementation.java
index 9ee643d72..1102ab4a5 100644
--- a/java/org/apache/tomcat/util/net/jsse/JSSEImplementation.java
+++ b/java/org/apache/tomcat/util/net/jsse/JSSEImplementation.java
@@ -18,7 +18,6 @@ package org.apache.tomcat.util.net.jsse;
import java.net.Socket;
-import org.apache.tomcat.util.compat.JdkCompat;
import org.apache.tomcat.util.net.SSLImplementation;
import org.apache.tomcat.util.net.SSLSupport;
import org.apache.tomcat.util.net.ServerSocketFactory;
@@ -32,12 +31,6 @@ import org.apache.tomcat.util.net.ServerSocketFactory;
public class JSSEImplementation extends SSLImplementation
{
- static final String JSSE15Factory =
- "org.apache.tomcat.util.net.jsse.JSSE15Factory";
- static final String JSSE14Factory =
- "org.apache.tomcat.util.net.jsse.JSSE14Factory";
- static final String JSSE13Factory =
- "org.apache.tomcat.util.net.jsse.JSSE13Support";
static final String SSLSocketClass = "javax.net.ssl.SSLSocket";
static org.apache.commons.logging.Log logger =
@@ -48,27 +41,7 @@ public class JSSEImplementation extends SSLImplementation
public JSSEImplementation() throws ClassNotFoundException {
// Check to see if JSSE is floating around somewhere
Class.forName(SSLSocketClass);
- if( JdkCompat.isJava15() ) {
- try {
- Class factcl = Class.forName(JSSE15Factory);
- factory = (JSSEFactory)factcl.newInstance();
- } catch(Exception ex) {
- if(logger.isDebugEnabled())
- logger.debug("Error getting factory: " + JSSE15Factory, ex);
- }
- }
- if(factory == null && JdkCompat.isJava14() ) {
- try {
- Class factcl = Class.forName(JSSE14Factory);
- factory = (JSSEFactory)factcl.newInstance();
- } catch(Exception ex) {
- if(logger.isDebugEnabled()) {
- logger.debug("Error getting factory: " + JSSE14Factory, ex);
- }
- }
- } if(factory == null) {
- factory = new JSSE13Factory();
- }
+ factory = new JSSEFactory();
}
diff --git a/java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java b/java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java
index 8bef00f94..0d317df11 100644
--- a/java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java
+++ b/java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java
@@ -26,12 +26,34 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.security.cert.CRL;
+import java.security.cert.CRLException;
+import java.security.cert.CertPathParameters;
+import java.security.cert.CertStore;
+import java.security.cert.CertStoreParameters;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.CollectionCertStoreParameters;
+import java.security.cert.PKIXBuilderParameters;
+import java.security.cert.X509CertSelector;
+import java.util.Collection;
import java.util.Vector;
+import javax.net.ssl.CertPathTrustManagerParameters;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509KeyManager;
+
+import org.apache.tomcat.util.res.StringManager;
/*
1. Make the JSSE's jars available, either as an installed
@@ -49,10 +71,15 @@ import javax.net.ssl.SSLSocket;
* @author Costin Manolache
* @author Stefan Freyr Stefansson
* @author EKR -- renamed to JSSESocketFactory
+ * @author Jan Luehe
+ * @author Bill Barker
*/
-public abstract class JSSESocketFactory
- extends org.apache.tomcat.util.net.ServerSocketFactory
-{
+public class JSSESocketFactory
+ extends org.apache.tomcat.util.net.ServerSocketFactory {
+
+ private static StringManager sm =
+ StringManager.getManager("org.apache.tomcat.util.net.jsse.res");
+
// defaults
static String defaultProtocol = "TLS";
static String defaultAlgorithm = "SunX509";
@@ -68,7 +95,17 @@ public abstract class JSSESocketFactory
protected String clientAuth = "false";
protected SSLServerSocketFactory sslProxy = null;
protected String[] enabledCiphers;
-
+
+ /**
+ * Flag to state that we require client authentication.
+ */
+ protected boolean requireClientAuth = false;
+
+ /**
+ * Flag to state that we would like client authentication.
+ */
+ protected boolean wantClientAuth = false;
+
public JSSESocketFactory () {
}
@@ -303,12 +340,214 @@ public abstract class JSSESocketFactory
/**
* Reads the keystore and initializes the SSL socket factory.
- *
- * Place holder method to initialize the KeyStore, etc.
*/
- abstract void init() throws IOException ;
+ void init() throws IOException {
+ try {
- /*
+ String clientAuthStr = (String) attributes.get("clientauth");
+ if("true".equalsIgnoreCase(clientAuthStr) ||
+ "yes".equalsIgnoreCase(clientAuthStr)) {
+ requireClientAuth = true;
+ } else if("want".equalsIgnoreCase(clientAuthStr)) {
+ wantClientAuth = true;
+ }
+
+ // SSL protocol variant (e.g., TLS, SSL v3, etc.)
+ String protocol = (String) attributes.get("protocol");
+ if (protocol == null) {
+ protocol = defaultProtocol;
+ }
+
+ // Certificate encoding algorithm (e.g., SunX509)
+ String algorithm = (String) attributes.get("algorithm");
+ if (algorithm == null) {
+ algorithm = defaultAlgorithm;
+ }
+
+ String keystoreType = (String) attributes.get("keystoreType");
+ if (keystoreType == null) {
+ keystoreType = defaultKeystoreType;
+ }
+
+ String trustAlgorithm = (String)attributes.get("truststoreAlgorithm");
+ if( trustAlgorithm == null ) {
+ trustAlgorithm = algorithm;
+ }
+ // Create and init SSLContext
+ SSLContext context = SSLContext.getInstance(protocol);
+ context.init(getKeyManagers(keystoreType, algorithm,
+ (String) attributes.get("keyAlias")),
+ getTrustManagers(keystoreType, trustAlgorithm),
+ new SecureRandom());
+
+ // create proxy
+ sslProxy = context.getServerSocketFactory();
+
+ // Determine which cipher suites to enable
+ String requestedCiphers = (String)attributes.get("ciphers");
+ enabledCiphers = getEnabledCiphers(requestedCiphers,
+ sslProxy.getSupportedCipherSuites());
+
+ } catch(Exception e) {
+ if( e instanceof IOException )
+ throw (IOException)e;
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ /**
+ * Gets the initialized key managers.
+ */
+ protected KeyManager[] getKeyManagers(String keystoreType,
+ String algorithm,
+ String keyAlias)
+ throws Exception {
+
+ KeyManager[] kms = null;
+
+ String keystorePass = getKeystorePassword();
+
+ KeyStore ks = getKeystore(keystoreType, keystorePass);
+ if (keyAlias != null && !ks.isKeyEntry(keyAlias)) {
+ throw new IOException(sm.getString("jsse.alias_no_key_entry", keyAlias));
+ }
+
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
+ kmf.init(ks, keystorePass.toCharArray());
+
+ kms = kmf.getKeyManagers();
+ if (keyAlias != null) {
+ if (JSSESocketFactory.defaultKeystoreType.equals(keystoreType)) {
+ keyAlias = keyAlias.toLowerCase();
+ }
+ for(int i=0; iPKIX is supported.
+ *
+ * @param algorithm The algorithm to get parameters for.
+ * @param crlf The path to the CRL file.
+ * @param trustStore The configured TrustStore.
+ * @return The parameters including the CRLs and TrustStore.
+ */
+ protected CertPathParameters getParameters(String algorithm,
+ String crlf,
+ KeyStore trustStore)
+ throws Exception {
+ CertPathParameters params = null;
+ if("PKIX".equalsIgnoreCase(algorithm)) {
+ PKIXBuilderParameters xparams = new PKIXBuilderParameters(trustStore,
+ new X509CertSelector());
+ Collection crls = getCRLs(crlf);
+ CertStoreParameters csp = new CollectionCertStoreParameters(crls);
+ CertStore store = CertStore.getInstance("Collection", csp);
+ xparams.addCertStore(store);
+ xparams.setRevocationEnabled(true);
+ String trustLength = (String)attributes.get("trustMaxCertLength");
+ if(trustLength != null) {
+ try {
+ xparams.setMaxPathLength(Integer.parseInt(trustLength));
+ } catch(Exception ex) {
+ log.warn("Bad maxCertLength: "+trustLength);
+ }
+ }
+
+ params = xparams;
+ } else {
+ throw new CRLException("CRLs not supported for type: "+algorithm);
+ }
+ return params;
+ }
+
+
+ /**
+ * Load the collection of CRLs.
+ *
+ */
+ protected Collection extends CRL> getCRLs(String crlf)
+ throws IOException, CRLException, CertificateException {
+
+ File crlFile = new File(crlf);
+ if( !crlFile.isAbsolute() ) {
+ crlFile = new File(System.getProperty("catalina.base"), crlf);
+ }
+ Collection extends CRL> crls = null;
+ InputStream is = null;
+ try {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ is = new FileInputStream(crlFile);
+ crls = cf.generateCRLs(is);
+ } catch(IOException iex) {
+ throw iex;
+ } catch(CRLException crle) {
+ throw crle;
+ } catch(CertificateException ce) {
+ throw ce;
+ } finally {
+ if(is != null) {
+ try{
+ is.close();
+ } catch(Exception ex) {
+ }
+ }
+ }
+ return crls;
+ }
+
+ /**
+ * Set the SSL protocol variants to be enabled.
+ * @param socket the SSLServerSocket.
+ * @param protocols the protocols to use.
+ */
+ protected void setEnabledProtocols(SSLServerSocket socket, String []protocols){
+ if (protocols != null) {
+ socket.setEnabledProtocols(protocols);
+ }
+ }
+
+ /**
* Determines the SSL protocol variants to be enabled.
*
* @param socket The socket to get supported list from.
@@ -318,16 +557,70 @@ public abstract class JSSESocketFactory
* @return Array of SSL protocol variants to be enabled, or null if none of
* the requested protocol variants are supported
*/
- abstract protected String[] getEnabledProtocols(SSLServerSocket socket,
- String requestedProtocols);
+ protected String[] getEnabledProtocols(SSLServerSocket socket,
+ String requestedProtocols){
+ String[] supportedProtocols = socket.getSupportedProtocols();
- /**
- * Set the SSL protocol variants to be enabled.
- * @param socket the SSLServerSocket.
- * @param protocols the protocols to use.
- */
- abstract protected void setEnabledProtocols(SSLServerSocket socket,
- String [] protocols);
+ String[] enabledProtocols = null;
+
+ if (requestedProtocols != null) {
+ Vector vec = null;
+ String protocol = requestedProtocols;
+ int index = requestedProtocols.indexOf(',');
+ if (index != -1) {
+ int fromIndex = 0;
+ while (index != -1) {
+ protocol = requestedProtocols.substring(fromIndex, index).trim();
+ if (protocol.length() > 0) {
+ /*
+ * Check to see if the requested protocol is among the
+ * supported protocols, i.e., may be enabled
+ */
+ for (int i=0; supportedProtocols != null
+ && i 0) {
+ /*
+ * Check to see if the requested protocol is among the
+ * supported protocols, i.e., may be enabled
+ */
+ for (int i=0; supportedProtocols != null
+ && iorg.apache.catalina.valves.CertificateValve
*/
@@ -174,5 +218,15 @@ class JSSESupport implements SSLSupport {
}
+ private static class Listener implements HandshakeCompletedListener {
+ volatile boolean completed = false;
+ public void handshakeCompleted(HandshakeCompletedEvent event) {
+ completed = true;
+ }
+ void reset() {
+ completed = false;
+ }
+ }
+
}
--
2.11.0