omniauth-suomifi 0.3.0 → 0.6.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: 4a1f6be0c9db1b5a90f38af2f9eb08aa48330aaf0fac09d820a91134a7d22ba9
4
- data.tar.gz: a03dae85e69231eb5106a76499bebf5a0dd8ddb639b8bcb3cc05348879d73470
3
+ metadata.gz: 2312191c6d70426259424cd525b77161966b43b151e84b9269dc7fe61c828754
4
+ data.tar.gz: a483682acfd192e66a87b4a556f9a61e7bbe63e9c9529635718005022c4f9e91
5
5
  SHA512:
6
- metadata.gz: e3b5d2142c659ecdda0d3e88b625e0005b35f58bb25b4f44d06dff8b984deb733b148f8e85537d05584a7d817d0f1b36bb3efba52599e71b9858003209417e1a
7
- data.tar.gz: a60c7e15ffa8aecad4d896d3de2ebb4aa20ac3cd44fb7764b093d66c85a8330b90954f889319e21704bfb2c70f1fc66f0f8bb5cf0b7774c1b31d18991e7bf2f5
6
+ metadata.gz: 856b8252bf76f046acb4788dcc5b5f4400a7dec5f7351c6fbae1fa17842335c805afcf008b32eddf856299f4b12e4bb6a6398ff7bbd2d84e5a70a59aca8cd0c8
7
+ data.tar.gz: 775d337ab4941f7c9fa79f4dd4376b2cfdc9f2d5f1e57a5dc9abbb00b52f3888dba5c7d6103d429f22a98ec46353ada3954d12bd931b842eafcb2ed1f0088ee4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # OmniAuth Suomi.fi
2
2
 
