A Probably-Secure Tomcat HTTPS Setup
Published on 7/6/2014
Edit %CATALINA_HOME%/conf/server.xml. We are doing a few things here:
- Setting up port 443 for HTTPS and port 80 to redirect to it
- Disabling insecure protocols (SSL)
- Disabling HTTP compression (HTTP compression with TLS may reveal session ids or CSRF tokens)
- using O/S User Environment Variables instead of putting passwords into files
- Using only good ciphers
Warning: Old clients might not work
<Connector
port ="80"
protocol ="org.apache.coyote.http11.Http11NioProtocol"
redirectPort ="443"
/>
<Connector
sslEnabledProtocols = "TLSv1.2, TLSv1.1, TLSv1"
compression = "off"
allowUnsafeLegacyRenegotiation = "false"
port = "443"
protocol = "org.apache.coyote.http11.Http11NioProtocol"
SSLEnabled = "true"
scheme = "https"
secure = "true"
keyAlias = "localhost"
keyPass = "${PWD_KEY_LOCALHOST}"
keystoreFile = "${user.home}/.keystore"
keystorePass = "${PWD_KEYSTORE}"
keystoreType = "JKS"
ciphers = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA"
/>
You would want to add the following to Tomcat’s web.xml to redirect http traffic to https:
<security-constraint>
<web-resource-collection>
<web-resource-name>HTTPSOnly</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
To pass O/S User Environment Variables to Tomcat, edit %CATALINA_BASE%/bin/setenv.bat :
set "CATALINA_OPTS=-DPWD_KEYSTORE=%PWD_KEYSTORE% -DPWD_KEY_LOCALHOST=%PWD_KEY_LOCALHOST%"
To create a keypair for your localhost development server, type:
keytool -genkeypair -validity 365 -keyalg EC -keysize 256 -alias localhost
When it (bizarrely) asks for your first and last name, type in localhost
To set O/S User Environment Variables, run cmd as that user, and type, for example SETX PWD_KEYSTORE s3cr3t