aliquot-pay 2.1.1 → 2.2.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: 5f1155997b8d956147e17ca76c1fa36341675f9a8ba4932b3d6a1a6152bec885
4
- data.tar.gz: aec39bc7bac88cc34ae9d36b4d09af287c42247b23c1e134c930e90d6dc86c75
3
+ metadata.gz: df10b773da7321ea564c012fd5d487c07c0779ced77d1535e3b3a10691157b39
4
+ data.tar.gz: c6231c0006e33298f414ced2e286ac45ef4df5f16a2efa633a8025e1373fca15
5
5
  SHA512:
6
- metadata.gz: d096ada956941cb30fd187db28f8b83665bd8b667280cd834fed2b2b1fa9535d73a163941674ef11702f429fef1b5804168059f56e02d53478bf0212e9fe3f30
7
- data.tar.gz: ea714b68416696db99049926200cefdcc65f2a14ac55ee6d5ead1c7132d4de0420b3b429610ef3637e1ed2aad3763edcc3162fa8a873bd686a915f04e3e53806
6
+ metadata.gz: 32790400342af932a01adeaaf8cb0ed943ffe2343954972deb4d20f7e5e34482ff71ab924f395221db3affd0128cfeb8b6ae95cc19d1c19dbcedde0d2ca963a6
7
+ data.tar.gz: 23aa8bec6cb97d8ec513e1fb6323f35b60f7ad1baca8627d4091e2898b1d1a03f38882b1949f34f56064bde33ba330978b84b0a69c0f321c35639bba26539d02
@@ -4,7 +4,7 @@ require 'hkdf'
4
4
  class AliquotPay
5
5
  class Util
6
6
  def self.generate_ephemeral_key
7
- OpenSSL::PKey::EC.new(AliquotPay::EC_CURVE).generate_key
7
+ OpenSSL::PKey::EC.generate(AliquotPay::EC_CURVE)
8
8
  end
9
9
 
10
10
  def self.generate_shared_secret(private_key, public_key)
data/lib/aliquot-pay.rb CHANGED
@@ -18,7 +18,7 @@ class AliquotPay
18
18
  attr_accessor :signed_key, :signatures
19
19
  attr_accessor :key_expiration, :key_value
20
20
  attr_accessor :encrypted_message, :cleartext_message, :ephemeral_public_key, :tag
21
- attr_accessor :message_expiration, :message_id, :payment_method, :payment_method_details
21
+ attr_accessor :message_expiration, :message_id, :payment_method, :payment_method_details, :gateway_merchant_id
22
22
  attr_accessor :pan, :expiration_month, :expiration_year, :auth_method
23
23
  attr_accessor :cryptogram, :eci_indicator
24
24
 
@@ -34,7 +34,7 @@ class AliquotPay
34
34
  end
35
35
 
36
36
  def extract_root_signing_keys
37
- key = Base64.strict_encode64(eckey_to_public(ensure_root_key).to_der)
37
+ key = Base64.strict_encode64(eckey_to_public(ensure_root_key))
38
38
  {
39
39
  'keys' => [
40
40
  'protocolVersion' => @protocol_version,
@@ -43,16 +43,19 @@ class AliquotPay
43
43
  }.to_json
44
44
  end
45
45
 
46
- def eckey_to_public(key)
47
- p = OpenSSL::PKey::EC.new(EC_CURVE)
48
-
49
- p.public_key = key.public_key
50
-
51
- p
46
+ if OpenSSL::VERSION >= '3'
47
+ # pkeys are immutable on OpenSSL >=3.0
48
+ def eckey_to_public(key)
49
+ key.public_to_der
50
+ end
51
+ else
52
+ def eckey_to_public(key)
53
+ k = OpenSSL::PKey::EC.new(EC_CURVE)
54
+ k.public_key = key.public_key
55
+ k.to_der
56
+ end
52
57
  end
53
58
 
54
- #private
55
-
56
59
  def sign(key, message)
57
60
  d = OpenSSL::Digest::SHA256.new
58
61
  def key.private?; private_key?; end
@@ -60,7 +63,7 @@ class AliquotPay
60
63
  end
61
64
 
62
65
  def encrypt(cleartext_message)
63
- @recipient ||= OpenSSL::PKey::EC.new('prime256v1').generate_key
66
+ @recipient ||= OpenSSL::PKey::EC.generate('prime256v1')
64
67
  @info ||= 'Google'
65
68
 
66
69
  eph = AliquotPay::Util.generate_ephemeral_key
@@ -113,6 +116,7 @@ class AliquotPay
113
116
 
114
117
  def build_cleartext_message
115
118
  return @cleartext_message if @cleartext_message
119
+
116
120
  default_message_id = Base64.strict_encode64(OpenSSL::Random.random_bytes(24))
117
121
  default_message_expiration = ((Time.now.to_f + 60 * 5) * 1000).round.to_s
118
122
 
@@ -122,6 +126,14 @@ class AliquotPay
122
126
  'paymentMethod' => @payment_method || 'CARD',
123
127
  'paymentMethodDetails' => build_payment_method_details
124
128
  }
