passkit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 14879f088666efc426ff4d2861589f526991129dd83f91a70d7bf8867f64071c
4
+ data.tar.gz: d52fca69a103bb5fd958502449e61ad194ba41928b8d1337c7f715cd799add79
5
+ SHA512:
6
+ metadata.gz: 37a9f00cc34e6f272ebb811a199fb9457eb750297b616bfd487cb091b48dad0fae0d5782674c50a70033eadd803767bdccc11b53f6e6b4149b5ecbf5c619bf54
7
+ data.tar.gz: ac193511be72f80a214a3e4bf4dd149430fc2682b4381368e6352e19635010298c623fe1b6c51b9b6f1323a062f023f1c2c45e53123a4fc801e2dfe9785be80d
data/.standard.yml ADDED
@@ -0,0 +1,2 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-21
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at coorasse@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in passkit.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "standard", "~> 1.3"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Alessandro Rodi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Passkit
2
+
3
+ Generate Wallet Passes for iOS.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'passkit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install passkit
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/passkit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/passkit/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Passkit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/passkit/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,24 @@
1
+ module Passkit
2
+ class PassesController < ActionController::Base
3
+ skip_before_action :verify_authenticity_token
4
+ before_action :decrypt_payload, only: :create
5
+
6
+ def create
7
+ send_file(fetch_pass(@payload))
8
+ end
9
+
10
+ private
11
+
12
+ def decrypt_payload
13
+ @payload = Passkit::UrlEncrypt.decrypt(params[:payload])
14
+ if DateTime.parse(@payload[:valid_until]).past?
15
+ head :not_found
16
+ end
17
+ end
18
+
19
+ def fetch_pass(payload)
20
+ generator = payload[:generator_type].constantize.find(payload[:generator_id])
21
+ Passkit::Factory.create_pass(generator)
22
+ end
23
+ end
24
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "passkit"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ Passkit::Engine.routes.draw do
4
+ resources :devices, only: [] do
5
+ post 'registrations/:pass_type_id/:serial_number' => 'registrations#create', as: :register
6
+ delete 'registrations/:pass_type_id/:serial_number' => 'registrations#destroy', as: :unregister
7
+ get 'registrations/:pass_type_id' => 'registrations#show', as: :registrations
8
+ end
9
+ get 'passes/:pass_type_id/:serial_number' => 'passes#show', as: :pass
10
+ get 'passes/:payload', to: 'passes#create', as: :passes
11
+ post 'log' => 'logs#create'
12
+ end
@@ -0,0 +1,9 @@
1
+ module Passkit
2
+ class Device < ActiveRecord::Base
3
+ validates_uniqueness_of :device_identifier
4
+ validates_uniqueness_of :push_token
5
+
6
+ has_many :registrations
7
+ has_many :passes, through: :registrations
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Passkit
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Passkit
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Passkit
2
+ class Factory
3
+ class << self
4
+ def create_pass(generator)
5
+ pass = Pass.create!(generator: generator)
6
+ Passkit::Generator.new(pass).generate_and_sign
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,115 @@
1
+ module Passkit
2
+ class Generator
3
+ TMP_FOLDER = Rails.root.join('tmp/pass_kit').freeze
4
+
5
+ def initialize(pass_name, pass)
6
+ @pass = pass
7
+ @generator = pass.generator
8
+ end
9
+
10
+ def generate_and_sign
11
+ create_temporary_directory
12
+ copy_pass_to_tmp_location
13
+ clean_ds_store_files
14
+ I18n.with_locale(@pass.language) do
15
+ generate_json_pass
16
+ end
17
+ generate_json_manifest
18
+ sign_manifest
19
+ compress_pass_file
20
+ end
21
+
22
+ private
23
+
24
+ def create_temporary_directory
25
+ FileUtils.mkdir_p(TMP_FOLDER) unless File.directory?(TMP_FOLDER)
26
+ @temporary_path = TMP_FOLDER.join(@pass.file_name)
27
+
28
+ FileUtils.rm_rf(@temporary_path) if File.directory?(@temporary_path)
29
+ end
30
+
31
+ def copy_pass_to_tmp_location
32
+ FileUtils.cp_r(@pass.pass_path, @temporary_path)
33
+ end
34
+
35
+ def clean_ds_store_files
36
+ Dir.glob(@temporary_path.join('**/.DS_Store')).each { |file| File.delete(file) }
37
+ end
38
+
39
+ # rubocop:disable Metrics/AbcSize
40
+ def generate_json_pass
41
+ pass = {
42
+ formatVersion: @pass.format_version,
43
+ teamIdentifier: @pass.apple_team_identifier,
44
+ foregroundColor: @pass.foreground_color,
45
+ backgroundColor: @pass.background_color,
46
+ webServiceURL: @pass.web_service_url,
47
+ barcode: @pass.barcode,
48
+ voided: @pass.voided,
49
+ organizationName: @pass.organization_name,
50
+ description: @pass.description,
51
+ logoText: @pass.logo_text,
52
+ locations: @pass.locations
53
+ }
54
+
55
+ pass = pass.merge({
56
+ serialNumber: @wallet_pass.serial_number,
57
+ passTypeIdentifier: @wallet_pass.pass_type_identifier,
58
+ authenticationToken: @wallet_pass.authentication_token
59
+ })
60
+
61
+ pass[@pass.pass_type] = {
62
+ headerFields: @pass.header_fields,
63
+ auxiliaryFields: @pass.auxiliary_fields,
64
+ backFields: @pass.back_fields
65
+ }
66
+
67
+ File.open(@temporary_path.join('pass.json'), 'w') { |f| f.write(pass.to_json) }
68
+ end
69
+
70
+ # rubocop:enable Metrics/AbcSize
71
+
72
+ def generate_json_manifest
73
+ manifest = {}
74
+ Dir.glob(@temporary_path.join('**')).each do |file|
75
+ manifest[File.basename(file)] = Digest::SHA1.hexdigest(File.read(file))
76
+ end
77
+
78
+ @manifest_url = @temporary_path.join('manifest.json')
79
+ File.open(@manifest_url, 'w') { |f| f.write(manifest.to_json) }
80
+ end
81
+
82
+ CERTIFICATE = Rails.root.join(ENV['PASSKIT_PRIVATE_P12_CERTIFICATE'])
83
+ INTERMEDIATE_CERTIFICATE = Rails.root.join(ENV['APPLE_INTERMEDIATE_CERTIFICATE'])
84
+ CERTIFICATE_PASSWORD = ENV['PASSKIT_CERTIFICATE_KEY']
85
+
86
+ # :nocov:
87
+ def sign_manifest
88
+ p12_certificate = OpenSSL::PKCS12.new(File.read(CERTIFICATE), CERTIFICATE_PASSWORD)
89
+ intermediate_certificate = OpenSSL::X509::Certificate.new(File.read(INTERMEDIATE_CERTIFICATE))
90
+
91
+ flag = OpenSSL::PKCS7::DETACHED | OpenSSL::PKCS7::BINARY
92
+ signed = OpenSSL::PKCS7.sign(p12_certificate.certificate,
93
+ p12_certificate.key, File.read(@manifest_url),
94
+ [intermediate_certificate], flag)
95
+
96
+ @signature_url = @temporary_path.join('signature')
97
+ File.open(@signature_url, 'w') { |f| f.syswrite signed.to_der }
98
+ end
99
+
100
+ # :nocov:
101
+
102
+ def compress_pass_file
103
+ zip_path = TMP_FOLDER.join("#{@pass.file_name}.pkpass")
104
+ zipped_file = File.open(zip_path, 'w')
105
+
106
+ Zip::OutputStream.open(zipped_file.path) do |z|
107
+ Dir.glob(@temporary_path.join('**')).each do |file|
108
+ z.put_next_entry(File.basename(file))
109
+ z.print File.read(file)
110
+ end
111
+ end
112
+ zip_path
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,4 @@
1
+ module Passkit
2
+ class Log < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Passkit
2
+ class Pass < ActiveRecord::Base
3
+ validates_uniqueness_of :serial_number
4
+
5
+ has_many :registrations
6
+ has_many :devices, through: :registrations
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ module Passkit
2
+ class UrlEncrypt
3
+ class << self
4
+ def encrypt(payload)
5
+ string = payload.to_json
6
+ cipher = cypher.encrypt
7
+ cipher.key = encryption_key
8
+ s = cipher.update(string) + cipher.final
9
+
10
+ s.unpack1('H*').upcase
11
+ end
12
+
13
+ def decrypt(string)
14
+ cipher = cypher.decrypt
15
+ cipher.key = encryption_key
16
+ s = [string].pack('H*').unpack('C*').pack('c*')
17
+
18
+ JSON.parse(cipher.update(s) + cipher.final, symbolize_names: true)
19
+ end
20
+
21
+ private
22
+
23
+ def encryption_key
24
+ Rails.application.secret_key_base[0..15]
25
+ end
26
+
27
+ def cypher
28
+ OpenSSL::Cipher.new('AES-128-CBC')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Passkit
4
+ VERSION = "0.1.0"
5
+ end
data/lib/passkit.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "passkit/version"
4
+ require 'passkit/engine'
5
+
6
+ module Passkit
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
data/sig/passkit.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Passkit
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Rodi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Passkit offers you a full Rails engine to serve Wallet Passes for iOS
14
+ and Android.
15
+ email:
16
+ - coorasse@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".standard.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - app/controllers/passkit/passes_controller.rb
29
+ - bin/console
30
+ - bin/setup
31
+ - config/routes.rb
32
+ - lib/passkit.rb
33
+ - lib/passkit/device.rb
34
+ - lib/passkit/engine.rb
35
+ - lib/passkit/factory.rb
36
+ - lib/passkit/generator.rb
37
+ - lib/passkit/log.rb
38
+ - lib/passkit/pass.rb
39
+ - lib/passkit/url_encrypt.rb
40
+ - lib/passkit/version.rb
41
+ - sig/passkit.rbs
42
+ homepage: https://github.com/coorasse/passkit
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://github.com/coorasse/passkit
47
+ source_code_uri: https://github.com/coorasse/passkit
48
+ changelog_uri: https://github.com/coorasse/passkit/blob/master/CHANGELOG.md
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.6.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.3.10
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Serve Wallet Passes for iOS and Android directly from your Rails app
68
+ test_files: []