Sha256: 6fca3eb969f86c289fe901b24fc2ab566162aa414902c46dcc17d288f87e6b2a

Contents?: true

Size: 827 Bytes

Versions: 4

Compression:

Stored size: 827 Bytes

Contents

require 'openssl'
require 'certificate_authority'
require 'digest'
require 'digest/md5'
require 'digest/sha1'

module LeapCli; module X509
  extend self

  #
  # returns a fingerprint of a x509 certificate
  #
  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


end; end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
leap_cli-1.5.6 lib/leap_cli/util/x509.rb
leap_cli-1.5.1 lib/leap_cli/util/x509.rb
leap_cli-1.5.0 lib/leap_cli/util/x509.rb
leap_cli-1.2.5 lib/leap_cli/util/x509.rb