Class: SSLVerify
- Inherits:
-
Object
- Object
- SSLVerify
- Defined in:
- lib/support/ssl_verify.rb
Instance Method Summary collapse
-
#initialize ⇒ SSLVerify
constructor
A new instance of SSLVerify.
- #ssl_verify_peer?(uri) ⇒ Boolean
- #test_gateways ⇒ Object
- #try_host(http, path) ⇒ Object
Constructor Details
#initialize ⇒ SSLVerify
Returns a new instance of SSLVerify.
6 7 8 |
# File 'lib/support/ssl_verify.rb', line 6 def initialize @gateways = GatewaySupport.new.gateways end |
Instance Method Details
#ssl_verify_peer?(uri) ⇒ Boolean
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/support/ssl_verify.rb', line 72 def ssl_verify_peer?(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.ca_file = File.dirname(__FILE__) + '/certs/cacert.pem' http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.open_timeout = 60 http.read_timeout = 60 if uri.path.blank? try_host(http, "/") else try_host(http, uri.path) end return :success rescue OpenSSL::SSL::SSLError => ex return :fail, ex.inspect rescue Net::HTTPBadResponse, Errno::ETIMEDOUT, EOFError, SocketError, Errno::ECONNREFUSED, Timeout::Error => ex return :error, ex.inspect end |
#test_gateways ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/support/ssl_verify.rb', line 10 def test_gateways success, failed, missing, errored, disabled = [], [], [], [], [] puts "Verifying #{@gateways.count} SSL certificates\n\n" @gateways.each do |g| if !g.live_url missing << g unless g.abstract_class next end if !g.ssl_strict disabled << g end uri = URI.parse(g.live_url) result, = ssl_verify_peer?(uri) case result when :success print "." success << g when :fail print "F" failed << {:gateway => g, :message => } when :error print "E" errored << {:gateway => g, :message => } end end puts "\n\n\nFailed Gateways:" failed.each do |f| puts "#{f[:gateway].name} - #{f[:message]}" end puts "\n\nError Gateways:" errored.each do |e| puts "#{e[:gateway].name} - #{e[:message]}" end if missing.size > 0 puts "\n\nGateways missing live_url:" missing.each do |m| puts m.name end end if disabled.size > 0 puts "\n\nGateways with ssl_strict=false:" disabled.each do |d| puts d.name end end end |
#try_host(http, path) ⇒ Object
66 67 68 69 70 |
# File 'lib/support/ssl_verify.rb', line 66 def try_host(http, path) http.get(path) rescue Net::HTTPBadResponse, EOFError, SocketError http.post(path, "") end |