pedicel-pay 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6946f1b2a2838dd1a7b10127e3d11e49945ef7377a904495b77df0238f39e242
4
- data.tar.gz: 6fc5c2e1bf92d810e1acaa6c2eb498aeec2f3a3bbe3f9bb59c71e3dcc0e393a0
3
+ metadata.gz: 12084da10c8a033bfa52a0bb9ab055780a1985760044e98f964afec44143dc27
4
+ data.tar.gz: 2c5c9b7e328b0ce6fb94b198a85e0212d503046b30f1e797145d0ebf343a3249
5
5
  SHA512:
6
- metadata.gz: 4f1ad26538147468ca693f8322fdf6ff88994e6f152ca947e9de3f8f8b3e7d8428dc3b58a3da67d9dba086e5f0c31ed1fd73f7d51ea88a1b02b1c541c05483cc
7
- data.tar.gz: 7b66f69c2daebc147a6a891e8ebb0f92d338bc3000c6bfed329c5393eb3f2af0967368a24eda7d387a7ce377865f1df86c235ee5ce4dd4723cd125c37b2302ed
6
+ metadata.gz: 66085fa5b654cd9bfe01a347865df7332435b4047ed0115a5cdff639ddd6fe524808cfc80f50aed1017eb454ac1c71f1191597cb1641f49c2d2915ae15de2ba7
7
+ data.tar.gz: 0c4f411ea8648e9b86c848197a4e6a57b26b30f0ebd621f4c453a9af0686521c5b2f183c039a47b2a30c0b63d73759ebbdb1e8cbd3c9d3ac085e5a63f18425f5
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.6'
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.6
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: 2022-09-14 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.0.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.0.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.1.6
120
119
  signing_key:
121
120
  specification_version: 4
122
121
  summary: Backend and client part of Apple Pay