Module: SSLInfo
- Defined in:
- lib/ssl_info.rb,
lib/ssl_info/version.rb
Overview
Docs to follow
Constant Summary collapse
- VERSION =
'1.0.0'.freeze
Class Method Summary collapse
- .cert ⇒ Object
- .common_name ⇒ Object
- .display_cert ⇒ Object
- .expires_in ⇒ Object
- .get_cert(domain_name, verify = false) ⇒ Object
- .issuer ⇒ Object
- .not_after ⇒ Object
- .not_before ⇒ Object
- .process_cert ⇒ Object
- .serial ⇒ Object
- .subject ⇒ Object
Class Method Details
.cert ⇒ Object
68 69 70 |
# File 'lib/ssl_info.rb', line 68 def self.cert @cert end |
.common_name ⇒ Object
84 85 86 |
# File 'lib/ssl_info.rb', line 84 def self.common_name @common_name end |
.display_cert ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/ssl_info.rb', line 58 def self.display_cert printf("Subject: #{@subject}\n") printf("Issuer: #{@issuer}\n") printf("Serial: #{@serial}\n") printf("Common Name: #{@common_name}\n") printf("Issued: #{@not_before}\n") printf("Expires: #{@not_after}\n") printf("Expires In: #{@expires_in} days\n") end |
.expires_in ⇒ Object
96 97 98 |
# File 'lib/ssl_info.rb', line 96 def self.expires_in @expires_in end |
.get_cert(domain_name, verify = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ssl_info.rb', line 20 def self.get_cert(domain_name, verify = false) begin uri = URI::HTTPS.build(host: domain_name) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE http.open_timeout = 10 http.read_timeout = 10 http.ssl_timeout = 10 http.start do |h| @cert = h.peer_cert end process_cert rescue SocketError, SystemCallError => e printf("Bad URL? #{e.}\n") rescue Net::OpenTimeout printf("Timed out. Is the site up?\n") rescue OpenSSL::SSL::SSLError => e printf("We're trying to validate your certificate using TLSv1 It looks like your server doesn't accept it: [#{$ERROR_INFO.}]\n") if e. =~ /sslv3.+tlsv1 alert/i end end |
.issuer ⇒ Object
76 77 78 |
# File 'lib/ssl_info.rb', line 76 def self.issuer @issuer end |
.not_after ⇒ Object
92 93 94 |
# File 'lib/ssl_info.rb', line 92 def self.not_after @not_after end |
.not_before ⇒ Object
88 89 90 |
# File 'lib/ssl_info.rb', line 88 def self.not_before @not_before end |
.process_cert ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ssl_info.rb', line 45 def self.process_cert return if @cert.nil? @subject = @cert.subject.to_s @common_name = @cert.subject.to_a.select { |name, _data, _type| name == 'CN' }.first[1] @issuer = @cert.issuer.to_a.select { |name, _data, _type| name == 'O' }.first[1] @serial = @cert.serial @version = @cert.version @not_before = @cert.not_before @not_after = @cert.not_after @expires_in = ((@not_after - Time.now) / 864_00).to_i end |
.serial ⇒ Object
80 81 82 |
# File 'lib/ssl_info.rb', line 80 def self.serial @serial end |
.subject ⇒ Object
72 73 74 |
# File 'lib/ssl_info.rb', line 72 def self.subject @subject end |