I'm having a terrible time getting SSL to verify a certificate. I'm completely ignorant on how certificates work so that's a major handicap to begin with. Here's the error I get when running the script:
c:/Ruby191/lib/ruby/1.9.1/net/http.rb:611:in `connect': SSL_connect returned=1 e
rrno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL
::SSL::SSLError)
Here's the relevant code:
client = Savon::Client.new order_svc
request = client.create_empty_cart { |soap, http|
http.auth.ssl.cert_file = 'mycert.crt'
http.auth.ssl.verify_mode = :none
http.read_timeout = 90
http.open_timeout = 90
http.headers = { "Content-Length" => "0", "Connection" => "Keep-Alive" }
soap.namespaces["xmlns:open"] = "http://schemas.datacontract.org/2004/07/Namespace"
soap.body = {
"wsdl:brand" => brand,
"wsdl:parnter" => [
{"open:catalogName" => catalogName, "open:partnerId" => partnerId }
] }.to_soap_xml
}
Any help is appreciated.
Putting the
http.auth.ssl.verify_mode = :none
inside theclient.request
block does not work for me.I had to use:
Using Savon 0.9.9 and Ruby 1.9.3-p125
check your cert.pem and your key.pem
the cert key should have one
your key.pem should have
and it may have some certs in it but that doesn't matter for this case. (Although it does for me as curl doesn't work without the extra certs) The webservice I am talking to has a good root CA, but the client auth keys are not trusted so this is probably why the extra certs make curl work.
getting those out of your client certificate was what caused me the problems.
here is what worked for me.
each will prompt you for the Import password and you can set a pem password if you want. (you would have to set that in the ruby code later)
you can also test with curl
My problem is that I am trying to validate a self-signed certificate. All I had to do was put the following code and omit anything to do with validating certificates.
I had to do this for both my SOAP and REST calls that were both experiencing the same issue.
SOAP using Savon
REST using HTTPClient
You need to provide the private key file that goes along with your certificate.
If your private key file is encrypted, you'll need to supply the password too: