The following code:
require 'net/https'
def get_http
http = Net::HTTP.new("ssltest7.bbtest.net", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
return http
end
puts "Without store: " +
(get_http.request(Net::HTTP::Get.new("/")).code rescue "FAIL")
store = OpenSSL::X509::Store.new
store.set_default_paths
http = get_http()
http.cert_store = store
puts "With store: " +
(http.request(Net::HTTP::Get.new("/")).code rescue "FAIL")
when run on 1.9.2-p180, outputs:
Without store: 200
With store: 200
However, on 1.8.7-p334, it outputs:
Without store: FAIL
With store: 200
In other words, VERIFY_PEER doesn’t work on 1.8.7 unless you provide a
certificate store. Is this expected, or is it a peculiarity of my
rvm-on-ubuntu-10.04 setup?
It’s worth noting that on jruby-1.6.0 I get:
Without store: FAIL
With store: FAIL
Is this a jruby bug? If not, how should I be setting up a Net::HTTP
for VERIFY_PEER?
–
Alex