Module: LeapCli::X509

Extended by:
X509
Included in:
X509
Defined in:
lib/leap_cli/util/x509.rb

Instance Method Summary collapse

Instance Method Details

#fingerprint(digest, cert_file) ⇒ Object

returns a fingerprint of a x509 certificate



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/leap_cli/util/x509.rb', line 14

def fingerprint(digest, cert_file)
  if cert_file.is_a? String
    cert = OpenSSL::X509::Certificate.new(Util.read_file!(cert_file))
  elsif cert_file.is_a? OpenSSL::X509::Certificate
    cert = cert_file
  elsif cert_file.is_a? CertificateAuthority::Certificate
    cert = cert_file.openssl_body
  end
  digester = case digest
    when "MD5" then Digest::MD5.new
    when "SHA1" then Digest::SHA1.new
    when "SHA256" then Digest::SHA256.new
    when "SHA384" then Digest::SHA384.new
    when "SHA512" then Digest::SHA512.new
  end
  digester.hexdigest(cert.to_der)
end