title: How to force java SSLContext to use TLSv1.1
body: <p><strong>How do I get a jersey client to use TLSv1.1?</strong>
  I'm trying to force a com.sun.jersey.client.urlconnection.HTTPSProperties (jersey client code eventually goes to this class) to use <strong>TLSv1.1</strong> (or TLSv1) to write test code that confirms a server's protocols.
  As I setup the client, I do the following:</p>
  <pre><code>SSLContext context = SSLContext.getInstance(&quot;TLSv1.1&quot;);
  context.init(null, trustAll, new SecureRandom());
  HTTPSProperties props = new HTTPSProperties(hv, context);
  clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, props);
  </code></pre>
  <p>Inside HTTPSProperties (I downloaded the 1.x source so this may be wrong) I see:</p>
  <pre><code>public void setConnection(HttpsURLConnection connection) {
      if (hostnameVerifier != null)
          connection.setHostnameVerifier(hostnameVerifier);
      connection.setSSLSocketFactory(sslContext.getSocketFactory());
  }
  </code></pre>
  <p>If I use <code>SSLContext.getInstance(&quot;TLS&quot;);</code> instead, the code works fine. I've tried add <code>System.setProperty(&quot;https.protocols&quot;, &quot;TLSv1.1&quot;);</code> but it still doesn't work. The code above gives the stack trace:</p>
  <pre><code>Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
          at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
          at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
          at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2020)
          at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1127)
          at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
          at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
          at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
          at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
          at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1580)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1508)
          at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
          at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352)
          at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:240)
          at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
          ... 22 more
  </code></pre>
  <p><strong>My server</strong> (Jetty 9.4.41) thinks it is allowing TLSV1.1. When I dump the sslFactory I get:</p>
  <pre><code>I. 2021-09-29 16:37:59. [main] SSL context: Server@239105a8[provider=null,keyStore=file:***,trustStore=null] -
  STOPPED
      +&gt; trustAll=false
      +&gt; Protocol Selections
      |  +&gt; Enabled size=3
      |  |  +&gt; TLSv1.1
      |  |  +&gt; TLSv1.2
      |  |  +&gt; TLSv1.3
      |  +&gt; Disabled size=3
      |     +&gt; SSLv2Hello - ConfigExcluded:'SSLv2Hello', ConfigIncluded:NotSelected
      |     +&gt; SSLv3 - ConfigExcluded:'SSLv3', ConfigIncluded:NotSelected JVM:disabled
      |     +&gt; TLSv1 - ConfigExcluded:'TLSv1', ConfigIncluded:NotSelected JVM:disabled
      +&gt; Cipher Suite Selections
         +&gt; Enabled size=39
         |  +&gt; TLS_AES_128_GCM_SHA256
         |  +&gt; TLS_AES_256_GCM_SHA384
         |  +&gt; TLS_DHE_DSS_WITH_AES_128_CBC_SHA
         |  +&gt; TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
         |  +&gt; TLS_DHE_DSS_WITH_AES_128_GCM_SHA256
         |  +&gt; TLS_DHE_DSS_WITH_AES_256_CBC_SHA
         |  +&gt; TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
         |  +&gt; TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
         |  +&gt; TLS_DHE_RSA_WITH_AES_128_CBC_SHA
         |  +&gt; TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
         |  +&gt; TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
         |  +&gt; TLS_DHE_RSA_WITH_AES_256_CBC_SHA
         |  +&gt; TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
         |  +&gt; TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
         |  +&gt; TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
         |  +&gt; TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
         |  +&gt; TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
         |  +&gt; TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
         |  +&gt; TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
         |  +&gt; TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
         |  +&gt; TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
         |  +&gt; TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
         |  +&gt; TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
         |  +&gt; TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
         |  +&gt; TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
         |  +&gt; TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
         |  +&gt; TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
         |  +&gt; TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
         |  +&gt; TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
         |  +&gt; TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
         |  +&gt; TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
         |  +&gt; TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
         |  +&gt; TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
         |  +&gt; TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
         |  +&gt; TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
         |  +&gt; TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
         |  +&gt; TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
         |  +&gt; TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
         |  +&gt; TLS_EMPTY_RENEGOTIATION_INFO_SCSV
         +&gt; Disabled size=6
            +&gt; TLS_RSA_WITH_AES_128_CBC_SHA - ConfigExcluded:'^TLS_RSA_.*$'
            +&gt; TLS_RSA_WITH_AES_128_CBC_SHA256 - ConfigExcluded:'^TLS_RSA_.*$'
            +&gt; TLS_RSA_WITH_AES_128_GCM_SHA256 - ConfigExcluded:'^TLS_RSA_.*$'
            +&gt; TLS_RSA_WITH_AES_256_CBC_SHA - ConfigExcluded:'^TLS_RSA_.*$'
            +&gt; TLS_RSA_WITH_AES_256_CBC_SHA256 - ConfigExcluded:'^TLS_RSA_.*$'
            +&gt; TLS_RSA_WITH_AES_256_GCM_SHA384 - ConfigExcluded:'^TLS_RSA_.*$'
  </code></pre>
  <p><strong>Any help is appreciated! Thanks in advance.</strong></p>