-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignoring SSL verification errors #5
Comments
Example: require 'rubygems'
require 'http_client'
user_agent = 'testing'
client_opts = {
:connection_timeout => 10000,
:timeout_in_seconds => 30,
:user_agent => user_agent,
:handle_redirects => true,
:max_redirects => 10,
:use_ssl => true
}
client = HTTP::Client.new(client_opts)
get_req = HTTP::Get.new('https://www.netuno.net/')
result = client.execute(get_req) |
This can be somewhat solved by doing this: // Example java.security.Provider implementation
// that trusts ALL SSL certificates
// Regardless of whether they are valid or not
// Store this code in a file called MyProvider.java
import java.security.Security;
import java.security.KeyStore;
import java.security.Provider;
import java.security.cert.X509Certificate;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactorySpi;
import javax.net.ssl.X509TrustManager;
public class MyProvider extends Provider
{
public MyProvider()
{
super("MyProvider", 1.0, "Trust certificates");
put("TrustManagerFactory.TrustAllCertificates", MyTrustManagerFactory.class.getName());
}
protected static class MyTrustManagerFactory extends TrustManagerFactorySpi
{
public MyTrustManagerFactory()
{}
protected void engineInit( KeyStore keystore )
{}
protected void engineInit(ManagerFactoryParameters mgrparams )
{}
protected TrustManager[] engineGetTrustManagers()
{
return new TrustManager[] {new MyX509TrustManager()};
}
}
protected static class MyX509TrustManager implements X509TrustManager
{
public void checkClientTrusted(X509Certificate[] chain, String authType)
{}
public void checkServerTrusted(X509Certificate[] chain, String authType)
{}
public X509Certificate[] getAcceptedIssuers()
{ return null; }
}
} then
And now you can do this:
This seems to somewhat work. It will however still blow up when running into a http -> https redirect |
Ok, next approach, less java :) class TrustStrategy
def isTrusted(chain, auth_type)
return true;
end
end
[...]
http_client = HTTP::Client.new(@client_opts)
begin
get_req = HTTP::Get.new(url_to_crawl.to_s)
result = http_client.execute(get_req)
rescue javax.net.ssl.SSLPeerUnverifiedException
# Disable SSL
ssl_socket_factory = org.apache.http.conn.ssl.SSLSocketFactory.new(TrustStrategy.new)
scheme = org.apache.http.conn.scheme.Scheme.new('https', 443, ssl_socket_factory)
http_client.instance_variable_get('@client').getConnectionManager().getSchemeRegistry().register(scheme)
get_req = HTTP::Get.new(url_to_crawl.to_s.gsub('http:', 'https:'))
result = http_client.execute(get_req)
end Quite a hack, but it works for me for now... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use jruby-httpclient in an environment where I might run into self-signed SSL certs which usually leads to this:
I really don't care all that much about the validity of the SSL certs. Is there any way to disable the cert checking alltogether for jruby-httpclient?
The text was updated successfully, but these errors were encountered: