Created
December 13, 2016 21:08
-
-
Save barata0/63705c0bcdd1054af2405e90c06f6b71 to your computer and use it in GitHub Desktop.
Ignore SSL certs in groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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