10 context = OpenSSL::SSL::SSLContext.new
11 context.verify_mode = OpenSSL::SSL::VERIFY_NONE
14 socket = TCPSocket.new(address, 443)
16 ssl = OpenSSL::SSL::SSLSocket.new(socket, context)
18 ssl.hostname = domains.first
20 rescue StandardError => error
21 puts "Error connecting to #{host}: #{error.message}"
24 certificate = ssl.peer_cert
26 if Time.now < certificate.not_before
27 puts "Certificate #{domains.first} on #{host} not valid until #{certificate.not_before}"
28 elsif certificate.not_after - Time.now < 21 * 86400
29 puts "Certificate #{domains.first} on #{host} expires at #{certificate.not_after}"
31 subject_alt_name = certificate.extensions.find { |e| e.oid == "subjectAltName" }
33 if subject_alt_name.nil?
34 puts "Certificate #{domains.first} on #{host} has no subjectAltName"
36 alt_names = subject_alt_name.value.split(/\s*,\s*/).map { |n| n.sub(/^DNS:/, "") }
38 domains.each do |domain|
39 if alt_names.include?(domain)
40 alt_names.delete(domain)
42 puts "Certificate #{domains.first} on #{host} is missing subjectAltName #{domain}"
46 alt_names.each do |name|
47 puts "Certificate #{domains.first} on #{host} has unexpected subjectAltName #{name}"