aliquot 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a327bbbe5f475b924454c120979cb3bc965c5363c2740366a9f1abea19a59707
4
- data.tar.gz: 044dd4f0c2daa2d72685133fbd27408247281449276c0e36cba1141778d98176
3
+ metadata.gz: 4fd348440efd40e2b2f67cbff74deb5100e7e68280710af2d67f6d64343122b7
4
+ data.tar.gz: 121a611e53d3d4745082877e0ab50d733349cc857d61abc905945b4392f7c193
5
5
  SHA512:
6
- metadata.gz: f25a55664501aa93322675512975d3471c4586112855d2d30f32b0f61fcad6240fdd3750d36e418feaa415f3a49ee752271f2d7c1dc5fe28cd6615fc5d16811b
7
- data.tar.gz: e48a4d748adc053caa2e8a7770d5ef580fee0867497fa2d98dfac8cfc202a8183e3e8c900b56bac1cd121a95fadc4d8699511442263e93076d10e95ce53407af
6
+ metadata.gz: 647493009e7daee01e264752c5fd1bd32969c4e1e3c9c1e78ee4e4f5bd074730d39144be9c07bc8757d653bd61301bf9eb11f1bb45339e39d83d4d1a1e5d0c44
7
+ data.tar.gz: cdc115e4500ddebdbbdb49b427ccb057162259c1f1400f5274e6d07a9e814333b07f2ea981a3b7b5151c9cac29ef9dbab8c7c90cdd61e31b56816a1c333a8777
@@ -28,4 +28,6 @@ module Aliquot
28
28
 
29
29
  # When shared_secret is invalid
30
30
  class InvalidSharedSecretError < Error; end
31
+
32
+ class InvalidMerchantIDError < Error; end
31
33
  end
@@ -17,7 +17,7 @@ module Aliquot
17
17
  # Parameters:
18
18
  # token_string:: Google Pay token (JSON string)
19
19
  # shared_secret:: Base64 encoded shared secret
20
- # merchant_id:: Google Pay merchant ID ("merchant:<SOMETHING>")
20
+ # merchant_id:: Google Pay merchant ID
21
21
  # signing_keys:: Signing keys fetched from Google
22
22
  def initialize(token_string, shared_secret, merchant_id,
23
23
  signing_keys: ENV['GOOGLE_SIGNING_KEYS'])
@@ -43,13 +43,15 @@ module Aliquot
43
43
  raise Error, "supported protocol versions are #{SUPPORTED_PROTOCOL_VERSIONS.join(', ')}"
44
44
  end
45
45
 
46
+ @recipient_id = validate_merchant_id
47
+
48
+ check_shared_secret
49
+
46
50
  if protocol_version == 'ECv2'
47
51
  @intermediate_key = validate_intermediate_key
48
52
  raise InvalidSignatureError, 'intermediate certificate expired' if intermediate_key_expired?
49
53
  end
50
54
 
51
- check_shared_secret
52
-
53
55
  check_signature
54
56
 
55
57
  @signed_message = validate_signed_message
@@ -100,6 +102,11 @@ module Aliquot
100
102
  @intermediate_key[:keyExpiration].to_i < cur_millis
101
103
  end
102
104
 
105
+ def validate_merchant_id
106
+ raise InvalidMerchantIDError unless /[[:graph:]]/ =~ @merchant_id
107
+ "merchant:#{@merchant_id}"
108
+ end
109
+
103
110
  def check_shared_secret
104
111
  begin
105
112
  decoded = Base64.strict_decode64(@shared_secret)
@@ -111,7 +118,7 @@ module Aliquot
111
118
  end
112
119
 
113
120
  def check_signature
114
- signed_string_message = ['Google', @merchant_id, protocol_version, @token[:signedMessage]].map do |str|
121
+ signed_string_message = ['Google', @recipient_id, protocol_version, @token[:signedMessage]].map do |str|
115
122
  [str.length].pack('V') + str
116
123
  end.join
117
124
  message_signature = Base64.strict_decode64(@token[:signature])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliquot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clearhaus
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.8'
61
+ version: '0.11'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.8'
68
+ version: '0.11'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement