Class: WebNotification::NotificationPackage
- Inherits:
-
Object
- Object
- WebNotification::NotificationPackage
- Includes:
- Singleton
- Defined in:
- lib/web_notification/notification_package.rb
Instance Attribute Summary collapse
-
#cert_path ⇒ Object
Returns the value of attribute cert_path.
-
#files ⇒ Object
Returns the value of attribute files.
-
#json ⇒ Object
Returns the value of attribute json.
-
#p12 ⇒ Object
Returns the value of attribute p12.
-
#wwdr_intermediate_certificate ⇒ Object
Returns the value of attribute wwdr_intermediate_certificate.
-
#wwdr_intermediate_certificate_path ⇒ Object
Returns the value of attribute wwdr_intermediate_certificate_path.
Instance Method Summary collapse
Instance Attribute Details
#cert_path ⇒ Object
Returns the value of attribute cert_path.
12 13 14 |
# File 'lib/web_notification/notification_package.rb', line 12 def cert_path @cert_path end |
#files ⇒ Object
Returns the value of attribute files.
12 13 14 |
# File 'lib/web_notification/notification_package.rb', line 12 def files @files end |
#json ⇒ Object
Returns the value of attribute json.
12 13 14 |
# File 'lib/web_notification/notification_package.rb', line 12 def json @json end |
#p12 ⇒ Object
Returns the value of attribute p12.
12 13 14 |
# File 'lib/web_notification/notification_package.rb', line 12 def p12 @p12 end |
#wwdr_intermediate_certificate ⇒ Object
Returns the value of attribute wwdr_intermediate_certificate.
12 13 14 |
# File 'lib/web_notification/notification_package.rb', line 12 def wwdr_intermediate_certificate @wwdr_intermediate_certificate end |
#wwdr_intermediate_certificate_path ⇒ Object
Returns the value of attribute wwdr_intermediate_certificate_path.
12 13 14 |
# File 'lib/web_notification/notification_package.rb', line 12 def wwdr_intermediate_certificate_path @wwdr_intermediate_certificate_path end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
14 15 16 |
# File 'lib/web_notification/notification_package.rb', line 14 def configure yield self end |
#generate_with_auth_token(authentication_token) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/web_notification/notification_package.rb', line 18 def generate_with_auth_token(authentication_token) files = {} path = "notification/web_package" Dir.glob(path+"/**/**").each do |file_path| next if File.directory? file_path filename = Pathname.new(file_path).relative_path_from(Pathname.new(path)) file = File.open(file_path, "rb") files[filename.to_s] = File.read(file) end json = JSON.parse(files['website.json']) json['authenticationToken'] = authentication_token files['website.json'] = JSON.pretty_generate(json) manifest = {} files.each do |filename, content| manifest[filename] = Digest::SHA1.hexdigest(content) end files['manifest.json'] = JSON.pretty_generate(manifest) flag = OpenSSL::PKCS7::BINARY|OpenSSL::PKCS7::DETACHED signed = OpenSSL::PKCS7::sign(p12.certificate, p12.key, files['manifest.json'], [wwdr_intermediate_certificate], flag) files['signature'] = signed.to_der.force_encoding('UTF-8') stringio = Zip::ZipOutputStream::write_buffer do |z| files.each do |filename, content| z.put_next_entry filename z.print content end end stringio.set_encoding "binary" stringio.rewind stringio end |