class X509Sleuth::ScannerDetailedPresenter

Public Instance Methods

parse_cn(cert) click to toggle source
# File lib/x509_sleuth/scanner_detailed_presenter.rb, line 50
def parse_cn(cert)
  subject_parts = cert.subject.to_s.split("/").collect{ |p| p.split("=") }
  common_name = ""
  subject_parts.each do |part|
    if part[0] && part[0] == "CN"
      common_name = part[1]
      break
    end
  end
  common_name
end
parse_san(cert) click to toggle source
# File lib/x509_sleuth/scanner_detailed_presenter.rb, line 62
def parse_san(cert)
  subject_alt_names = []
  cert.extensions.each do |extension|
    if extension.oid == "subjectAltName"
      subject_alt_names = extension.value.split(/[:,]|\s/).reject{ |part| part.nil? || part.empty? || part == "DNS" }
    end
  end
  subject_alt_names
end
tableize(clients) click to toggle source
# File lib/x509_sleuth/scanner_detailed_presenter.rb, line 6
def tableize(clients)
  clients.collect do |client|
    if client.peer_certificate
      {
        host: client.host,
        subject: client.peer_certificate.subject,
        common_name: parse_cn(client.peer_certificate),
        alt_names: parse_san(client.peer_certificate).join(","),
        issuer: client.peer_certificate.issuer,
        serial: client.peer_certificate.serial,
        not_before: client.peer_certificate.not_before, 
        not_after: client.peer_certificate.not_after
      }
    else
      {
        host: client.host,
        subject: "",
        common_name: "",
        alt_names: [],
        issuer: "",
        serial: "",
        not_before: "", 
        not_after: ""
      }
    end
  end
end
to_s() click to toggle source
# File lib/x509_sleuth/scanner_detailed_presenter.rb, line 34
def to_s
  Formatador.display_compact_table(
    tableize(filter),
    [
      :host,
      :subject,
      :common_name,
      :alt_names,
      :issuer,
      :serial,
      :not_before,
      :not_after
    ]
  )
end