Class: TLSChecker::CertificateChecker
- Inherits:
-
Object
- Object
- TLSChecker::CertificateChecker
- Defined in:
- lib/tls_checker/certificate_checker.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#starttls ⇒ Object
readonly
Returns the value of attribute starttls.
Instance Method Summary collapse
- #certificate ⇒ Object
- #check ⇒ Object
- #humanized_address ⇒ Object
-
#initialize(hostname, address, port, starttls) ⇒ CertificateChecker
constructor
A new instance of CertificateChecker.
- #service ⇒ Object
-
#to_e ⇒ Object
rubocop:disable Metrics/MethodLength.
- #to_s ⇒ Object
Constructor Details
#initialize(hostname, address, port, starttls) ⇒ CertificateChecker
Returns a new instance of CertificateChecker.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tls_checker/certificate_checker.rb', line 9 def initialize(hostname, address, port, starttls) @hostname = hostname @address = address @port = port @starttls = starttls @certificate = nil @certificate_failure = nil @tls_socket = nil end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
20 21 22 |
# File 'lib/tls_checker/certificate_checker.rb', line 20 def address @address end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
20 21 22 |
# File 'lib/tls_checker/certificate_checker.rb', line 20 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
20 21 22 |
# File 'lib/tls_checker/certificate_checker.rb', line 20 def port @port end |
#starttls ⇒ Object (readonly)
Returns the value of attribute starttls.
20 21 22 |
# File 'lib/tls_checker/certificate_checker.rb', line 20 def starttls @starttls end |
Instance Method Details
#certificate ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tls_checker/certificate_checker.rb', line 49 def certificate return @certificate unless @certificate.nil? if tls_socket.peer_cert @certificate = OpenSSL::X509::Certificate.new(tls_socket.peer_cert) else @certificate_failure = 'No peer certificate (TLS handshake failed?)' @certificate = false end rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketRecvTimeout, IO::TimeoutError => e @certificate_failure = "#{e.class.name}: #{e.}" @certificate = false end |
#check ⇒ Object
41 42 43 |
# File 'lib/tls_checker/certificate_checker.rb', line 41 def check !!certificate end |
#humanized_address ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/tls_checker/certificate_checker.rb', line 67 def humanized_address if @address.is_a?(Resolv::IPv6) "[#{@address}]" else @address.to_s end end |
#service ⇒ Object
63 64 65 |
# File 'lib/tls_checker/certificate_checker.rb', line 63 def service "X.509/#{hostname}/#{humanized_address}:#{port}" end |
#to_e ⇒ Object
rubocop:disable Metrics/MethodLength
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tls_checker/certificate_checker.rb', line 22 def to_e # rubocop:disable Metrics/MethodLength if certificate InternetSecurityEvent::TLSStatus.build(hostname, certificate) else { state: 'critical', description: @certificate_failure || "#{hostname} does not have a valid certificate", } end.merge( service: service, af: af, hostname: hostname, address: address.to_s, port: port, ttl: 12.hours.to_i, tags: ['tls-checker'], ) end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/tls_checker/certificate_checker.rb', line 45 def to_s description end |