Class: SslCertificate::Certificate

Inherits:
OpenSSL::X509::Certificate
  • Object
show all
Defined in:
lib/ssl_certificate.rb

Instance Method Summary collapse

Instance Method Details

#alternative_namesObject



15
16
17
18
19
20
21
22
# File 'lib/ssl_certificate.rb', line 15

def alternative_names
  alt_name = extensions.find { |ex| ex.oid == 'subjectAltName' }
  if alt_name
    alt_name.value.split(',').map { |dns| dns.strip.gsub(/^DNS:/, '') }
  else
    nil
  end
end

#check_fqdn(fqdn) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ssl_certificate.rb', line 29

def check_fqdn(fqdn)
  matched = match_between(fqdn, common_name)
  if matched.nil? && alternative_names
    matched = alternative_names.find { |name| match_between(fqdn, name) }
  end
  matched ? true : false
end

#check_private_key_str(private_key_str) ⇒ Object



24
25
26
27
# File 'lib/ssl_certificate.rb', line 24

def check_private_key_str(private_key_str)
  private_key = OpenSSL::PKey::RSA.new(private_key_str)
  check_private_key(private_key)
end

#common_nameObject



6
7
8
9
10
11
12
13
# File 'lib/ssl_certificate.rb', line 6

def common_name
  common_name = subject.to_a.find { |value| value[0] == 'CN' }
  if common_name
    common_name[1]
  else
    nil
  end
end