Skip to content

Instantly share code, notes, and snippets.

@barata0
Created December 13, 2016 21:08
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save barata0/63705c0bcdd1054af2405e90c06f6b71 to your computer and use it in GitHub Desktop.
Save barata0/63705c0bcdd1054af2405e90c06f6b71 to your computer and use it in GitHub Desktop.
Ignore SSL certs in groovy
def nullTrustManager = [
checkClientTrusted: { chain, authType -> },
checkServerTrusted: { chain, authType -> },
getAcceptedIssuers: { null }
]
def nullHostnameVerifier = [
verify: { hostname, session ->
//true
hostname.startsWith('yuml.me')
}
]
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL")
sc.init(null, [nullTrustManager as javax.net.ssl.X509TrustManager] as javax.net.ssl.X509TrustManager[], null)
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(nullHostnameVerifier as javax.net.ssl.HostnameVerifier)
def url = new URL('https://mysecureserver')
url.openStream()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment