Skip to content

Instantly share code, notes, and snippets.

@hartsock
Created September 20, 2012 15:41
Show Gist options
  • Save hartsock/3756681 to your computer and use it in GitHub Desktop.
Save hartsock/3756681 to your computer and use it in GitHub Desktop.
Make the JVM trust all SSL certs
void trustAllSSL() {
def trustAllTrustManager = [
checkClientTrusted: { chain, authType -> },
checkServerTrusted: { chain, authType -> },
getAcceptedIssuers: { null }
]
def trustAllHostnameVerifier = [
verify: { hostname, session -> true }
]
def sc = javax.net.ssl.SSLContext.getInstance("SSL")
sc.init(null, [trustAllTrustManager as javax.net.ssl.X509TrustManager] as javax.net.ssl.TrustManager[], null)
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
trustAllHostnameVerifier as javax.net.ssl.HostnameVerifier)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment