ipizza 2.1.0 → 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: 160c73db6da0b92bb8d59f3478ae2836a8efdfe57cbfe174a0715559a980273a
4
- data.tar.gz: 40486a43f105c5ee73fb7d3f4e827124f7bff5cb8fb1bfa93c2fca677c06f9c7
3
+ metadata.gz: 5ed9393a3cf761d93af6cacfe5ab9f5290bd9f9fa07df805eba6e8923c302b80
4
+ data.tar.gz: 8543fd69e9b7c1c523bdbed2f20ac511b8fef3f3661987d4a960c27df9827bab
5
5
  SHA512:
6
- metadata.gz: 173c0fd63f8e5c43c099a9871005db2bc83272455eb56c10c9c01fabb4a2ab2c42925d490f9608332aca2916ef172ef81bc204ae9f211d9a357a3a4989581f43
7
- data.tar.gz: b702c29a1c3ccf89a46a10828c3911ab9d7d9880d43e79387ff4e5cd6284aabe83dcb81c28f65c19f484550f018c2fb93261b0e7a7939ed04c587a76a00ed2be
6
+ metadata.gz: 9172fb1cbe9b620439a73b41b12d53f0e6bfd5f4ce2d219f0398ab6c4136716200463885ba692cf34b70675e4151f3536398c10a4bf59e9817b09f2c3b52eb69
7
+ data.tar.gz: 01010f397f8c724adcf89e9db463f7ba6ba9277501ef243957e58b8a7e2eb863c840d9a533e921ec4f953dd10d76479676b0ade0b7bf24da69891bc8fc6cfd7e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ipizza (2.0.1)
4
+ ipizza (2.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -46,3 +46,6 @@ DEPENDENCIES
46
46
  rake
47
47
  rb-fsevent
48
48
  rspec (~> 2.9.0)
49
+
50
+ BUNDLED WITH
51
+ 1.17.3
@@ -1,8 +1,8 @@
1
1
  module Ipizza
2
2
  class Authentication
3
-
3
+
4
4
  attr_accessor :provider, :user, :message_time, :sender_id, :receiver_id, :user_name, :user_id, :country, :other, :authentication_identifier, :request_identifier
5
-
5
+
6
6
  def initialize(attribs = {})
7
7
  attribs.each do |key, value|
8
8
  if self.respond_to?("#{key.to_s}=".to_sym)
@@ -1,18 +1,18 @@
1
1
  module Ipizza
2
2
  class AuthenticationResponse < Ipizza::Response
3
-
3
+
4
4
  def success?
5
5
  %w(3012 3013).include?(@params['VK_SERVICE'])
6
6
  end
7
-
7
+
8
8
  def valid?
9
9
  @valid
10
10
  end
11
-
11
+
12
12
  def info_social_security_id
13
13
  authentication_info.user_id
14
14
  end
15
-
15
+
16
16
  def info_name
17
17
  authentication_info.user_name
18
18
  end
@@ -1,8 +1,8 @@
1
1
  module Ipizza
2
2
  class Payment
3
-
3
+
4
4
  attr_accessor :provider, :stamp, :amount, :currency, :refnum, :receiver_account, :receiver_name, :sender_account, :sender_name, :message, :transaction_id, :transaction_time
5
-
5
+
6
6
  def initialize(attribs = {})
7
7
  attribs.each do |key, value|
8
8
  if self.respond_to?("#{key.to_s}=".to_sym)
@@ -3,15 +3,15 @@ class Ipizza::PaymentResponse < Ipizza::Response
3
3
  def success?
4
4
  %w(1111).include?(@params['VK_SERVICE'])
5
5
  end
6
-
6
+
7
7
  def valid?
8
8
  @valid
9
9
  end
10
-
10
+
11
11
  def automatic_message?
12
12
  @params['VK_AUTO'] == 'Y'
13
13
  end
14
-
14
+
15
15
  def payment_info
16
16
  @payment_info ||= Ipizza::Payment.new(
17
17
  provider: @params['VK_SND_ID'],
@@ -4,7 +4,20 @@ module Ipizza::Provider
4
4
  SUPPORTED_ENCODINGS = %w(UTF-8 ISO-8859-1 WINDOWS-1257)
5
5
 
6
6
  class << self
7
- attr_accessor :service_url, :return_url, :cancel_url, :file_key, :key_secret, :file_cert, :snd_id, :rec_id, :rec_acc, :rec_name, :encoding, :lang
7
+ attr_accessor :service_url,
8
+ :return_url,
9
+ :cancel_url,
10
+ :file_key,
11
+ :key_secret,
12
+ :file_cert,
13
+ :sign_algorithm,
14
+ :verification_algorithm,
15
+ :snd_id,
16
+ :rec_id,
17
+ :rec_acc,
18
+ :rec_name,
19
+ :encoding,
20
+ :lang
8
21
  end
9
22
 
10
23
  def payment_request(payment, service_no = 1012)
@@ -40,7 +53,10 @@ module Ipizza::Provider
40
53
 
41
54
  def payment_response(params)
42
55
  response = Ipizza::PaymentResponse.new(params)
43
- response.verify(self.class.file_cert)
56
+ response.verify(
57
+ self.class.file_cert,
58
+ self.class.verification_algorithm || Ipizza::Util::DEFAULT_HASH_ALGORITHM
59
+ )
44
60
  response
45
61
  end
46
62
 
@@ -77,7 +93,10 @@ module Ipizza::Provider
77
93
 
78
94
  def authentication_response(params)
79
95
  response = Ipizza::AuthenticationResponse.new(params)
80
- response.verify(self.class.file_cert)
96
+ response.verify(
97
+ self.class.file_cert,
98
+ self.class.verification_algorithm || Ipizza::Util::DEFAULT_HASH_ALGORITHM
99
+ )
81
100
  response
82
101
  end
83
102
 
@@ -1,6 +1,6 @@
1
1
  module Ipizza
2
2
  class Request
3
-
3
+
4
4
  attr_accessor :extra_params
5
5
  attr_accessor :sign_params
6
6
  attr_accessor :service_url
@@ -16,7 +16,7 @@ module Ipizza
16
16
  signature = Ipizza::Util.sign(privkey_path, privkey_secret, Ipizza::Util.mac_data_string(sign_params, order))
17
17
  self.sign_params[mac_param] = signature
18
18
  end
19
-
19
+
20
20
  def request_params
21
21
  sign_params.merge(extra_params)
22
22
  end
@@ -2,21 +2,21 @@ class Ipizza::Response
2
2
 
3
3
  attr_accessor :verify_params
4
4
  attr_accessor :verify_params_order
5
-
5
+
6
6
  PARAM_ORDER = {
7
7
  '1111' => %w(VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP VK_T_NO VK_AMOUNT VK_CURR VK_REC_ACC VK_REC_NAME VK_SND_ACC VK_SND_NAME VK_REF VK_MSG VK_T_DATETIME),
8
8
  '3012' => %w(VK_SERVICE VK_VERSION VK_USER VK_DATETIME VK_SND_ID VK_REC_ID VK_USER_NAME VK_USER_ID VK_COUNTRY VK_OTHER VK_TOKEN VK_RID),
9
9
  '3013' => %w(VK_SERVICE VK_VERSION VK_DATETIME VK_SND_ID VK_REC_ID VK_NONCE VK_USER_NAME VK_USER_ID VK_COUNTRY VK_OTHER VK_TOKEN VK_RID),
10
10
  '1911' => %w(VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP VK_REF VK_MSG)
11
- }
12
-
11
+ }
12
+
13
13
  def initialize(params)
14
14
  @params = params
15
15
  end
16
16
 
17
- def verify(certificate_path)
17
+ def verify(certificate_path, hash_algorithm = Ipizza::Util::DEFAULT_HASH_ALGORITHM)
18
18
  mac_string = Ipizza::Util.mac_data_string(@params, PARAM_ORDER[@params['VK_SERVICE']])
19
19
 
20
- @valid = Ipizza::Util.verify_signature(certificate_path, @params['VK_MAC'], mac_string)
20
+ @valid = Ipizza::Util.verify_signature(certificate_path, @params['VK_MAC'], mac_string, hash_algorithm)
21
21
  end
22
22
  end
data/lib/ipizza/util.rb CHANGED
@@ -3,24 +3,33 @@ require 'openssl'
3
3
 
4
4
  module Ipizza
5
5
  class Util
6
-
6
+
7
+ DEFAULT_HASH_ALGORITHM = 'sha1'
8
+
7
9
  class << self
8
-
9
- def verify_signature(certificate_path, signature, data)
10
+
11
+ def verify_signature(certificate_path, signature, data, hash_algorithm = DEFAULT_HASH_ALGORITHM)
10
12
  if !certificate_path.to_s.empty? && !signature.to_s.empty? && File.file?(certificate_path)
11
13
  certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path).gsub(/ /, '')).public_key
12
- certificate.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), data)
14
+ certificate.verify(
15
+ digest_class(hash_algorithm).new,
16
+ Base64.decode64(signature),
17
+ data
18
+ )
13
19
  else
14
20
  false
15
21
  end
16
22
  end
17
-
18
- def sign(privkey_path, privkey_secret, data)
23
+
24
+ def sign(privkey_path, privkey_secret, data, hash_algorithm = DEFAULT_HASH_ALGORITHM)
19
25
  privkey = File.open(privkey_path, 'r') { |f| f.read }
20
26
  privkey = OpenSSL::PKey::RSA.new(privkey.gsub(/ /, ''), privkey_secret)
21
27
 
22
- signature = privkey.sign(OpenSSL::Digest::SHA1.new, data)
23
- signature = Base64.encode64(signature).gsub(/\n/, '')
28
+ signature = privkey.sign(
29
+ digest_class(hash_algorithm).new,
30
+ data
31
+ )
32
+ Base64.encode64(signature).gsub(/\n/, '')
24
33
  end
25
34
 
26
35
  # Calculates and adds control number using 7-3-1 algoritm for Estonian banking account and reference numbers.
@@ -74,6 +83,16 @@ module Ipizza
74
83
  sprintf('%03i', val.bytesize)
75
84
  end