129
+
130
+ if @protocol_version == :ECv2
131
+ @cleartext_message.merge!(
132
+ 'gatewayMerchantId' => @gateway_merchant_id || 'SOME GATEWAY MERCHANT ID'
133
+ )
134
+ end
135
+
136
+ @cleartext_message
125
137
  end
126
138
 
127
139
  def build_signed_message
@@ -143,13 +155,11 @@ class AliquotPay
143
155
  return @signed_key if @signed_key
144
156
  ensure_intermediate_key
145
157
 
146
- if @intermediate_key.private_key? || @intermediate_key.public_key?
147
- public_key = eckey_to_public(@intermediate_key)
148
- else
158
+ if !@intermediate_key.private_key? && !@intermediate_key.public_key?
149
159
  fail 'Intermediate key must be public and private key'
150
160
  end
151
161
 
152
- default_key_value = Base64.strict_encode64(public_key.to_der)
162
+ default_key_value = Base64.strict_encode64(eckey_to_public(@intermediate_key))
153
163
  default_key_expiration = "#{Time.now.to_i + 3600}000"
154
164
 
155
165
  @signed_key = {
@@ -163,11 +173,11 @@ class AliquotPay
163
173
  end
164
174
 
165
175
  def ensure_root_key
166
- @root_key ||= OpenSSL::PKey::EC.new(EC_CURVE).generate_key
176
+ @root_key ||= OpenSSL::PKey::EC.generate(EC_CURVE)
167
177
  end
168
178
 
169
179
  def ensure_intermediate_key
170
- @intermediate_key ||= OpenSSL::PKey::EC.new(EC_CURVE).generate_key
180
+ @intermediate_key ||= OpenSSL::PKey::EC.generate(EC_CURVE)
171
181
  end
172
182
 
173
183
  def build_signature
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliquot-pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clearhaus
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-09 00:00:00.000000000 Z
11
+ date: 2023-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hkdf
@@ -30,42 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.1.1
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.1.1
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.3'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.3'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13.0'
40
+ version: '2.1'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: rspec
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +52,7 @@ dependencies:
80
52
  - - "~>"
81
53
  - !ruby/object:Gem::Version
82
54
  version: '3'
83
- description:
55
+ description:
84
56
  email: hello@clearhaus.com
85
57
  executables: []
86
58
  extensions: []
@@ -92,7 +64,7 @@ homepage: https://github.com/clearhaus/aliquot-pay
92
64
  licenses:
93
65
  - MIT
94
66
  metadata: {}
95
- post_install_message:
67
+ post_install_message:
96
68
  rdoc_options: []
97
69
  require_paths:
98
70
  - lib
@@ -108,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
80
  version: '0'
109
81
  requirements: []
110
82
  rubygems_version: 3.1.6
111
- signing_key:
83
+ signing_key:
112
84
  specification_version: 4
113
85
  summary: Generates Google Pay test dummy tokens
114
86
  test_files: []