diff --git a/Gemfile.lock b/Gemfile.lock index 016d814..bbfe730 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ GIT PATH remote: . specs: - apple_pay (0.1.0) + gala (0.2.0) aead GEM @@ -24,4 +24,4 @@ PLATFORMS DEPENDENCIES aead! - apple_pay! + gala! diff --git a/README.md b/README.md index 97e40d7..a0b9c7a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Apple Pay +# Gala -Ruby library for decrypting [Apple Pay tokens](https://developer.apple.com/library/ios/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html). +Named after the [Gala apple](http://en.wikipedia.org/wiki/Gala_(apple)), Gala is a Ruby library for decrypting [Apple Pay payment tokens](https://developer.apple.com/library/ios/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html). *Note: This library is not currently being used in a production environment. Please approach with caution.* @@ -9,22 +9,22 @@ Ruby library for decrypting [Apple Pay tokens](https://developer.apple.com/libra Add to your `Gemfile`: ```ruby -gem "apple_pay", git: "https://github.com/spreedly/apple_pay.git" +gem "gala", git: "https://github.com/spreedly/gala.git" ``` ## Usage -This Apple Pay library works by: +Gala works by: -1. Initializing an instance of `ApplePay::Token` with the hash of values present in the Apple Pay token string (a JSON representation of [this data](https://developer.apple.com/library/ios/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html)). +1. Initializing an instance of `Gala::PaymentToken` with the hash of values present in the Apple Pay token string (a JSON representation of [this data](https://developer.apple.com/library/ios/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html)). 2. Decrypting the token using the PEM formatted merchant certificate and private key (the latter of which, at least, is managed by a third-party such as a gateway or independent processor like [Spreedly](https://spreedly.com)). ```ruby -require "apple_pay" +require "gala" # token_json = raw token string you get from your iOS app token_attrs = JSON.parse(token_json) -token = ApplePay::Token.new(token_attrs) +token = Gala::PaymentToken.new(token_attrs) certificate_pem = File.read("mycert.pem") private_key_pem = File.read("private_key.pem") @@ -48,7 +48,7 @@ token.decrypt(certificate_pem, private_key_pem) ## Testing ```session -$ ruby test/apple_pay_token_test.rb +$ ruby test/payment_token_test.rb ... 5 tests, 18 assertions, 0 failures, 0 errors, 0 skips ``` diff --git a/apple_pay.gemspec b/gala.gemspec similarity index 59% rename from apple_pay.gemspec rename to gala.gemspec index 1d575ff..9ffb86d 100644 --- a/apple_pay.gemspec +++ b/gala.gemspec @@ -1,18 +1,16 @@ $LOAD_PATH.push File.expand_path("../lib", __FILE__) -require 'apple_pay/version' +require 'gala/version' Gem::Specification.new do |s| - s.name = "apple_pay" - s.version = ApplePay::VERSION + s.name = "gala" + s.version = Gala::VERSION s.platform = Gem::Platform::RUBY - s.author = "Mark Bennett" - s.email = ["mark@spreedly.com"] - s.homepage = "https://github.com/spreedly/apple_pay" - s.summary = "Apple Pay token decryption library" + s.authors = ["Mark Bennett", "Ryan Daigle"] + s.email = ["ryan@spreedly.com"] + s.homepage = "https://github.com/spreedly/gala" + s.summary = "Apple Pay payment token decryption library" s.description = "Given an (encrypted) Apple Pay token, verify and decrypt it" - s.rubyforge_project = "apple_pay" - s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } diff --git a/lib/apple_pay.rb b/lib/apple_pay.rb deleted file mode 100644 index eac352c..0000000 --- a/lib/apple_pay.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative "apple_pay/token" diff --git a/lib/apple_pay/version.rb b/lib/apple_pay/version.rb deleted file mode 100644 index 098a760..0000000 --- a/lib/apple_pay/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module ApplePay - VERSION = "0.1.0" unless defined? ApplePay::VERSION -end diff --git a/lib/gala.rb b/lib/gala.rb new file mode 100644 index 0000000..f98fe5a --- /dev/null +++ b/lib/gala.rb @@ -0,0 +1 @@ +require_relative "gala/payment_token" diff --git a/lib/apple_pay/token.rb b/lib/gala/payment_token.rb similarity index 98% rename from lib/apple_pay/token.rb rename to lib/gala/payment_token.rb index 5f43f70..36bfcf3 100644 --- a/lib/apple_pay/token.rb +++ b/lib/gala/payment_token.rb @@ -2,8 +2,8 @@ require 'base64' require 'aead' -module ApplePay - class Token +module Gala + class PaymentToken MERCHANT_ID_FIELD_OID = "1.2.840.113635.100.6.32" diff --git a/lib/gala/version.rb b/lib/gala/version.rb new file mode 100644 index 0000000..673ca3b --- /dev/null +++ b/lib/gala/version.rb @@ -0,0 +1,3 @@ +module Gala + VERSION = "0.2.0" unless defined? Gala::VERSION +end diff --git a/test/apple_pay_token_test.rb b/test/payment_token_test.rb similarity index 62% rename from test/apple_pay_token_test.rb rename to test/payment_token_test.rb index 7dc25ff..ee21f31 100644 --- a/test/apple_pay_token_test.rb +++ b/test/payment_token_test.rb @@ -1,46 +1,46 @@ $LOAD_PATH.push File.expand_path("../lib", __FILE__) require 'test/unit' require 'json' -require 'apple_pay' +require 'gala' -class ApplePay::TokenTest < Test::Unit::TestCase +class Gala::PaymentTokenTest < Test::Unit::TestCase def setup fixtures = File.dirname(__FILE__) + "/fixtures/" @token_attrs = JSON.parse(File.read(fixtures + "token.json")) @certificate = File.read(fixtures + "certificate.pem") @private_key = File.read(fixtures + "private_key.pem") - @apple_pay_token = ApplePay::Token.new(@token_attrs) + @payment_token = Gala::PaymentToken.new(@token_attrs) @merchant_id = "F938F4658CA2C1C9C38B8DFCB5DBB2A2245607DDE2F114620E8468EF52D208CA" @shared_secret = Base64.decode64("a2pPfemSdA560FnzLSv8zfdlWdGJTonApOLq1zfgx8w=") @symmetric_key = Base64.decode64("HOSago9Z1DhhukQvzmgpuCGPuwq1W0AgasMQWNZvUIY=") end def test_initialize - assert_equal @token_attrs["version"], @apple_pay_token.version - assert_equal @token_attrs["data"], @apple_pay_token.data - assert_equal @token_attrs["signature"], @apple_pay_token.signature - assert_equal @token_attrs["header"]["transactionId"], @apple_pay_token.transaction_id - assert_equal @token_attrs["header"]["ephemeralPublicKey"], @apple_pay_token.ephemeral_public_key - assert_equal @token_attrs["header"]["publicKeyHash"], @apple_pay_token.public_key_hash + assert_equal @token_attrs["version"], @payment_token.version + assert_equal @token_attrs["data"], @payment_token.data + assert_equal @token_attrs["signature"], @payment_token.signature + assert_equal @token_attrs["header"]["transactionId"], @payment_token.transaction_id + assert_equal @token_attrs["header"]["ephemeralPublicKey"], @payment_token.ephemeral_public_key + assert_equal @token_attrs["header"]["publicKeyHash"], @payment_token.public_key_hash end def test_merchant_id cert = OpenSSL::X509::Certificate.new(@certificate) - assert_equal @merchant_id, ApplePay::Token.extract_merchant_id(cert) + assert_equal @merchant_id, Gala::PaymentToken.extract_merchant_id(cert) end def test_shared_secret priv_key = OpenSSL::PKey::EC.new(@private_key) - assert_equal @shared_secret, ApplePay::Token.generate_shared_secret(priv_key, @token_attrs["header"]["ephemeralPublicKey"]) + assert_equal @shared_secret, Gala::PaymentToken.generate_shared_secret(priv_key, @token_attrs["header"]["ephemeralPublicKey"]) end def test_symmetric_key - assert_equal @symmetric_key, ApplePay::Token.generate_symmetric_key(@merchant_id, @shared_secret) + assert_equal @symmetric_key, Gala::PaymentToken.generate_symmetric_key(@merchant_id, @shared_secret) end def test_decrypt - payment_data = @apple_pay_token.decrypt(@certificate, @private_key) + payment_data = @payment_token.decrypt(@certificate, @private_key) assert_equal "4109370251004320", payment_data["applicationPrimaryAccountNumber"] assert_equal "200731", payment_data["applicationExpirationDate"] assert_equal "840", payment_data["currencyCode"]