3
- [![Build Status](https://travis-ci.com/mainio/omniauth-suomifi.svg?branch=master)](https://travis-ci.com/mainio/omniauth-suomifi)
3
+ [![Build Status](https://github.com/mainio/omniauth-suomifi/actions/workflows/ci_omniauth-suomifi.yml/badge.svg)](https://github.com/mainio/omniauth-suomifi/actions)
4
4
  [![codecov](https://codecov.io/gh/mainio/omniauth-suomifi/branch/master/graph/badge.svg)](https://codecov.io/gh/mainio/omniauth-suomifi)
5
5
 
6
6
  This is an unofficial OmniAuth strategy for authenticating with the Suomi.fi
@@ -28,16 +28,16 @@ module OmniAuth
28
28
  # - en_US
29
29
  #
30
30
  # In case a valid language cannot be parsed from the parameter, the locale
31
- # parameter will default to `:idp_sso_target_url_default_locale`.
31
+ # parameter will default to `:idp_sso_service_url_default_locale`.
32
32
  #
33
33
  # Note that the locale parameter is always added as the last parameter in
34
34
  # in the redirect URL as expected by Suomi.fi.
35
- option :idp_sso_target_url_locale_params, %w[locale language lang]
35
+ option :idp_sso_service_url_locale_params, %w[locale language lang]
36
36
 
37
37
  # This is the default locale to be passed to IdP sign in redirect URL as
38
38
  # defined above. In case a valid locale is not found from the request
39
39
  # parameters, this will be used instead.
40
- option :idp_sso_target_url_default_locale, 'fi'
40
+ option :idp_sso_service_url_default_locale, 'fi'
41
41
 
42
42
  # The request attributes for Suomi.fi
43
43
  option :possible_request_attributes, [
@@ -557,7 +557,7 @@ module OmniAuth
557
557
  # Suomi.fi requires that the service provider needs to end the local user
558
558
  # session BEFORE sending the logout request to the identity provider.
559
559
  def other_phase_for_spslo
560
- return super unless options.idp_slo_target_url
560
+ return super unless options.idp_slo_service_url
561
561
 
562
562
  with_settings do |settings|
563
563
  # Some session variables are needed when generating the logout request
@@ -609,8 +609,8 @@ module OmniAuth
609
609
  case options.mode
610
610
  when :test
611
611
  'https://testi.apro.tunnistus.fi/static/metadata/idp-metadata.xml'
612
- else
613
- 'https://tunnistus.suomi.fi/static/metadata/idp-metadata-secondary.xml'
612
+ else # :production
613
+ 'https://tunnistus.suomi.fi/static/metadata/idp-metadata-tunnistautuminen.xml'
614
614
  end
615
615
  end
616
616
 
@@ -629,6 +629,16 @@ module OmniAuth
629
629
  slo_binding: ['urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect']
630
630
  )
631
631
 
632
+ if settings[:idp_slo_response_service_url].nil? && settings[:idp_slo_target_url].nil?
633
+ # Mitigation after ruby-saml update to 1.12.x. This gem has been
634
+ # originally developed relying on the `:idp_slo_target_url` settings
635
+ # which was removed from the newer versions. The SLO requests won't
636
+ # work unless `:idp_slo_response_service_url` is defined in the
637
+ # metadata through the `ResponseLocation` attribute in the
638
+ # `<SingleLogoutService />` node.
639
+ settings[:idp_slo_target_url] ||= settings[:idp_slo_service_url]
640
+ end
641
+
632
642
  # Local certificate and private key to decrypt the responses
633
643
  settings[:certificate] = certificate
634
644
  settings[:private_key] = private_key
@@ -662,8 +672,8 @@ module OmniAuth
662
672
  end
663
673
 
664
674
  def locale_for_authn_request
665
- if options.idp_sso_target_url_locale_params.is_a?(Array)
666
- options.idp_sso_target_url_locale_params.each do |param|
675
+ if options.idp_sso_service_url_locale_params.is_a?(Array)
676
+ options.idp_sso_service_url_locale_params.each do |param|
667
677
  next unless request.params.key?(param.to_s)
668
678
 
669
679
  locale = parse_language_value(request.params[param.to_s])
@@ -671,7 +681,7 @@ module OmniAuth
671
681
  end
672
682
  end
673
683
 
674
- options.idp_sso_target_url_default_locale
684
+ options.idp_sso_service_url_default_locale
675
685
  end
676
686
 
677
687
  def parse_language_value(string)
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This overrides the decryption method in RubySaml in order to add support for
4
+ # AES GCM decryption required by Suomi.fi. The Suomi.fi AES GCM cipher text
5
+ # contains an auth tag that needs to be extracted from the end of the cipher
6
+ # text before decrypting it. Otherwise the `cipher.final` method would fail
7
+ # becuse the decrypted data is incorrect.
8
+ #
9
+ # Related to this GitHub issue:
10
+ # https://github.com/onelogin/ruby-saml/issues/541
11
+ #
12
+ # This differs from the original implementation only with the following aspects:
13
+ # - Detects the AES GCM cipher methods
14
+ # - For the AES CGM cipher methods, extracts the auth tag from the end of the
15
+ # cipher text, assuming it to be 16 bytes in length.
16
+ #
17
+ # Regarding the authentication tag, see:
18
+ # https://tools.ietf.org/html/rfc5116#section-5.1
19
+ #
20
+ # > An authentication tag with a length of 16 octets (128
21
+ # > bits) is used. The AEAD_AES_128_GCM ciphertext is formed by
22
+ # > appending the authentication tag provided as an output to the GCM
23
+ # > encryption operation to the ciphertext that is output by that
24
+ # > operation.
25
+ OneLogin::RubySaml::Utils.class_eval do
26
+ # Obtains the deciphered text
27
+ # @param cipher_text [String] The ciphered text
28
+ # @param symmetric_key [String] The symetric key used to encrypt the text
29
+ # @param algorithm [String] The encrypted algorithm
30
+ # @return [String] The deciphered text
31
+ def self.retrieve_plaintext(cipher_text, symmetric_key, algorithm)
32
+ case algorithm
33
+ when 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' then cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').decrypt
34
+ when 'http://www.w3.org/2001/04/xmlenc#aes128-cbc' then cipher = OpenSSL::Cipher.new('AES-128-CBC').decrypt
35
+ when 'http://www.w3.org/2001/04/xmlenc#aes192-cbc' then cipher = OpenSSL::Cipher.new('AES-192-CBC').decrypt
36
+ when 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' then cipher = OpenSSL::Cipher.new('AES-256-CBC').decrypt
37
+ when 'http://www.w3.org/2009/xmlenc11#aes128-gcm' then auth_cipher = OpenSSL::Cipher.new('AES-128-GCM').decrypt
38
+ when 'http://www.w3.org/2009/xmlenc11#aes192-gcm' then auth_cipher = OpenSSL::Cipher.new('AES-192-GCM').decrypt
39
+ when 'http://www.w3.org/2009/xmlenc11#aes256-gcm' then auth_cipher = OpenSSL::Cipher.new('AES-256-GCM').decrypt
40
+ when 'http://www.w3.org/2001/04/xmlenc#rsa-1_5' then rsa = symmetric_key
41
+ when 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' then oaep = symmetric_key
42
+ end
43
+
44
+ if cipher
45
+ iv_len = cipher.iv_len
46
+ data = cipher_text[iv_len..-1]
47
+ cipher.padding = 0
48
+ cipher.key = symmetric_key
49
+ cipher.iv = cipher_text[0..iv_len - 1]
50
+ assertion_plaintext = cipher.update(data)
51
+ assertion_plaintext << cipher.final
52
+ elsif auth_cipher
53
+ iv_len = auth_cipher.iv_len
54
+ text_len = cipher_text.length
55
+ tag_len = 16
56
+ data = cipher_text[iv_len..text_len - 1 - tag_len]
57
+ auth_cipher.padding = 0
58
+ auth_cipher.key = symmetric_key
59
+ auth_cipher.iv = cipher_text[0..iv_len - 1]
60
+ auth_cipher.auth_data = ''
61
+ auth_cipher.auth_tag = cipher_text[text_len - tag_len..-1]
62
+ assertion_plaintext = auth_cipher.update(data)
63
+ assertion_plaintext << auth_cipher.final
64
+ elsif rsa
65
+ rsa.private_decrypt(cipher_text)
66
+ elsif oaep
67
+ oaep.private_decrypt(cipher_text, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
68
+ else
69
+ cipher_text
70
+ end
71
+ end
72
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Suomifi
5
- VERSION = '0.3.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -2,3 +2,4 @@
2
2
 
3
3
  require 'omniauth-suomifi/version'
4
4
  require 'omniauth/strategies/suomifi'
5
+ require 'omniauth-suomifi/ruby_saml_extensions'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-suomifi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antti Hukkanen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-saml
@@ -16,42 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.10.1
19
+ version: '2.0'
20
20
  type: :runtime
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.10.1
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-saml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.13.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.13.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '12.3'
47
+ version: '13.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '12.3'
54
+ version: '13.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.8'
61
+ version: '3.9'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.8'
68
+ version: '3.9'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rack-test
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -106,14 +120,14 @@ dependencies:
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: 0.16.0
123
+ version: 0.19.0
110
124
  type: :development
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
128
  - - "~>"
115
129
  - !ruby/object:Gem::Version
116
- version: 0.16.0
130
+ version: 0.19.0
117
131
  description: Suomi.fi e-Identification service integration for OmniAuth.
118
132
  email:
119
133
  - antti.hukkanen@mainiotech.fi
@@ -125,6 +139,7 @@ files:
125
139
  - README.md
126
140
  - Rakefile
127
141
  - lib/omniauth-suomifi.rb
142
+ - lib/omniauth-suomifi/ruby_saml_extensions.rb
128
143
  - lib/omniauth-suomifi/test.rb
129
144
  - lib/omniauth-suomifi/test/certificate_generator.rb
130
145
  - lib/omniauth-suomifi/test/templates/encrypted_data_template.xml