Skip to main content

Groovy Script

The disableSSLVerification function is designed to disable SSL verification. This function allows connections to pass without verifying SSL certificates and hostnames. The following method is added and called before opening the connection to bypass PKIX error.
import javax.net.ssl.*
import java.security.cert.X509Certificate

def disableSSLVerification() {
   TrustManager[] trustAllCerts = [
       [
           checkClientTrusted: { X509Certificate[] certs, String authType -> },
           checkServerTrusted: { X509Certificate[] certs, String authType -> },
           getAcceptedIssuers: { null }
       ] as X509TrustManager
   ]
   SSLContext sc = SSLContext.getInstance("SSL")
   sc.init(null, trustAllCerts, new java.security.SecureRandom())
   HttpsURLConnection.setDefaultSSLSocketFactory(sc.socketFactory)
   HttpsURLConnection.setDefaultHostnameVerifier({ hostname, session -> true } as HostnameVerifier)
}
This function should be used carefully and only when necessary, as it can lead to security vulnerabilities. It can be used in insecure test environments or when verification process is not desired.