76
85
  end
86
+
87
+ def digest_class(hash_algorithm)
88
+ algorithm = (hash_algorithm || '').upcase
89
+
90
+ if OpenSSL::Digest.const_defined?(algorithm)
91
+ OpenSSL::Digest.const_get(algorithm)
92
+ else
93
+ raise ArgumentError, "Unknown hash algorithm OpenSSL::Digest::#{algorithm}"
94
+ end
95
+ end
77
96
  end
78
97
  end
79
98
  end
@@ -1,3 +1,3 @@
1
1
  module Ipizza
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -41,6 +41,8 @@ seb:
41
41
  key_secret: foobar
42
42
  encoding: UTF-8
43
43
  snd_id: sender
44
+ sign_algorithm: 'sha256'
45
+ verification_algorithm: 'sha256'
44
46
 
45
47
  luminor:
46
48
  service_url: https://banklink.luminor.ee/test
@@ -11,3 +11,5 @@ swedbank:
11
11
 
12
12
  seb:
13
13
  service_url: https://www.seb.ee/banklink
14
+ sign_algorithm: 'sha256'
15
+ verification_algorithm: 'sha1'
@@ -16,6 +16,8 @@ describe Ipizza::Config do
16
16
  Ipizza::Provider::Swedbank.encoding.should == 'UTF-8'
17
17
 
18
18
  Ipizza::Provider::Seb.service_url.should == 'https://www.seb.ee/banklink'
