title: kotlin library that can do httpS connection without certificate verification (like curl --insecure)
body: <p>I need to crawl internal company site that has expired/self-signed certificate. Noone is ever going to configure valid certificate for that host, so I have to use insecure connection. </p>
  
  <p><code>curl</code> has <code>--insecure</code> flag for that purpose,</p>
  
  <p>Scala finagle library has <code>.tlsWithoutValidation()</code> mode. </p>
  
  <p><strong>QUESTION</strong>: Is there a Kotlin library that has similar option?</p>
  
  <p><strong>UPD</strong>: so far I am using <a href="https://github.com/kittinunf/Fuel" rel="noreferrer">Fuel</a> with the javish workaround found <a href="https://stackoverflow.com/questions/36134445/how-to-solve-javax-net-ssl-sslhandshakeexception-java-security-cert-certificate">here</a> but still searching for better ways..</p>
  
  <pre><code>fun useInsecureSSL() {
  
      // Create a trust manager that does not validate certificate chains
      val trustAllCerts = arrayOf&lt;TrustManager&gt;(object : X509TrustManager {
          override fun getAcceptedIssuers(): Array&lt;X509Certificate&gt;? = null
          override fun checkClientTrusted(chain: Array&lt;X509Certificate&gt;, authType: String) = Unit
          override fun checkServerTrusted(chain: Array&lt;X509Certificate&gt;, authType: String) = Unit
      })
  
      val sc = SSLContext.getInstance("SSL")
      sc.init(null, trustAllCerts, java.security.SecureRandom())
      HttpsURLConnection.setDefaultSSLSocketFactory(sc.socketFactory)
  
      // Create all-trusting host name verifier
      val allHostsValid = HostnameVerifier { _, _ -&gt; true }
  
      // Install the all-trusting host verifier
      HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid)
  }
  </code></pre>
  
  <p>The above workaround works however it is too verbose and seems to set insecure mode for <strong>every</strong> connection made by my app, not only for the particular one. </p>