pedicel-pay 0.0.5 → 0.0.7

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: 6946f1b2a2838dd1a7b10127e3d11e49945ef7377a904495b77df0238f39e242
4
- data.tar.gz: 6fc5c2e1bf92d810e1acaa6c2eb498aeec2f3a3bbe3f9bb59c71e3dcc0e393a0
3
+ metadata.gz: a92860cb4e7c25dc894df194c4fa590e2dfe92075faf8bbd89328b0e00708fb2
4
+ data.tar.gz: 17dc4fae67dc3b00eea283fa5d281fc91f41c055baf4d38d805d7a63082a75ed
5
5
  SHA512:
6
- metadata.gz: 4f1ad26538147468ca693f8322fdf6ff88994e6f152ca947e9de3f8f8b3e7d8428dc3b58a3da67d9dba086e5f0c31ed1fd73f7d51ea88a1b02b1c541c05483cc
7
- data.tar.gz: 7b66f69c2daebc147a6a891e8ebb0f92d338bc3000c6bfed329c5393eb3f2af0967368a24eda7d387a7ce377865f1df86c235ee5ce4dd4723cd125c37b2302ed
6
+ metadata.gz: 87e21de8f44baac69f46be2b9156f0d089cc3c30d445d990c1424dd69c402448f6fd32396f031c17b257b864d87ca6e8421fc7fb8c93a05875d866ee7046e24f
7
+ data.tar.gz: '097631854de1f3527cddc1f9fc083b84c8a4400a8df6de6b1aebb3eaca3d8416ad73802f8148a8e15fab0883e689d522574c35df91fc9d09e5d0ea7957565a90'
data/exe/pedicel-pay CHANGED
@@ -137,6 +137,19 @@ module PedicelPay
137
137
  puts token.to_json
138
138
  end
139
139
 
140
+ desc 'extract-symmetric-key', 'Extract the symmetric key that is used for encryption/decryption of the token'
141
+ option 'client-path', type: :string, path: true, aliases: :c
142
+ option 'file', type: :string, aliases: :f
143
+
144
+ def extract_symmetric_key
145
+ raw_token = options['file'] ? File.read(options['file']) : $stdin.read
146
+ token = JSON.parse(raw_token)
147
+
148
+ client = Helper.load_client(options['client-path'])
149
+
150
+ puts client.symmetric_key(token)
151
+ end
152
+
140
153
 
141
154
  desc 'decrypt-token', 'Decrypt a token'
142
155
  option 'client-path', type: :string, path: true, aliases: :c
@@ -152,6 +165,28 @@ module PedicelPay
152
165
 
153
166
  puts client.decrypt(token, ca_certificate_pem: backend.ca_certificate.to_pem)
154
167
  end
168
+
169
+ desc 'decrypt-token-from-symmetric-key', 'Decrypt a token using the symmetric key'
170
+ option 'symmetric-key', type: :string, alias: :k
171
+ option 'file', type: :string, aliases: :f
172
+ option 'backend-path', type: :string, path: true, aliases: :b
173
+ option 'time', type: :string, alias: :t
174
+
175
+ def decrypt_token_from_symmetric_key
176
+ raw_token = options['file'] ? File.read(options['file']) : $stdin.read
177
+ token = JSON.parse(raw_token)
178
+
179
+ params = { symmetric_key: Helper.hex_to_bytestring(options['symmetric-key']) }
180
+
181
+ params.merge!(now: Time.parse(options['time'])) if options['time']
182
+
183
+ if options['backend-path']
184
+ backend = Helper.load_backend(options['backend-path'])
185
+ params.merge!(ca_certificate_pem: backend.ca_certificate.to_pem)
186
+ end
187
+
188
+ puts Pedicel::EC.new(token).decrypt(params)
189
+ end
155
190
  end
156
191
 
157
192
  class Helper
@@ -104,6 +104,17 @@ module PedicelPay
104
104
  OpenSSL::PKCS7::BINARY # Handle 0x00 correctly.
105
105
  )
106
106
 
107
+ # Check that the newly created signature is good.
108
+ flags = \
109
+ # https://wiki.openssl.org/index.php/Manual:PKCS7_verify(3)#VERIFY_PROCESS
110
+ OpenSSL::PKCS7::NOCHAIN | # Ignore certs in the message.
111
+ OpenSSL::PKCS7::NOINTERN # Only look at the supplied certificate.
112
+ trust_store = OpenSSL::X509::Store.new
113
+ trust_store.add_cert(ca_certificate).add_cert(intermediate_certificate)
114
+ unless signature.verify([certificate], trust_store, message, flags)
115
+ fail 'signature is wrong'
116
+ end
117
+
107
118
  if replace
108
119
  # Just replace token.signature.
109
120
  else
@@ -38,5 +38,12 @@ module PedicelPay
38
38
  new(token).
39
39
  decrypt(private_key: key, certificate: certificate, ca_certificate_pem: ca_certificate_pem, now: now)
40
40
  end
41
+
42
+ def symmetric_key(token)
43
+ Pedicel::EC.
44
+ new(token).
45
+ symmetric_key(private_key: key, certificate: certificate).
46
+ unpack('H*')
47
+ end
41
48
  end
42
49
  end
@@ -20,6 +20,10 @@ module PedicelPay
20
20
  string.unpack('H*').first
21
21
  end
22
22
 
23
+ def self.hex_to_bytestring(hex)
24
+ [hex].pack('H*')
25
+ end
26
+
23
27
  def self.merchant_id(x)
24
28
  case x
25
29
  when Client
@@ -102,7 +102,7 @@ module PedicelPay
102
102
  end
103
103
 
104
104
  def card_expired?(now)
105
- Time.parse(expired) <= now
105
+ Time.parse(expiry) <= now
106
106
  end
107
107
 
108
108
  def self.sample_expiry(expired: nil, now: nil, soon: nil)
@@ -1,3 +1,3 @@
1
1
  module PedicelPay
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pedicel-pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clearhaus A/S
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-06 00:00:00.000000000 Z
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.1.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.0'
47
+ version: 1.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.0'
54
+ version: 1.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -115,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.7
118
+ rubygems_version: 3.3.5
120
119
  signing_key:
121
120
  specification_version: 4
122
121
  summary: Backend and client part of Apple Pay