19
+ Ipizza::Provider::Seb.sign_algorithm.should == 'sha256'
20
+ Ipizza::Provider::Seb.verification_algorithm.should == 'sha1'
19
21
  end
20
22
 
21
23
  it 'should load certificates from path relative to configuration file' do
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  describe Ipizza::Provider::Luminor do
4
4
  let(:response_time) { Ipizza::Util.time_to_iso8601(Time.now) }
5
- let(:bank_key) { File.expand_path('../../../certificates/pangalink_luminor_bank_key.pem', __FILE__) }
5
+ let(:bank_key) { File.expand_path('../../../certificates/pangalink_seb_bank_key.pem', __FILE__) }
6
6
 
7
7
  describe '#payment_request' do
8
8
  let(:payment) { Ipizza::Payment.new(stamp: 1, amount: '123.34', refnum: 1, message: 'Payment message', currency: 'EUR') }
@@ -45,7 +45,12 @@ describe Ipizza::Provider::Seb do
45
45
  }
46
46
 
47
47
  it 'should parse and verify the payment response from bank' do
48
- signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['1111']))
48
+ signature = Ipizza::Util.sign(
49
+ bank_key,
50
+ nil,
51
+ Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['1111']),
52
+ Ipizza::Provider::Seb.sign_algorithm
53
+ )
49
54
  Ipizza::Provider::Seb.new.payment_response(params.merge('VK_MAC' => signature)).should be_valid
50
55
  end
51
56
  end
@@ -82,7 +87,12 @@ describe Ipizza::Provider::Seb do
82
87
  }
83
88
 
84
89
  it 'should parse and verify the authentication response from bank' do
85
- signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['3012']))
90
+ signature = Ipizza::Util.sign(
91
+ bank_key,
92
+ nil,
93
+ Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['3012']),
94
+ Ipizza::Provider::Seb.sign_algorithm
95
+ )
86
96
  Ipizza::Provider::Seb.new.authentication_response(params.merge('VK_MAC' => signature)).should be_valid
87
97
  end
88
98
  end
@@ -46,10 +46,6 @@ describe Ipizza::Provider do
46
46
  Ipizza::Provider.get('krediidipank').should be_a(Ipizza::Provider::Krediidipank)
47
47
  end
48
48
 
49
- it 'returns nordea provider for "nordea" attribute' do
50
- Ipizza::Provider.get('nordea').should be_a(Ipizza::Provider::Nordea)
51
- end
52
-
53
49
  it 'returns nothing for "unkn" attribute' do
54
50
  Ipizza::Provider.get('unkn').should be_nil
55
51
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipizza
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Priit Haamer
8
8
  - Tanel Jakobsoo
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-15 00:00:00.000000000 Z
12
+ date: 2023-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -136,10 +136,6 @@ files:
136
136
  - spec/ipizza/provider/krediidipank_spec.rb
137
137
  - spec/ipizza/provider/lhv_spec.rb
138
138
  - spec/ipizza/provider/luminor_spec.rb
139
- - spec/ipizza/provider/nordea/authentication_response_spec.rb
140
- - spec/ipizza/provider/nordea/payment_request_spec.rb
141
- - spec/ipizza/provider/nordea/payment_response_spec.rb
142
- - spec/ipizza/provider/nordea_spec.rb
143
139
  - spec/ipizza/provider/sampo_spec.rb
144
140
  - spec/ipizza/provider/seb_spec.rb
145
141
  - spec/ipizza/provider/swedbank_spec.rb
@@ -150,7 +146,7 @@ files:
150
146
  homepage: https://github.com/Voog/ipizza
151
147
  licenses: []
152
148
  metadata: {}
153
- post_install_message:
149
+ post_install_message:
154
150
  rdoc_options: []
155
151
  require_paths:
156
152
  - lib
@@ -165,8 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
161
  - !ruby/object:Gem::Version
