Skip to content

Instantly share code, notes, and snippets.

@idletekz
Forked from thomastaylor312/disableSSL.groovy
Created February 21, 2018 03:06
Show Gist options
  • Save idletekz/c3476165af5706467324c7cff56c3b34 to your computer and use it in GitHub Desktop.
Save idletekz/c3476165af5706467324c7cff56c3b34 to your computer and use it in GitHub Desktop.
Disable SSL validation in Groovy
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment