Class: Passifier::Signing

Inherits:
Object
  • Object
show all
Defined in:
lib/passifier/signing.rb

Overview

Class for Pass signing functionality

Instance Method Summary collapse

Constructor Details

#initialize(key_pem, pass_phrase, certificate_pem, wwdr_pem) ⇒ Signing

Returns a new instance of Signing.

Parameters:

  • key_pem (String)

    The key pem file location

  • pass_phrase (String)

    The key pass phrase

  • certificate_pem (String)

    The certificate pem file location

  • wwdr_pem (String)

    The WWDR certificate pem file location



12
13
14
15
16
17
# File 'lib/passifier/signing.rb', line 12

def initialize(key_pem, pass_phrase, certificate_pem, wwdr_pem)
  @key = File.read(key_pem)
  @pass_phrase = pass_phrase
  @certificate = File.read(certificate_pem)
  @wwdr = File.read(wwdr_pem)
end

Instance Method Details

#sha(content) ⇒ String

Generate a digest of the given content

Parameters:

  • content (String)

    The content to generate a digest from

Returns:

  • (String)

    The resulting digest



22
23
24
25
# File 'lib/passifier/signing.rb', line 22

def sha(content)
  signed_contents = sign(content)
  Digest::SHA1.hexdigest(signed_contents)
end

#sign(content) ⇒ String

Sign the given content

Parameters:

  • content (String)

    The content to generate a signing of

Returns:

  • (String)

    The resulting signing



30
31
32
33
34
35
# File 'lib/passifier/signing.rb', line 30

def sign(content)
  key = OpenSSL::PKey::RSA.new(@key, @pass_phrase)
  certificate = OpenSSL::X509::Certificate.new(@certificate)
  wwdr = OpenSSL::X509::Certificate.new(@wwdr)
  OpenSSL::PKCS7.sign(certificate, key, content, [wwdr], OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::NOATTR | OpenSSL::PKCS7::DETACHED).to_der
end