class PkiExpress::Signer

Attributes

cert_password[RW]
cert_thumb[RW]
output_file_path[RW]
trust_service_session[RW]

Public Class Methods

new(config=PkiExpressConfig.new) click to toggle source
Calls superclass method PkiExpress::BaseSigner::new
# File lib/pki_express/signer.rb, line 7
def initialize(config=PkiExpressConfig.new)
  super(config)
  @output_file_path = nil
  @pkcs12_path = nil
  @cert_thumb = nil
  @cert_password = nil
  @use_machine = false
  @trust_service_session = nil
end

Public Instance Methods

pkcs12() click to toggle source

region The “pkcs12” accessors

# File lib/pki_express/signer.rb, line 19
def pkcs12
  _get_pkcs12
end
pkcs12=(content_raw) click to toggle source
# File lib/pki_express/signer.rb, line 32
def pkcs12=(content_raw)
  _set_pkcs12(content_raw)
end
pkcs12_base64() click to toggle source
# File lib/pki_express/signer.rb, line 49
def pkcs12_base64
  _get_pkcs12_base64
end
pkcs12_base64=(pkcs12_base64) click to toggle source
# File lib/pki_express/signer.rb, line 63
def pkcs12_base64=(pkcs12_base64)
  _set_pkcs12_base64(pkcs12_base64)
end
pkcs12_path() click to toggle source
# File lib/pki_express/signer.rb, line 82
def pkcs12_path
  _get_pkcs12_path
end
pkcs12_path=(pkcs12_path) click to toggle source
# File lib/pki_express/signer.rb, line 91
def pkcs12_path=(pkcs12_path)
  _set_pkcs12_path(pkcs12_path)
end

Protected Instance Methods

verify_and_add_common_options(args) click to toggle source

endregion

# File lib/pki_express/signer.rb, line 109
def verify_and_add_common_options(args)
  # Verify and add common option between signers and signature starters.
  super(args)

  if !@cert_thumb && !@pkcs12_path && !@trust_service_session
    raise 'Neither the PKCS #12 file, the certificate\'s thumbprint nor the trust service session was provided'
  end

  if @cert_thumb
    args.append('--thumbprint')
    args.append(@cert_thumb)
    @version_manager.require_version('1.3')
  end

  if @pkcs12_path
    args.append('--pkcs12')
    args.append(@pkcs12_path)
    @version_manager.require_version('1.3')
  end

  if @cert_password
    args.append('--password')
    args.append(@cert_password)
    @version_manager.require_version('1.3')
  end

  if @use_machine
    args.append('--machine')
    @version_manager.require_version('1.3')
  end

  if @trust_service_session
    args.append('--trust-service-session')
    args.append(@trust_service_session)
    # This option can only be used on versions greater than 1.18 of
    # the PKI Express.
    @version_manager.require_version('1.18')
  end
end

Private Instance Methods

_get_pkcs12() click to toggle source
# File lib/pki_express/signer.rb, line 23
def _get_pkcs12
  unless @pkcs12_path
    return nil
  end

  File.read(@pkcs12_path)
end
_get_pkcs12_base64() click to toggle source
# File lib/pki_express/signer.rb, line 53
def _get_pkcs12_base64
  unless @pkcs12_path
    return nil
  end

  content = File.read(@pkcs12_path)
  Base64.encode64(content)
end
_get_pkcs12_path() click to toggle source
# File lib/pki_express/signer.rb, line 86
def _get_pkcs12_path
  @pkcs12_path
end
_set_pkcs12(content_raw) click to toggle source
# File lib/pki_express/signer.rb, line 36
def _set_pkcs12(content_raw)
  unless content_raw
    raise 'The provided "pkcs12" is not valid'
  end

  temp_file_path = self.create_temp_file
  File.open(temp_file_path, 'wb') do |f|
    f.write(content_raw)
  end
  @pkcs12_path = temp_file_path
end
_set_pkcs12_base64(pkcs12_base64) click to toggle source
# File lib/pki_express/signer.rb, line 67
def _set_pkcs12_base64(pkcs12_base64)
  unless pkcs12_base64
    raise 'The provided "pkcs12_base64" is not valid'
  end

  begin
    content_raw = Base64.decode64(pkcs12_base64)
  rescue Error
    raise 'The provided "pkcs12_base64" is not Base64-encoded'
  end

  _set_pkcs12(content_raw)
end
_set_pkcs12_path(pkcs12_path) click to toggle source
# File lib/pki_express/signer.rb, line 95
def _set_pkcs12_path(pkcs12_path)
  unless pkcs12_path
    raise 'The provided "pkcs12_path" is not valid'
  end
  unless File.exists?(pkcs12_path)
    raise 'The provided "pkcs12_path" does not exist'
  end

  @pkcs12_path = pkcs12_path
end