Skip to content

Instantly share code, notes, and snippets.

@rbobillot
Last active January 18, 2018 16:17
Show Gist options
  • Save rbobillot/ad28d88e7ff56ba5e530 to your computer and use it in GitHub Desktop.
Save rbobillot/ad28d88e7ff56ba5e530 to your computer and use it in GitHub Desktop.
/*
** To bypass SSL, just call
** SSLBypasser.bypassSSL
** in your main
*/
object SSLBypasser
{
import java.security.cert.X509Certificate
import javax.net.ssl._
object AllTM extends X509TrustManager
{
def getAcceptedIssuers: Array[X509Certificate] = null
def checkClientTrusted(certs: Array[X509Certificate], authType: String){}
def checkServerTrusted(certs: Array[X509Certificate], authType: String){}
}
object AllHosts extends HostnameVerifier
{
def verify(urlHostName: String, session: SSLSession) = true
}
def bypassSSL
{
val trustAllCerts = Array[TrustManager](AllTM)
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory)
HttpsURLConnection.setDefaultHostnameVerifier(AllHosts);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment