27

I am trying to enable TLS 1.2 on Tomcat on Spring-boot 1.2.1. Android 5.0 is failing to connect to the default SSL settings, due to an SSL handshake failure. Android 4.4, iOS, Firefox, and Chrome all connect to the default version. I think this is because of a mismatch in the TLS protocols supported in Android 5.0 and the spring boot tomcat defaults (TLS v1?).

I imagine I want to change this application.properties setting:

server.ssl.protocol=TLS

but I have not located the other acceptable strings (or if there are any, even). There is no enumeration that I can find by searching on "protocol" in spring boot github. I have tried "TLSv1.2", but this appears to have no effect.

The current SSL configuration in application.properties is:

server.ssl.key-store = chainedcertificates.p12
server.ssl.key-store-password = secret
server.ssl.key-store-type = PKCS12

How do you enable TLS 1.2 in spring boot?

If it matters, I am using Java 1.7. The documentation for this seems to indicate it should support TLS 1.2.

Tomcat 8 seems to have support present. I am not sure how to check exactly which version is running in spring boot.

mattm
  • 5,851
  • 11
  • 47
  • 77
  • 1
    Boot passes the server.ssl.protocol setting through to Tomcat (https://github.com/spring-projects/spring-boot/blob/master/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java#L266) so it's Tomcat, rather than Boot, that determines the acceptable values. AFAIK, `TLSv1.2` is the value you need. – Andy Wilkinson Jan 17 '15 at 22:33

2 Answers2

28

You may experience an SSL handshake error due to the default ciphers that spring boot includes. It is recommended that you define a set of ciphers. We had a similar issue, and the way we fixed it was by using SSLScan on the caller and then scanning our system to see if there were any matches. This lead us to find out that there were no matches and helped us define a list of ciphers we should support.

Using SSLScan these are the default ciphers spring boot will use:

Preferred TLSv1.2  128 bits  ECDHE-RSA-AES128-GCM-SHA256   Curve P-256 DHE 256
Accepted  TLSv1.2  128 bits  ECDHE-RSA-AES128-SHA256       Curve P-256 DHE 256
Accepted  TLSv1.2  128 bits  ECDHE-RSA-AES128-SHA          Curve P-256 DHE 256
Accepted  TLSv1.2  128 bits  DHE-RSA-AES128-GCM-SHA256     DHE 1024 bits
Accepted  TLSv1.2  128 bits  DHE-RSA-AES128-SHA256         DHE 1024 bits
Accepted  TLSv1.2  128 bits  DHE-RSA-AES128-SHA            DHE 1024 bits

To enable TLS 1.2 and to define the cipher list please do the following:

#enable/diable https
server.ssl.enabled=true

#ssl ciphers
server.ssl.ciphers=TLS_RSA_WITH_AES_128_CBC_SHA256, INCLUDE_ANY_OTHER_ONES_YOU_NEED_TO_SUPPORT

# SSL protocol to use.
server.ssl.protocol=TLS

# Enabled SSL protocols.
server.ssl.enabled-protocols=TLSv1.2

For a list of of ciphers you can use https://testssl.sh/openssl-rfc.mapping.html and https://msdn.microsoft.com/en-us/library/windows/desktop/mt813794(v=vs.85).aspx

Dot Batch
  • 608
  • 6
  • 17
  • where did you find all the property names ? Is there spring doc for that ? – magulla Oct 30 '18 at 22:48
  • 2
    @magulla yeah you can find it here. https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html – Dot Batch Nov 01 '18 at 01:02
  • @DotBatch, can I make server.ssl.ciphers multiline? – Artanis Zeratul Jun 24 '19 at 07:03
  • @ArtanisZeratul If you are using YAML you can. https://stackoverflow.com/a/3790497/2939985 Duplicate property keys are not allowed. – Dot Batch Jun 24 '19 at 14:41
  • Thanks @DotBatch, I am using application.properties file. But I found the answer here: https://stackoverflow.com/questions/11610789/java-properties-file-using-multiple-lines-for-one-property/11610808 – Artanis Zeratul Jun 24 '19 at 22:58
  • 1
    Thanks @DotBatch for giving me this clue. This helped get a mark of A in https://www.ssllabs.com/ssltest/ by combining your settings here and tweaking the ciphers by using what is recommended in here: https://weakdh.org/sysadmin.html and just used the 256-based algorithms. – Artanis Zeratul Jun 25 '19 at 02:29
  • Not sure you can use `server.ssl.protocol` property to configure tomcat. It seems `org.apache.tomcat.util.net.SSLHostConfig` has a default set of protocols and spring doesn't expose a way to modify those defaults. Uncovered this in my own attempts at denying anything other than TLSv1.2 – Norbert Jan 06 '20 at 22:35
  • Thanks. These 2 lines solved the issue for me `server.ssl.protocol=TLS server.ssl.enabled-protocols=TLSv1.2` – samir105 Feb 13 '20 at 08:00
  • @DotBatch how did you find the cipher list supported by spring boot from using sslscan? – learner May 14 '20 at 11:12
  • @user10237300 Are you asking how do you use sslscan? In terminal `./sslscan [host]` The list of ciphers Spring Boot leverages depends on the version of openssl installed so you may see variance. – Dot Batch May 23 '20 at 21:40
17

TLS 1.2 is enabled by default in spring-boot 1.2.1. This can be verified by running the following from the command line

openssl s_client -connect serverAddress:port

which outputs

SSL-Session:
Protocol  : TLSv1.2
Cipher    : ECDHE-RSA-AES256-SHA384

So my problem must be something separate.

mattm
  • 5,851
  • 11
  • 47
  • 77
  • We're experiencing a similar issue where an android client fails to connect our spring boot 1.4.1 enabled server powered by embedded tomcat with ssl. We failed to nail down the root cause but we do suspect it's a mismatch with the ssl protocol as you mentioned. Were you able to solve this and can share your path? Thnx – baraka Nov 12 '16 at 18:00
  • @baraka The root of my problem was a bug in the implementation of Android. See http://stackoverflow.com/questions/28011581/websocket-ssl-handshake-failure. This bug was triggered by the Tyrus reference websocket, but not by other implementations like AndroidAsync or nv-websocket. Not sure whether this is relevant to your particular case. – mattm Nov 12 '16 at 21:12
  • I am having the same problem...did you manage to fix this guys? – mor222 Jan 30 '18 at 15:33
  • @mor222 see my answer. You may also be having an issue due to cipher mismatch. I also include how to enable tls 1.2 – Dot Batch Feb 03 '18 at 21:32
  • @DotBatch thanks for your answer. I actually found the problem on my server. It was exactly the problem with cipher mismatch. – mor222 Feb 04 '18 at 21:58
  • I am facing issue with the browser. cipher suite mismatch. – learner May 16 '20 at 07:11