166
162
  version: '0'
167
163
  requirements: []
168
- rubygems_version: 3.0.3
169
- signing_key:
164
+ rubygems_version: 3.0.8
165
+ signing_key:
170
166
  specification_version: 4
171
167
  summary: Implements iPizza protocol to communicate with Estonian Banks
172
168
  test_files:
@@ -195,10 +191,6 @@ test_files:
195
191
  - spec/ipizza/provider/krediidipank_spec.rb
196
192
  - spec/ipizza/provider/lhv_spec.rb
197
193
  - spec/ipizza/provider/luminor_spec.rb
198
- - spec/ipizza/provider/nordea/authentication_response_spec.rb
199
- - spec/ipizza/provider/nordea/payment_request_spec.rb
200
- - spec/ipizza/provider/nordea/payment_response_spec.rb
201
- - spec/ipizza/provider/nordea_spec.rb
202
194
  - spec/ipizza/provider/sampo_spec.rb
203
195
  - spec/ipizza/provider/seb_spec.rb
204
196
  - spec/ipizza/provider/swedbank_spec.rb
@@ -1,33 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
-
3
- describe Ipizza::Provider::Nordea::AuthenticationResponse do
4
- before(:each) do
5
- @valid_params = {
6
- 'B02K_CUSTNAME' => 'Demo kasutaja', 'B02K_IDNBR' => '87654321', 'B02K_TIMESTMP' => '20020101204145428720',
7
- 'B02K_STAMP' => '20101204155339', 'B02K_KEYVERS' => '0001', 'B02K_MAC' => 'A061E22312D7D63FDC2B0B52E16BC971',
8
- 'B02K_CUSTTYPE' => '01', 'B02K_ALG' => '01', 'B02K_CUSTID' => '37404280367', 'B02K_VERS' => '0002'
9
- }
10
- @response = Ipizza::Provider::Nordea::AuthenticationResponse.new(@valid_params)
11
- @response.verify(Ipizza::Provider::Nordea.file_key)
12
- end
13
-
14
- describe '#valid?' do
15
- context 'given valid parameters' do
16
- it 'returns true' do
17
- @response.valid?.should be_true
18
- end
19
- end
20
- end
21
-
22
- describe '#info_social_security_id' do
23
- it 'should get user social security id from the response' do
24
- @response.info_social_security_id.should == '37404280367'
25
- end
26
- end
27
-
28
- describe '#info_name' do
29
- it 'should get user name from the response' do
30
- @response.info_name.should == 'Demo kasutaja'
31
- end
32
- end
33
- end
@@ -1,4 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
-
3
- describe Ipizza::Provider::Nordea::PaymentRequest do
4
- end
@@ -1,4 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
-
3
- describe Ipizza::Provider::Nordea::PaymentResponse do
4
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
-
3
- describe Ipizza::Provider::Nordea do
4
- describe '#authentication_request' do
5
- before(:each) do
6
- @req = Ipizza::Provider::Nordea.new.authentication_request
7
- end
8
-
9
- it 'returns signed authentication request object' do
10
- @req.request_params.fetch('A01Y_MAC').should be
11
- end
12
-
13
- it 'adds service url to request' do
14
- @req.service_url.should == Ipizza::Provider::Nordea.auth_service_url
15
- end
16
-
17
- it 'adds return url from configuration to request' do
18
- @req.request_params.fetch('A01Y_RETLINK').should == Ipizza::Provider::Nordea.auth_return_url
19
- end
20
-
21
- it 'adds cancel url from configuration to request' do
22
- @req.request_params.fetch('A01Y_CANLINK').should == Ipizza::Provider::Nordea.auth_cancel_url
23
- end
24
-
25
- it 'adds reject url from configuration to request' do
26
- @req.request_params.fetch('A01Y_REJLINK').should == Ipizza::Provider::Nordea.auth_reject_url
27
- end
28
- end
29
- end