Class: Passifier::Signing
- Inherits:
-
Object
- Object
- Passifier::Signing
- Defined in:
- lib/passifier/signing.rb
Overview
Class for Pass signing functionality
Instance Method Summary collapse
-
#initialize(key_pem, pass_phrase, certificate_pem, wwdr_pem) ⇒ Signing
constructor
A new instance of Signing.
-
#sha(content) ⇒ String
Generate a digest of the given content.
-
#sign(content) ⇒ String
Sign the given content.
Constructor Details
#initialize(key_pem, pass_phrase, certificate_pem, wwdr_pem) ⇒ Signing
Returns a new instance of Signing.
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
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
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 |