title: javax.net.ssl.SSLHandshakeException: "Remote host closed connection during handshake" opening an HTTPS page with HTMLUnit
body: <p>I'm trying to fetch the <strong>HTTPS</strong> page <a href="https://portal.mvp.bafin.de/database/AnteileInfo/" rel="nofollow noreferrer">https://portal.mvp.bafin.de/database/AnteileInfo/</a> using <strong><a href="http://htmlunit.sourceforge.net/" rel="nofollow noreferrer">HTML Unit</a></strong> 2.23 under <strong>Java 7</strong>, Ubuntu Linux.</p>
  
  <p>The following code worked until some days ago, but now I receive the exception reported below.</p>
  
  <p>The problem should be related to the type of security certificates used, but nothing changes executing the code with the vm option <strong>"-Dhttps.protocols=TLSv1.1,TLSv1.2"</strong> as I read <a href="https://stackoverflow.com/questions/21245796/javax-net-ssl-sslhandshakeexception-remote-host-closed-connection-during-handsh">here</a></p>
  
  <p>The code:</p>
  
  <pre><code>import java.io.IOException;
  import java.net.MalformedURLException;
  
  import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
  import com.gargoylesoftware.htmlunit.WebClient;
  import com.gargoylesoftware.htmlunit.html.HtmlPage;
  
  public class SSLTest {
  
      public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
          final String URL = "https://portal.mvp.bafin.de/database/AnteileInfo/";
          final WebClient wc = new WebClient();
          // the code should be ok without the following line,
          // but even with it, it doesn't work
          // wc.getOptions().setSSLClientProtocols(new String[]{"TLSv1.1","TLSv1.2"});
          final HtmlPage mainPage = wc.getPage(URL);
      }
  }
  </code></pre>
  
  <p>The exception is the following: <strong>Remote host closed connection during handshake</strong></p>
  
  <pre><code>Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:880)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1262)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1289)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1273)
      at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
      at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
      at com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory.connectSocket(HtmlUnitSSLConnectionSocketFactory.java:189)
      at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
      at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
      at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:183)
      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1358)
      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1275)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:451)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:436)
      at fetchers.bafin.SSLTest.main(SSLTest.java:16)
  Caused by: java.io.EOFException: SSL peer shut down incorrectly
      at sun.security.ssl.InputRecord.read(InputRecord.java:352)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:861)
      ... 23 more
  </code></pre>
  
  <p><strong>if uncomment the following line</strong></p>
  
  <pre><code>wc.getOptions().setSSLClientProtocols(new String[]{"TLSv1.1","TLSv1.2"});
  </code></pre>
  
  <p>I get the exception below, which gives a slightly different message: <strong>fatal alert: handshake_failure</strong></p>
  
  <pre><code>Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
      at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1911)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1027)
  [...]
  </code></pre>
  
  <p>Any suggestion?</p>