aliquot-pay 3.0.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aliquot-pay.rb +67 -33
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 900a3ab50c572b86accb200902899275239c68e2951792467be905fa8495f796
|
4
|
+
data.tar.gz: ed4476fc237b67d49ea342bdca9db82782332ccf06be65de0d06ac6cf106b19f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ddea3d61ed2dc2e2b35a3ddcb4e2afc329707af26a823efd55ba54d2491264e1af0e02a9a08e5b3efa005b69ffee15bc07b8a5566bad0b614acdb3b4a4d68f2
|
7
|
+
data.tar.gz: fd98206c62e82c6bda44e15c7bc9ac9ca2e279bbd0bb1e7ea78d671d1886ac917f5aba05fb7581832ab148f8577ec867eab9a8b1908d3ebbf3ce1de016ae70a0
|
data/lib/aliquot-pay.rb
CHANGED
@@ -25,11 +25,10 @@ class AliquotPay
|
|
25
25
|
attr_accessor :recipient, :info, :root_key, :intermediate_key
|
26
26
|
attr_writer :recipient_id, :shared_secret, :token, :signed_key_string
|
27
27
|
|
28
|
-
def initialize(protocol_version
|
28
|
+
def initialize(protocol_version: :ECv2, root_key: nil, type: :browser)
|
29
29
|
@protocol_version = protocol_version
|
30
|
-
|
31
|
-
|
32
|
-
end
|
30
|
+
@root_key = root_key
|
31
|
+
@type = type
|
33
32
|
end
|
34
33
|
|
35
34
|
def token
|
@@ -39,10 +38,10 @@ class AliquotPay
|
|
39
38
|
def extract_root_signing_keys
|
40
39
|
key = Base64.strict_encode64(ensure_root_key.to_der)
|
41
40
|
{
|
42
|
-
'keys' => [
|
41
|
+
'keys' => [{
|
43
42
|
'protocolVersion' => @protocol_version,
|
44
|
-
'keyValue' => key
|
45
|
-
]
|
43
|
+
'keyValue' => key
|
44
|
+
}]
|
46
45
|
}.to_json
|
47
46
|
end
|
48
47
|
|
@@ -68,7 +67,7 @@ class AliquotPay
|
|
68
67
|
when :ECv2
|
69
68
|
cipher = OpenSSL::Cipher::AES256.new(:CTR)
|
70
69
|
else
|
71
|
-
raise StandardError, "Invalid protocol_version #{protocol_version}"
|
70
|
+
raise StandardError, "Invalid protocol_version #{@protocol_version}"
|
72
71
|
end
|
73
72
|
|
74
73
|
keys = AliquotPay::Util.derive_keys(eph.public_key.to_bn.to_s(2), ss, @info, @protocol_version)
|
@@ -83,29 +82,54 @@ class AliquotPay
|
|
83
82
|
{
|
84
83
|
'encryptedMessage' => Base64.strict_encode64(encrypted_message),
|
85
84
|
'ephemeralPublicKey' => Base64.strict_encode64(eph.public_key.to_bn.to_s(2)),
|
86
|
-
'tag' => Base64.strict_encode64(tag)
|
85
|
+
'tag' => Base64.strict_encode64(tag)
|
87
86
|
}
|
88
87
|
end
|
89
88
|
|
90
89
|
def build_payment_method_details
|
91
90
|
return @payment_method_details if @payment_method_details
|
91
|
+
|
92
|
+
return build_payment_method_details_non_tokenized if @type == :browser
|
93
|
+
|
94
|
+
build_payment_method_details_tokenized
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_payment_method_details_non_tokenized
|
92
98
|
value = {
|
93
99
|
'pan' => @pan || '4111111111111111',
|
94
|
-
'expirationYear' => @expiration_year ||
|
95
|
-
'expirationMonth' => @expiration_month || 12
|
96
|
-
'authMethod' => @auth_method || 'PAN_ONLY',
|
100
|
+
'expirationYear' => @expiration_year || Time.now.year + 1,
|
101
|
+
'expirationMonth' => @expiration_month || 12
|
97
102
|
}
|
98
103
|
|
99
|
-
if @
|
104
|
+
if @protocol_version == :ECv2 && @type == :browser
|
100
105
|
value.merge!(
|
101
|
-
'
|
102
|
-
'eciIndicator' => @eci_indicator || '05'
|
106
|
+
'authMethod' => @auth_method || 'PAN_ONLY'
|
103
107
|
)
|
104
108
|
end
|
105
|
-
|
106
109
|
value
|
107
110
|
end
|
108
111
|
|
112
|
+
def build_payment_method_details_tokenized
|
113
|
+
value = {
|
114
|
+
'expirationYear' => @expiration_year || Time.now.year + 1,
|
115
|
+
'expirationMonth' => @expiration_month || 12,
|
116
|
+
'eciIndicator' => @eci_indicator || '05'
|
117
|
+
}
|
118
|
+
if @protocol_version == :ECv1
|
119
|
+
value.merge!(
|
120
|
+
'dpan' => @pan || '4111111111111111',
|
121
|
+
'authMethod' => @auth_method || '3DS',
|
122
|
+
'3dsCryptogram' => @cryptogram || Base64.strict_encode64(OpenSSL::Random.random_bytes(20))
|
123
|
+
)
|
124
|
+
else
|
125
|
+
value.merge!(
|
126
|
+
'pan' => @pan || '4111111111111111',
|
127
|
+
'authMethod' => @auth_method || 'CRYPTOGRAM_3DS',
|
128
|
+
'cryptogram' => @cryptogram || Base64.strict_encode64(OpenSSL::Random.random_bytes(20))
|
129
|
+
)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
109
133
|
def build_cleartext_message
|
110
134
|
return @cleartext_message if @cleartext_message
|
111
135
|
|
@@ -114,8 +138,8 @@ class AliquotPay
|
|
114
138
|
|
115
139
|
@cleartext_message = {
|
116
140
|
'messageExpiration' => @message_expiration || default_message_expiration,
|
117
|
-
'messageId' => @message_id
|
118
|
-
'paymentMethod' => @payment_method
|
141
|
+
'messageId' => @message_id || default_message_id,
|
142
|
+
'paymentMethod' => @payment_method || 'CARD',
|
119
143
|
'paymentMethodDetails' => build_payment_method_details
|
120
144
|
}
|
121
145
|
|
@@ -140,11 +164,12 @@ class AliquotPay
|
|
140
164
|
end
|
141
165
|
|
142
166
|
def signed_message_string
|
143
|
-
|
167
|
+
build_signed_message.to_json
|
144
168
|
end
|
145
169
|
|
146
170
|
def build_signed_key
|
147
171
|
return @signed_key if @signed_key
|
172
|
+
|
148
173
|
ensure_intermediate_key
|
149
174
|
|
150
175
|
if !@intermediate_key.private_key? && !@intermediate_key.public_key?
|
@@ -156,7 +181,7 @@ class AliquotPay
|
|
156
181
|
|
157
182
|
@signed_key = {
|
158
183
|
'keyExpiration' => @key_expiration || default_key_expiration,
|
159
|
-
'keyValue' => @key_value
|
184
|
+
'keyValue' => @key_value || default_key_value
|
160
185
|
}
|
161
186
|
end
|
162
187
|
|
@@ -181,40 +206,49 @@ class AliquotPay
|
|
181
206
|
ensure_intermediate_key
|
182
207
|
end
|
183
208
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
209
|
+
signature_elements = [
|
210
|
+
'Google',
|
211
|
+
recipient_id,
|
212
|
+
@protocol_version.to_s,
|
213
|
+
signed_message_string
|
214
|
+
]
|
215
|
+
|
216
|
+
signature_string = signature_elements.map { |e| [e.length].pack('V') + e }.join
|
191
217
|
@signature = sign(key, signature_string)
|
192
218
|
end
|
193
219
|
|
194
220
|
def build_signatures
|
195
221
|
return @signatures if @signatures
|
196
222
|
|
197
|
-
signature_string =
|
198
|
-
|
199
|
-
|
200
|
-
end.join
|
223
|
+
signature_string = ['Google', 'ECv2', signed_key_string].map do |str|
|
224
|
+
[str.to_s.length].pack('V') + str.to_s
|
225
|
+
end.join
|
201
226
|
|
202
227
|
@signatures = [sign(ensure_root_key, signature_string)]
|
203
228
|
end
|
204
229
|
|
205
230
|
def build_token
|
206
231
|
return @token if @token
|
232
|
+
|
233
|
+
if @type == :app
|
234
|
+
@auth_method = 'CRYPTOGRAM_3DS'
|
235
|
+
if @protocol_version == :ECv1
|
236
|
+
@auth_method = '3DS'
|
237
|
+
@payment_method = 'TOKENIZED_CARD'
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
207
241
|
res = {
|
208
242
|
'protocolVersion' => @protocol_version.to_s,
|
209
243
|
'signedMessage' => @signed_message || signed_message_string,
|
210
|
-
'signature' => build_signature
|
244
|
+
'signature' => build_signature
|
211
245
|
}
|
212
246
|
|
213
247
|
if @protocol_version == :ECv2
|
214
248
|
intermediate = {
|
215
249
|
'intermediateSigningKey' => @intermediate_signing_key || {
|
216
250
|
'signedKey' => signed_key_string,
|
217
|
-
'signatures' => build_signatures
|
251
|
+
'signatures' => build_signatures
|
218
252
|
}
|
219
253
|
}
|
220
254
|
|
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clearhaus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hkdf
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.0'
|
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: '
|
40
|
+
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.1.6
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Generates Google Pay test dummy tokens
|