Class: LibGems::Security::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/libgems/security.rb

Overview

Basic OpenSSL-based package signing class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, cert_chain) ⇒ Signer

Returns a new instance of Signer.



780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/libgems/security.rb', line 780

def initialize(key, cert_chain)
  LibGems.ensure_ssl_available
  @algo = LibGems::Security::OPT[:dgst_algo]
  @key, @cert_chain = key, cert_chain

  # check key, if it's a file, and if it's key, leave it alone
  if @key && !@key.kind_of?(OpenSSL::PKey::PKey)
    @key = OpenSSL::PKey::RSA.new(File.read(@key))
  end

  # check cert chain, if it's a file, load it, if it's cert data, convert
  # it into a cert object, and if it's a cert object, leave it alone
  if @cert_chain
    @cert_chain = @cert_chain.map do |cert|
      # check cert, if it's a file, load it, if it's cert data, convert it
      # into a cert object, and if it's a cert object, leave it alone
      if cert && !cert.kind_of?(OpenSSL::X509::Certificate)
        cert = File.read(cert) if File::exist?(cert)
        cert = OpenSSL::X509::Certificate.new(cert)
      end
      cert
    end
  end
end

Instance Attribute Details

#cert_chainObject

Returns the value of attribute cert_chain.



778
779
780
# File 'lib/libgems/security.rb', line 778

def cert_chain
  @cert_chain
end

#keyObject

Returns the value of attribute key.



778
779
780
# File 'lib/libgems/security.rb', line 778

def key
  @key
end

Instance Method Details

#sign(data) ⇒ Object

Sign data with given digest algorithm



808
809
810
# File 'lib/libgems/security.rb', line 808

def sign(data)
  @key.sign(@algo.new, data)
end