Uri Benaya
Uri Benaya

Reputation: 21

getting SSL_connect ... sslv3 alert handshake failure when using .p12 file ruby

I'm trying to use a p12 file and password to open an https page using RestClient in ruby.

p12 = OpenSSL::PKCS12.new(File.read("#{RAILS_ROOT}/file.p12"), "pass")

resp = RestClient::Resource.new(url, :ssl_client_key => p12.key).get

than I get:

SSL_connect returned=1 errno=0 state=SSLv3 read finished A: sslv3 alert handshake failure

(RestClient is not mandatory - anything else will do)

what am I missing?

Upvotes: 2

Views: 3652

Answers (2)

Balaji Ravichandran
Balaji Ravichandran

Reputation: 368

You need to import your file.p12 file into your nssdb location.

mkdir /root/nssdb
pk12util -i /path-to/your/file.p12 -d /root/nssdb
certutil -L -d /root/nssdb/
export SSL_DIR = /root/nssdb

curl -X POST -H "Content-Type: text/xml" --data "#{xml}" --cert cert:password "https://yoururl.com" -v -k
chmod -R 777 /root/nssdb
chown -R user /root/nssdb

Embed this curl call in your ruby client. It will work.

Note: If you are using a different ssl version you need to add --tlsv1.0 to the curl command

Upvotes: 0

Eraden
Eraden

Reputation: 2858

You must install openssl package and reinstall ruby. Not sure that important:

rmdir $rvm_path/usr/ssl/certs
ln -s /etc/ssl/certs $rvm_path/usr/ssl

Necesery:

rvm pkg install openssl
rvm <(if exist) re>install <RUBY_VERSION> --with-openssl-dir=$rvm_path/usr

Upvotes: 1

Related Questions