Skip to content

Commit

Permalink
Rename to Gala
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Feb 19, 2015
1 parent 6a93cb1 commit c82c063
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: .
specs:
apple_pay (0.1.0)
gala (0.2.0)
aead

GEM
Expand All @@ -24,4 +24,4 @@ PLATFORMS

DEPENDENCIES
aead!
apple_pay!
gala!
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.*

Expand All @@ -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")
Expand All @@ -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
```
Expand Down
16 changes: 7 additions & 9 deletions apple_pay.gemspec → gala.gemspec
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
1 change: 0 additions & 1 deletion lib/apple_pay.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/apple_pay/version.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/gala.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative "gala/payment_token"
4 changes: 2 additions & 2 deletions lib/apple_pay/token.rb → lib/gala/payment_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions lib/gala/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Gala
VERSION = "0.2.0" unless defined? Gala::VERSION
end
26 changes: 13 additions & 13 deletions test/apple_pay_token_test.rb → test/payment_token_test.rb
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down

0 comments on commit c82c063

Please sign in to comment.