From f712dda438f5b1d5f53bf5989a1bd90c4e77cee9 Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 19 Nov 2009 18:00:09 +0000 Subject: [PATCH] Fix SSL for BIO post refactoring Make attribute names consistent Endpoints are now responsible for configuring the SSL "engine" Basics work but still needs more testing NIO & APR to follow git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@882231 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/connector/Connector.java | 4 - .../coyote/http11/AbstractHttp11Protocol.java | 77 +++++---- .../apache/tomcat/util/net/AbstractEndpoint.java | 172 +++++++++++++++------ java/org/apache/tomcat/util/net/JIoEndpoint.java | 69 +++++++-- java/org/apache/tomcat/util/net/NioEndpoint.java | 10 +- .../tomcat/util/net/jsse/JSSESocketFactory.java | 79 ++++++---- webapps/docs/config/http.xml | 34 +++- 7 files changed, 313 insertions(+), 132 deletions(-) diff --git a/java/org/apache/catalina/connector/Connector.java b/java/org/apache/catalina/connector/Connector.java index 54bebe931..6253e766b 100644 --- a/java/org/apache/catalina/connector/Connector.java +++ b/java/org/apache/catalina/connector/Connector.java @@ -284,12 +284,8 @@ public class Connector replacements.put("connectionLinger", "soLinger"); replacements.put("connectionTimeout", "soTimeout"); replacements.put("connectionUploadTimeout", "timeout"); - replacements.put("clientAuth", "clientauth"); - replacements.put("keystoreFile", "keystore"); replacements.put("randomFile", "randomfile"); replacements.put("rootFile", "rootfile"); - replacements.put("keystorePass", "keypass"); - replacements.put("keystoreType", "keytype"); replacements.put("sslProtocols", "protocols"); } diff --git a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java index e9944cb31..5a435efc7 100644 --- a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java +++ b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java @@ -325,49 +325,68 @@ public abstract class AbstractHttp11Protocol implements ProtocolHandler, MBeanRe public int getSoLinger() { return endpoint.getSoLinger(); } public void setSoLinger(int soLinger) { endpoint.setSoLinger(soLinger); } + // JSSE SSL attrbutes + public String getAlgorithm() { return endpoint.getAlgorithm();} + public void setAlgorithm(String s ) { endpoint.setAlgorithm(s);} + public String getClientAuth() { return endpoint.getClientAuth();} + public void setClientAuth(String s ) { endpoint.setClientAuth(s);} + public String getKeystoreFile() { return endpoint.getKeystoreFile();} public void setKeystoreFile(String s ) { endpoint.setKeystoreFile(s);} - public void setKeystore(String s) { setKeystoreFile(s);} - public String getKeystore(){ return getKeystoreFile();} - public String getKeyAlias() { return (endpoint).getKeyAlias();} - public void setKeyAlias(String s ) { (endpoint).setKeyAlias(s);} + public String getKeystorePass() { return endpoint.getKeystorePass();} + public void setKeystorePass(String s ) { endpoint.setKeystorePass(s);} - public String getAlgorithm() { return (endpoint).getAlgorithm();} - public void setAlgorithm(String s ) { (endpoint).setAlgorithm(s);} - - public void setClientauth(String s) {setClientAuth(s);} - public String getClientauth(){ return getClientAuth();} - public String getClientAuth() { return (endpoint).getClientAuth();} - public void setClientAuth(String s ) { (endpoint).setClientAuth(s);} + public String getKeystoreType() { return endpoint.getKeystoreType();} + public void setKeystoreType(String s ) { endpoint.setKeystoreType(s);} + + public String getKeystoreProvider() { return endpoint.getKeystoreProvider();} + public void setKeystoreProvider(String s ) { endpoint.setKeystoreProvider(s);} + + public String getSslProtocol() { return endpoint.getSslProtocol();} + public void setSslProtocol(String s) { endpoint.setSslProtocol(s);} - public String getKeystorePass() { return (endpoint).getKeystorePass();} - public void setKeystorePass(String s ) { (endpoint).setKeystorePass(s);} - public void setKeypass(String s) { setKeystorePass(s);} - public String getKeypass() { return getKeystorePass();} - public String getKeystoreType() { return (endpoint).getKeystoreType();} - public void setKeystoreType(String s ) { (endpoint).setKeystoreType(s);} - public String getKeytype() { return getKeystoreType();} - public void setKeytype(String s ) { setKeystoreType(s);} + public String getCiphers() { return endpoint.getCiphers();} + public void setCiphers(String s) { endpoint.setCiphers(s);} + + public String getKeyAlias() { return endpoint.getKeyAlias();} + public void setKeyAlias(String s ) { endpoint.setKeyAlias(s);} - public void setTruststoreFile(String f){(endpoint).setTruststoreFile(f);} - public String getTruststoreFile(){return (endpoint).getTruststoreFile();} - public void setTruststorePass(String p){(endpoint).setTruststorePass(p);} - public String getTruststorePass(){return (endpoint).getTruststorePass();} - public void setTruststoreType(String t){(endpoint).setTruststoreType(t);} - public String getTruststoreType(){ return (endpoint).getTruststoreType();} + public String getKeyPass() { return endpoint.getKeyPass();} + public void setKeyPass(String s ) { endpoint.setKeyPass(s);} + public void setTruststoreFile(String f){ endpoint.setTruststoreFile(f);} + public String getTruststoreFile(){ return endpoint.getTruststoreFile();} + + public void setTruststorePass(String p){ endpoint.setTruststorePass(p);} + public String getTruststorePass(){return endpoint.getTruststorePass();} + + public void setTruststoreType(String t){ endpoint.setTruststoreType(t);} + public String getTruststoreType(){ return endpoint.getTruststoreType();} + + public void setTruststoreProvider(String t){endpoint.setTruststoreProvider(t);} + public String getTruststoreProvider(){ return endpoint.getTruststoreProvider();} + + public void setTruststoreAlgorithm(String a){endpoint.setTruststoreAlgorithm(a);} + public String getTruststoreAlgorithm(){ return endpoint.getTruststoreAlgorithm();} - public String getSslProtocol() { return (endpoint).getSslProtocol();} - public void setSslProtocol(String s) { (endpoint).setSslProtocol(s);} + public void setTrustMaxCertLength(String s){endpoint.setTrustMaxCertLength(s);} + public String getTrustMaxCertLength(){ return endpoint.getTrustMaxCertLength();} - public String getCiphers() { return (endpoint).getCiphers();} - public void setCiphers(String s) { (endpoint).setCiphers(s);} + public void setCrlFile(String s){endpoint.setCrlFile(s);} + public String getCrlFile(){ return endpoint.getCrlFile();} + public void setSessionCacheSize(String s){endpoint.setSessionCacheSize(s);} + public String getSessionCacheSize(){ return endpoint.getTruststoreAlgorithm();} + public void setSessionTimeout(String s){endpoint.setTruststoreAlgorithm(s);} + public String getSessionTimeout(){ return endpoint.getTruststoreAlgorithm();} + + public abstract void init() throws Exception; public abstract void start() throws Exception; + // -------------------- JMX related methods -------------------- // * diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java index 6b3ddf797..8afcb806a 100644 --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java @@ -77,7 +77,40 @@ public abstract class AbstractEndpoint { public enum SocketState { OPEN, CLOSED, LONG } - } + } + + // Standard SSL Configuration attributes + // JSSE + // Standard configuration attribute names + public static final String SSL_ATTR_ALGORITHM = "algorithm"; + public static final String SSL_ATTR_CLIENT_AUTH = "clientAuth"; + public static final String SSL_ATTR_KEYSTORE_FILE = "keystoreFile"; + public static final String SSL_ATTR_KEYSTORE_PASS = "keystorePass"; + public static final String SSL_ATTR_KEYSTORE_TYPE = "keystoreType"; + public static final String SSL_ATTR_KEYSTORE_PROVIDER = "keystoreProvider"; + public static final String SSL_ATTR_SSL_PROTOCOL = "sslProtocol"; + public static final String SSL_ATTR_CIPHERS = "ciphers"; + public static final String SSL_ATTR_CIPHERS_ARRAY = "ciphersArray"; + public static final String SSL_ATTR_KEY_ALIAS = "keyAlias"; + public static final String SSL_ATTR_KEY_PASS = "keyPass"; + public static final String SSL_ATTR_TRUSTSTORE_FILE = "truststoreFile"; + public static final String SSL_ATTR_TRUSTSTORE_PASS = "truststorePass"; + public static final String SSL_ATTR_TRUSTSTORE_TYPE = "truststoreType"; + public static final String SSL_ATTR_TRUSTSTORE_PROVIDER = + "truststoreProvider"; + public static final String SSL_ATTR_TRUSTSTORE_ALGORITHM = + "truststoreAlgorithm"; + public static final String SSL_ATTR_CRL_FILE = + "crlFile"; + public static final String SSL_ATTR_TRUST_MAX_CERT_LENGTH = + "trustMaxCertLength"; + public static final String SSL_ATTR_SESSION_CACHE_SIZE = + "sessionCacheSize"; + public static final String SSL_ATTR_SESSION_TIMEOUT = + "sessionTimeout"; + public static final String SSL_ATTR_ALLOW_UNSAFE_RENEG = + "allowUnsafeLegacyRenegotiation"; + // ----------------------------------------------------------------- Fields @@ -414,36 +447,11 @@ public abstract class AbstractEndpoint { public String defaultIfNull(String val, String defaultValue) { if (val==null) return defaultValue; - else return val; + return val; } + // -------------------- SSL related properties -------------------- - private String truststoreFile = System.getProperty("javax.net.ssl.trustStore"); - public void setTruststoreFile(String s) { - s = adjustRelativePath(s,System.getProperty("catalina.base")); - this.truststoreFile = s; - } - public String getTruststoreFile() {return truststoreFile;} - private String truststorePass = System.getProperty("javax.net.ssl.trustStorePassword"); - public void setTruststorePass(String truststorePass) {this.truststorePass = truststorePass;} - public String getTruststorePass() {return truststorePass;} - private String truststoreType = System.getProperty("javax.net.ssl.trustStoreType"); - public void setTruststoreType(String truststoreType) {this.truststoreType = truststoreType;} - public String getTruststoreType() {return truststoreType;} - private String keystoreFile = System.getProperty("user.home")+"/.keystore"; - public String getKeystoreFile() { return keystoreFile;} - public void setKeystoreFile(String s ) { - s = adjustRelativePath(s,System.getProperty("catalina.base")); - this.keystoreFile = s; - } - public void setKeystore(String s ) { setKeystoreFile(s);} - public String getKeystore() { return getKeystoreFile();} - - private String keyAlias = null; - public String getKeyAlias() { return keyAlias;} - public void setKeyAlias(String s ) { keyAlias = s;} - - private String algorithm = "SunX509"; public String getAlgorithm() { return algorithm;} public void setAlgorithm(String s ) { this.algorithm = s;} @@ -452,7 +460,14 @@ public abstract class AbstractEndpoint { public String getClientAuth() { return clientAuth;} public void setClientAuth(String s ) { this.clientAuth = s;} - private String keystorePass = "changeit"; + private String keystoreFile = System.getProperty("user.home")+"/.keystore"; + public String getKeystoreFile() { return keystoreFile;} + public void setKeystoreFile(String s ) { + String file = adjustRelativePath(s,System.getProperty("catalina.base")); + this.keystoreFile = file; + } + + private String keystorePass = null; public String getKeystorePass() { return keystorePass;} public void setKeystorePass(String s ) { this.keystorePass = s;} @@ -460,20 +475,16 @@ public abstract class AbstractEndpoint { public String getKeystoreType() { return keystoreType;} public void setKeystoreType(String s ) { this.keystoreType = s;} + private String keystoreProvider = null; + public String getKeystoreProvider() { return keystoreProvider;} + public void setKeystoreProvider(String s ) { this.keystoreProvider = s;} + private String sslProtocol = "TLS"; public String getSslProtocol() { return sslProtocol;} public void setSslProtocol(String s) { sslProtocol = s;} - private String sslEnabledProtocols=null; //"TLSv1,SSLv3,SSLv2Hello" - private String[] sslEnabledProtocolsarr = new String[0]; - public String[] getSslEnabledProtocolsArray() { return this.sslEnabledProtocolsarr;} - public void setSslEnabledProtocols(String s) { - this.sslEnabledProtocols = s; - StringTokenizer t = new StringTokenizer(s,","); - sslEnabledProtocolsarr = new String[t.countTokens()]; - for (int i=0; i -

The password used to access the server certificate from the - specified keystore file. The default value is "changeit". +

The password used to access the specified keystore file. The default + value is the value of the keyPass attribute.

@@ -750,6 +750,12 @@ specified the first key read in the keystore will be used.

+ +

The password used to access the server certificate from the + specified keystore file. The default value is "changeit". +

+
+

The TrustStore file to use to validate client certificates.

@@ -772,6 +778,25 @@

+ +

The algorithm to use for truststore. If not specified, the default + value returned by + javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm() is + used.

+
+ + +

The certificate revocation list to be used to verify client + certificates. If not defined, client certificates will not be checked + against a certificate revocation list.

+
+ + +

The maximum number of intermediate certificates that will be allowed + when validating client certificates. If not specified, the default value + of 5 will be used.

+
+

The number of SSL sessions to maintain in the session cache. Use 0 to specify an unlimited cache size. If not specified, a default of 0 is @@ -784,11 +809,6 @@ default of 86400 (24 hours) is used.

- -

The certificate revocation list file to use to validate client - certificates.

-
-

Is unsafe legacy TLS renegotiation allowed which is likely to expose users to CVE-2009-3555, a man-in-the-middle vulnerability in the TLS -- 2.11.0