1 #!<%= node[:ruby][:interpreter] %>
11 context = OpenSSL::SSL::SSLContext.new
12 context.verify_mode = OpenSSL::SSL::VERIFY_NONE
15 socket = TCPSocket.new(address, 443)
17 ssl = OpenSSL::SSL::SSLSocket.new(socket, context)
19 ssl.hostname = domains.first
21 rescue StandardError => e
22 puts "Error connecting to #{host}: #{e.message}"
26 certificate = ssl.peer_cert
27 chain = ssl.peer_cert_chain.drop(1)
30 if Time.now < certificate.not_before
31 puts "Certificate #{domains.first} on #{host} not valid until #{certificate.not_before}"
32 elsif certificate.not_after - Time.now < 21 * 86400
33 puts "Certificate #{domains.first} on #{host} expires at #{certificate.not_after}"
36 unless certificate.public_key.is_a?(OpenSSL::PKey::EC)
37 puts "Certificate #{domains.first} on #{host} does not use ECDSA key type"
40 subject_alt_name = certificate.extensions.find { |ext| ext.oid == "subjectAltName" }
42 if subject_alt_name.nil?
43 puts "Certificate #{domains.first} on #{host} has no subjectAltName"
45 alt_names = subject_alt_name.value.split(/\s*,\s*/).map { |n| n.sub(/^DNS:/, "") }
47 domains.each do |domain|
48 if alt_names.include?(domain)
49 alt_names.delete(domain)
51 puts "Certificate #{domains.first} on #{host} is missing subjectAltName #{domain}"
55 alt_names.each do |name|
56 puts "Certificate #{domains.first} on #{host} has unexpected subjectAltName #{name}"