Class: Passbook::Signer
- Inherits:
-
Object
- Object
- Passbook::Signer
- Defined in:
- lib/passbook/signer.rb
Instance Attribute Summary collapse
-
#certificate ⇒ Object
Returns the value of attribute certificate.
-
#key ⇒ Object
Returns the value of attribute key.
-
#key_hash ⇒ Object
Returns the value of attribute key_hash.
-
#p12_cert ⇒ Object
Returns the value of attribute p12_cert.
-
#password ⇒ Object
Returns the value of attribute password.
-
#wwdc_cert ⇒ Object
Returns the value of attribute wwdc_cert.
Instance Method Summary collapse
- #compute_cert ⇒ Object
-
#initialize(params = {}) ⇒ Signer
constructor
A new instance of Signer.
- #sign(data) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Signer
Returns a new instance of Signer.
8 9 10 11 12 13 14 |
# File 'lib/passbook/signer.rb', line 8 def initialize(params = {}) @certificate = params[:certificate] || Passbook.p12_certificate @password = params[:password] || Passbook.p12_password @key = params[:key] || (params.empty? ? Passbook.p12_key : nil) @wwdc_cert = params[:wwdc_cert] || Passbook.wwdc_cert compute_cert end |
Instance Attribute Details
#certificate ⇒ Object
Returns the value of attribute certificate.
6 7 8 |
# File 'lib/passbook/signer.rb', line 6 def certificate @certificate end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/passbook/signer.rb', line 6 def key @key end |
#key_hash ⇒ Object
Returns the value of attribute key_hash.
6 7 8 |
# File 'lib/passbook/signer.rb', line 6 def key_hash @key_hash end |
#p12_cert ⇒ Object
Returns the value of attribute p12_cert.
6 7 8 |
# File 'lib/passbook/signer.rb', line 6 def p12_cert @p12_cert end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/passbook/signer.rb', line 6 def password @password end |
#wwdc_cert ⇒ Object
Returns the value of attribute wwdc_cert.
6 7 8 |
# File 'lib/passbook/signer.rb', line 6 def wwdc_cert @wwdc_cert end |
Instance Method Details
#compute_cert ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/passbook/signer.rb', line 29 def compute_cert @key_hash = {} if key @key_hash[:key] = OpenSSL::PKey::RSA.new File.read(key), password @key_hash[:cert] = OpenSSL::X509::Certificate.new File.read(certificate) else p12 = OpenSSL::PKCS12.new File.read(certificate), password @key_hash[:key], @key_hash[:cert] = p12.key, p12.certificate end end |
#sign(data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/passbook/signer.rb', line 16 def sign(data) wwdc = OpenSSL::X509::Certificate.new File.read(wwdc_cert) pk7 = OpenSSL::PKCS7.sign key_hash[:cert], key_hash[:key], data.to_s, [wwdc], OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::DETACHED data = OpenSSL::PKCS7.write_smime pk7 str_debut = "filename=\"smime.p7s\"\n\n" data = data[data.index(str_debut)+str_debut.length..data.length-1] str_end = "\n\n------" data = data[0..data.index(str_end)-1] Base64.decode64(data) end |