Ruby SSL with Twitter failed on cert OpenSSL issue on Windows 7 -


i've searched high , low answer this. many people have own answers. none of them have worked me. i'll provide situation.

so want access twitter , upon using net:http's post function error.

ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed 

yes know get's message.

here viable solutions found.

first; manually set cert file:

#! /usr/bin/env ruby require 'net/https' require 'uri'  uri = uri.parse(argv[0] || 'https://localhost/') http = net::http.new(uri.host, uri.port) if uri.scheme == "https"   http.use_ssl = true   http.verify_mode = openssl::ssl::verify_peer   http.ca_file = file.join(file.dirname(__file__), "cacert.pem") end http.start {   http.request_get(uri.path) {|res|     print res.body   } } 

this provided ariejan de vroom @ link http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/

many people have given similar answer this. did not work me.

then found brought me along right path. guy mislav marohnić http://mislav.uniqpath.com/2013/07/ruby-openssl/ nailed area of concern. has openssl::x509::default_cert_file , openssl::x509::default_cert_dir . turns out hard coded ruby 1.9.3 through it's source code. mislav give's work around so:

require 'https'  http = net::http.new('example.com', 443) http.use_ssl = true http.verify_mode = openssl::ssl::verify_peer  http.cert_store = openssl::x509::store.new http.cert_store.set_default_paths http.cert_store.add_file('/path/to/cacert.pem') # ...or: cert = openssl::x509::certificate.new(file.read('mycert.pem')) http.cert_store.add_cert(cert) 

i dabbled around , error

openssl::x509::storeerror: cert in hash table 

bah humbug , stuff!

i should mention has written script should debug what's going on. may you, not in case. link on page.

oh yeah. set

env['ssl_cert_file'] env['ssl_cert_dir'] 

in ruby code without success.

then proceeded set environment variables in windows start -> control panel -> system -> advanced system settings -> advanced(tab) -> environment variables -> system variables new , added ssl_cert_dir , ssl_cert_file. didn't work either.

and certified gem didn't work me... https://github.com/stevegraham/certified

so provide hack answer windows 7 users out there below.

so dug around , stared @ hard coded path of certs. typing @ command line

ruby -ropenssl -e 'puts openssl::x509::default_cert_file' 

i got following...

c:/users/luis/code/openknapsack/knap-build/var/knapsack/software/x86-windows/openssl/1.0.0k/ssl/cert.pem 

so solution first download cacert.pem http://curl.haxx.se/ca/cacert.pem c:\ . open windows control panel -> administrative tools -> windows powershell modules. proceeded type out:

cd \ cd users mkdir luis cd luis mkdir code cd code mkdir openknapsack cd openknapsack mkdir knap-build cd knap-build mkdir var cd var mkdir knapsack cd knapsack mkdir software cd software mkdir x86-windows cd x86-windows mkir openssl cd openssl mkdir 1.0.0k cd 1.0.0k mkdir ssl cd ssl cp c:\cacert.pem .\cert.pem 

and works! yes it's cheap hack , it's ugly. both , can doing serious coding , not worry pesky problems.

i know it's not great fix, it's thing worked me, , should too.

if 1 write powershell script auto install cert file directory more deploy ruby project windows 7. thought.

by way, can duplicate process operating system should need arise. find path cert file belongs in with:

ruby -ropenssl -e 'puts openssl::x509::default_cert_file' 

and sure rename file appears in ouput!


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -