forked from pact-foundation/pact_broker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbethtest.rb
30 lines (22 loc) · 874 Bytes
/
bethtest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'openssl'
require 'uri'
require 'net/http'
uri = URI('https://self-signed.badssl.com')
downloaded_cert_path = '/tmp/downloaded_cert.pem'
puts `openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -text`
command = "openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -outform PEM > #{downloaded_cert_path}"
puts command
puts `#{command}`
cert_store = OpenSSL::X509::Store.new
puts "Adding certificate #{downloaded_cert_path}"
cert_store.add_file(downloaded_cert_path)
req = Net::HTTP::Get.new(uri)
options = {
:use_ssl => uri.scheme == 'https',
verify_mode: OpenSSL::SSL::VERIFY_PEER,
cert_store: cert_store
}
response = Net::HTTP.start(uri.hostname, uri.port, options) do |http|
http.request req
end
puts response