title: Java 1.6 TLS 1.2 handshake_failure
body: <p>I'm trying to comunicate with an URI that uses TLS 1.2 using java jdk 1.6.30 and I tried to setup BouncyCastle provider on my system as TLS 1.2 is not suported by default on java jdk 1.6.30 I also instaled the certificate on my local machine but I'm receiving the following error:</p>
  
  <pre><code>Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1806)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:986)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1197)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1181)
      at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
      at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
      at main.main(main.java:22)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  </code></pre>
  
  <p>The code I'm using is as follows:</p>
  
  <pre><code>import org.bouncycastle.jce.provider.BouncyCastleProvider;
  
  import java.net.*;
  import java.security.Security;
  
  public class main {
  
      static {
          Security.addProvider(new BouncyCastleProvider());
      }
  
      public static void main(String[] args) throws Exception {
          final URL url = new URL("URL");
          final String postData = "POST_DATA";
          final byte[] postDataBytes = postData.getBytes("UTF-8");
          final HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
          httpURLConnection.setRequestMethod("POST");
          httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
          httpURLConnection.setDoOutput(true);
          httpURLConnection.getOutputStream().write(postDataBytes);
          httpURLConnection.getInputStream();
          System.out.println("OK");
      }
  }
  </code></pre>
  
  <p>I tried to google but I haven't found any solution (<a href="https://stackoverflow.com/questions/33517476/tls-1-2-java-1-6-bouncycastle">TLS 1.2 + Java 1.6 + BouncyCastle</a>, <a href="https://stackoverflow.com/questions/7844860/received-fatal-alert-handshake-failure-with-tomcat">Received fatal alert: handshake_failure with Tomcat</a>, etc).</p>
  
  <p>Is there anything I can try to trust the certificate?</p>
  
  <p>Thanks in advance</p>