How do I tell Ruby's OpenSSL library to ignore

2020-07-22 03:48发布

问题:

I'm trying to use Ruby's SOAP support as follows:

SERVICE_URL = 'https://...'
...
def create_driver
  ::SOAP::WSDLDriverFactory.new(SERVICE_URL).create_rpc_driver
  driver.options['protocol.http.ssl_config.verify_mode']  = OpenSSL::SSL::VERIFY_NONE
  driver.options['protocol.http.ssl_config.client_cert']  = @certificate_path
  driver
end

but the call to new(SERVICE_URL) blows up with "OpenSSL::SSL::SSLError: certificate verify failed." How do I do the equivalent of driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE for the first call to retrieve the WSDL itself?

回答1:

I put a file called "soap/property" on my load path, e.g.:

- lib/
    - foo.rb
    - foo/
        - bar.rb
    - soap/
        - property

And put this in the file:

client.protocol.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE

Alternatively, if you have multiple settings with the same prefix, you can use the group syntax:

[client.protocol.http]
ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
...


回答2:

try this:

...
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
  ::SOAP::WSDLDriverFactory.new(SERVICE_URL).create_rpc_driver
...


回答3:

I stumbled across this url : https://gist.github.com/fnichol/867550 .This might be useful for anyone who is having similar problems.