Skip to content

Instantly share code, notes, and snippets.

@thomasjachmann
Created September 6, 2011 16:47
Show Gist options
  • Save thomasjachmann/1198128 to your computer and use it in GitHub Desktop.
Save thomasjachmann/1198128 to your computer and use it in GitHub Desktop.
configures java to ignore invalid/untrusted ssl certificates
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