Created
September 6, 2011 16:47
-
-
Save thomasjachmann/1198128 to your computer and use it in GitHub Desktop.
configures java to ignore invalid/untrusted ssl certificates
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
module JavaSslIgnorance | |
include Java | |
class TrustingTrustManager | |
include javax.net.ssl.X509TrustManager | |
def get_accepted_issuers; nil; end | |
def check_client_trusted(certs, auth_type); end | |
def check_server_trusted(certs, auth_type); end | |
end | |
class IndifferentHostnameVerifier | |
include javax.net.ssl.HostnameVerifier | |
def verify(hostname, session); true; end | |
end | |
def self.setup | |
sc = javax.net.ssl.SSLContext.get_instance('SSL') | |
sc.init(nil, [TrustingTrustManager.new], java.security.SecureRandom.new) | |
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.get_socket_factory) | |
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(IndifferentHostnameVerifier.new) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment