Skip to content

Instantly share code, notes, and snippets.

@vadikgo
Forked from thomastaylor312/disableSSL.groovy
Created March 6, 2020 11:21
Show Gist options
  • Save vadikgo/65360b846c93db9293f4204baf93e220 to your computer and use it in GitHub Desktop.
Save vadikgo/65360b846c93db9293f4204baf93e220 to your computer and use it in GitHub Desktop.

Revisions

  1. @thomastaylor312 thomastaylor312 created this gist Nov 3, 2016.
    14 changes: 14 additions & 0 deletions disableSSL.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    def nullTrustManager = [
    checkClientTrusted: { chain, authType -> },
    checkServerTrusted: { chain, authType -> },
    getAcceptedIssuers: { null }
    ]

    def nullHostnameVerifier = [
    verify: { hostname, session -> true }
    ]

    SSLContext sc = SSLContext.getInstance("SSL")
    sc.init(null, [nullTrustManager as X509TrustManager] as TrustManager[], null)
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
    HttpsURLConnection.setDefaultHostnameVerifier(nullHostnameVerifier as HostnameVerifier)