Created
January 20, 2011 11:42
-
-
Save tothda/787776 to your computer and use it in GitHub Desktop.
Disable Java SSL certificate and hostname verification from JRuby
This file contains hidden or 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
require 'java' | |
class JavaTrustManager | |
include javax.net.ssl.X509TrustManager | |
include javax.net.ssl.HostnameVerifier | |
# implementation of X509TrustManager | |
def check_client_trusted(a, b); end | |
def check_server_trusted(a, b); end | |
def accepted_issuers | |
return nil | |
end | |
# implementation of HostnameVerifier | |
def verify(a,b) | |
return true | |
end | |
def self.trust_everything | |
sc = javax.net.ssl.SSLContext.getInstance("SSL") | |
inst = new() | |
trust_managers = [inst] | |
sc.init(nil, trust_managers, java.security.SecureRandom.new) | |
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) | |
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(inst); | |
end | |
end | |
JavaTrustManager.trust_everything |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment