20

In my java Code i am creating one instance of SSL Context using command

SSLContext ctx = SSLContext.getInstance("TLS");

But in my tomcat server i am setting TLSv1.2 and i am getting handshake error.

How we can support all the TLS protocols using this method like in cpp we have SSLV23 client method which will support all protocols.

mahan07
  • 887
  • 4
  • 14
  • 32
  • 3
    Which version of Java do you use? – Uwe Plonus Apr 24 '15 at 08:00
  • 6
    SSLContext ctx = SSLContext.getInstance("TLSv1.2"); suports all protocols :) – mahan07 Apr 24 '15 at 09:43
  • 5
    *`SSLContext ctx = SSLContext.getInstance("TLS");`* - it gets worse. On Java 8 and below, you also get SSLv3. A bug report was filed with Oracle, but it was closed as "won't fix" because its by design. Also see [Which Cipher Suites to enable for SSL Socket?](http://stackoverflow.com/a/23365536/608639) – jww Apr 24 '15 at 09:58
  • do you've the bug id? – Kay Feb 24 '18 at 00:26
  • @mahan07 `SSLContext.getInstance("TLSv1.2")` does not necessarily support all protocols - it depends of JVM. In my case the class configured like this cannot connect to an Apache server using TLSv1 being run on IBM JVM 1.7.0 when it **can** connect being run on Oracle JVM 1.7.0. – polarfish May 01 '18 at 06:05

1 Answers1

24

To use TLSv1.2 try to use below code:

SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, null, null);
Rahim Rahimov
  • 1,347
  • 15
  • 24
  • May I know how to apply this `sslContext` into my `RestTemplate`? I am working in Spring version 3.0.x, keep trying but cant get it. – Panadol Chong Apr 18 '19 at 02:19
  • https://stackoverflow.com/questions/52836065/i-o-error-on-post-request-for-java-net-socketexception-connection-reset/55333280#55333280 – Camil Sep 09 '22 at 09:11