aliquot-pay 0.13.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/aliquot-pay.rb +1 -126
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a52570068b0b6f57550e57a2c10abef65e06ab5ba4f37988cae74ac5a97f8c85
|
4
|
+
data.tar.gz: 3a26fe4ac93a160960ecaf57951d5bb5d6b3977c913057f0edbed0ed7bbe756b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 983bf42c16fc65c840c0e65b3eeafba6148edfb8d4be67f5b94a4348619aa61e07323ad0419116ad4df1f37562427e51a97bab64573f06a68e271a5fa7f513e6
|
7
|
+
data.tar.gz: 1feed4a38dc29a91554fa272c492e84a9941454a10ebfbf11058254e06cc9993778961c424d4564d5861e6be025e9a0675f5e1dd5779bf7d175c65e72ba4cee0
|
data/lib/aliquot-pay.rb
CHANGED
@@ -29,131 +29,6 @@ class AliquotPay
|
|
29
29
|
@protocol_version = protocol_version
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.sign(key, message)
|
33
|
-
d = OpenSSL::Digest::SHA256.new
|
34
|
-
def key.private?; private_key?; end
|
35
|
-
Base64.strict_encode64(key.sign(d, message))
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.encrypt(cleartext_message, recipient, protocol_version, info = 'Google')
|
39
|
-
eph = AliquotPay::Util.generate_ephemeral_key
|
40
|
-
ss = AliquotPay::Util.generate_shared_secret(eph, recipient.public_key)
|
41
|
-
|
42
|
-
case protocol_version
|
43
|
-
when :ECv1
|
44
|
-
cipher = OpenSSL::Cipher::AES128.new(:CTR)
|
45
|
-
when :ECv2
|
46
|
-
cipher = OpenSSL::Cipher::AES256.new(:CTR)
|
47
|
-
else
|
48
|
-
raise StandardError, "Invalid protocol_version #{protocol_version}"
|
49
|
-
end
|
50
|
-
|
51
|
-
keys = AliquotPay::Util.derive_keys(eph.public_key.to_bn.to_s(2), ss, info, protocol_version)
|
52
|
-
|
53
|
-
cipher.encrypt
|
54
|
-
cipher.key = keys[:aes_key]
|
55
|
-
|
56
|
-
encrypted_message = cipher.update(cleartext_message) + cipher.final
|
57
|
-
|
58
|
-
tag = AliquotPay::Util.calculate_tag(keys[:mac_key], encrypted_message)
|
59
|
-
|
60
|
-
{
|
61
|
-
'encryptedMessage' => Base64.strict_encode64(encrypted_message),
|
62
|
-
'ephemeralPublicKey' => Base64.strict_encode64(eph.public_key.to_bn.to_s(2)),
|
63
|
-
'tag' => Base64.strict_encode64(tag),
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
# Return a default payment
|
68
|
-
def self.payment(
|
69
|
-
auth_method: :PAN_ONLY,
|
70
|
-
expiration: ((Time.now.to_f + 60 * 5) * 1000).round.to_s
|
71
|
-
)
|
72
|
-
id = Base64.strict_encode64(OpenSSL::Random.random_bytes(24))
|
73
|
-
p = {
|
74
|
-
'messageExpiration' => expiration,
|
75
|
-
'messageId' => id,
|
76
|
-
'paymentMethod' => 'CARD',
|
77
|
-
'paymentMethodDetails' => {
|
78
|
-
'expirationYear' => 2023,
|
79
|
-
'expirationMonth' => 12,
|
80
|
-
'pan' => '4111111111111111',
|
81
|
-
'authMethod' => 'PAN_ONLY',
|
82
|
-
},
|
83
|
-
}
|
84
|
-
|
85
|
-
if auth_method == :CRYPTOGRAM_3DS
|
86
|
-
p['paymentMethodDetails']['authMethod'] = 'CRYPTOGRAM_3DS'
|
87
|
-
p['paymentMethodDetails']['cryptogram'] = 'SOME CRYPTOGRAM'
|
88
|
-
p['paymentMethodDetails']['eciIndicator'] = '05'
|
89
|
-
end
|
90
|
-
|
91
|
-
p
|
92
|
-
end
|
93
|
-
|
94
|
-
# Return a string length as a 4byte little-endian integer, as a string
|
95
|
-
def self.four_byte_length(str)
|
96
|
-
[str.length].pack('V')
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.generate_signature(*args)
|
100
|
-
args.map do |s|
|
101
|
-
four_byte_length(s) + s
|
102
|
-
end.join
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.signature_string(
|
106
|
-
message,
|
107
|
-
merchant_id: DEFAULTS[:merchant_id],
|
108
|
-
sender_id: DEFAULTS[:info],
|
109
|
-
protocol_version: 'ECv1'
|
110
|
-
)
|
111
|
-
|
112
|
-
generate_signature(sender_id, "merchant:#{merchant_id}", protocol_version, message)
|
113
|
-
end
|
114
|
-
|
115
|
-
# payment:: Google Pay token as a ruby Hash
|
116
|
-
# signing_key:: OpenSSL::PKEY::EC
|
117
|
-
# recipient:: OpenSSL::PKey::EC
|
118
|
-
# signed_message:: Pass a customized message to sign as signed messaged.
|
119
|
-
def self.generate_token_ecv1(payment, signing_key, recipient, signed_message = nil)
|
120
|
-
signed_message ||= encrypt(payment.to_json, recipient, :ECv1).to_json
|
121
|
-
signature_string = signature_string(signed_message)
|
122
|
-
|
123
|
-
{
|
124
|
-
'protocolVersion' => 'ECv1',
|
125
|
-
'signature' => sign(signing_key, signature_string),
|
126
|
-
'signedMessage' => signed_message,
|
127
|
-
}
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.generate_token_ecv2(payment, signing_key, intermediate_key, recipient,
|
131
|
-
signed_message: nil, expire_time: "#{Time.now.to_i + 3600}000")
|
132
|
-
signed_message ||= encrypt(payment.to_json, recipient, :ECv2).to_json
|
133
|
-
sig = signature_string(signed_message, protocol_version: 'ECv2')
|
134
|
-
|
135
|
-
intermediate_pub = OpenSSL::PKey::EC.new(EC_CURVE)
|
136
|
-
intermediate_pub.public_key = intermediate_key.public_key
|
137
|
-
|
138
|
-
signed_key = {
|
139
|
-
'keyExpiration' => expire_time,
|
140
|
-
'keyValue' => Base64.strict_encode64(intermediate_pub.to_der)
|
141
|
-
}.to_json
|
142
|
-
|
143
|
-
ik_signature_string = generate_signature('Google', 'ECv2', signed_key)
|
144
|
-
signatures = [sign(signing_key, ik_signature_string)]
|
145
|
-
|
146
|
-
{
|
147
|
-
'protocolVersion' => 'ECv2',
|
148
|
-
'signature' => sign(intermediate_key, sig),
|
149
|
-
'signedMessage' => signed_message,
|
150
|
-
'intermediateSigningKey' => {
|
151
|
-
'signedKey' => signed_key,
|
152
|
-
'signatures' => signatures,
|
153
|
-
},
|
154
|
-
}
|
155
|
-
end
|
156
|
-
|
157
32
|
def token
|
158
33
|
build_token
|
159
34
|
end
|
@@ -223,7 +98,7 @@ class AliquotPay
|
|
223
98
|
'pan' => @pan || '4111111111111111',
|
224
99
|
'expirationYear' => @expiration_year || 2023,
|
225
100
|
'expirationMonth' => @expiration_month || 12,
|
226
|
-
'authMethod'
|
101
|
+
'authMethod' => @auth_method || 'PAN_ONLY',
|
227
102
|
}
|
228
103
|
|
229
104
|
if @auth_method == 'CRYPTOGRAM_3DS'
|
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: 0.
|
4
|
+
version: 1.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: 2019-
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hkdf
|