How can I get ruby ​​xmlrpc client to ignore SSL certificate errors?

When accessing the XML-RPC service using xmlrpc/client in ruby, it throws OpenSSL::SSL::SSLError when the server certificate is invalid. How can I make it ignore this error and continue the connection?

+8
ruby ssl xml-rpc
source share
2 answers

It calls it like this:

 xmlrpc = ::XMLRPC::Client.new("foohost") xmlrpc.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE) 

This works with ruby ​​1.9.2, but obviously shows the insides, so the real answer is: "The API does not provide such a mechanism, but hacking."

+12
source share

In fact, the client was updated, now it has direct access to the http connection: https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41286/diff/lib/xmlrpc/client. rb

 xmlrpc.http.verify_mode = OpenSSL::SSL::VERIFY_NONE 

But it is better to set ca_file or ca_path . However, I see no way to apply this configuration to _async calls.

Update: A workaround was found by decapitating the client object:

  xmlrpc_client.http.ca_file = @options[:ca_file] xmlrpc_client.instance_variable_set(:@ca_file, @options[:ca_file]) def xmlrpc_client.net_http(host, port, proxy_host, proxy_port) h = Net::HTTP.new host, port, proxy_host, proxy_port h.ca_file = @ca_file h end 

So, you need both, the older approach and the monkey fix. We also add an instance variable, otherwise the new method will not be able to see the actual value.

0
source share

Source: https://habr.com/ru/post/651301/


All Articles