omniauth-suomifi 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/omniauth-suomifi.rb +1 -0
- data/lib/omniauth-suomifi/ruby_saml_extensions.rb +68 -0
- data/lib/omniauth-suomifi/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a565773bca57e1803acfbf666ee25c54474374831857b4a1d7eeec965dbf289
|
4
|
+
data.tar.gz: f555e8a657886b482b19bc93decac583dd3f6101c2060a48f9f811cc27af1272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df188a2b7f673b6b2710a63dda35c123b5d757d2a0310b11b76ed43f58ec0c8cc39aa682bb2c99caa8967c5a8083137dc7340804e311aaae7ac20aaabed91739
|
7
|
+
data.tar.gz: ce866b947cce063f0df0233bca9a5de7836b2b0326c4dab6398abb6255cd4b58627d365d9abcae09d74bc27fc4f0c7a07ab8f67eaac73efc2ebf0e3891758aeb
|
data/lib/omniauth-suomifi.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
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, cipher.key, cipher.iv = 0, symmetric_key, cipher_text[0..iv_len-1]
|
48
|
+
assertion_plaintext = cipher.update(data)
|
49
|
+
assertion_plaintext << cipher.final
|
50
|
+
elsif auth_cipher
|
51
|
+
iv_len, text_len, tag_len = auth_cipher.iv_len, cipher_text.length, 16
|
52
|
+
data = cipher_text[iv_len..text_len-1-tag_len]
|
53
|
+
auth_cipher.padding = 0
|
54
|
+
auth_cipher.key = symmetric_key
|
55
|
+
auth_cipher.iv = cipher_text[0..iv_len-1]
|
56
|
+
auth_cipher.auth_data = ''
|
57
|
+
auth_cipher.auth_tag = cipher_text[text_len-tag_len..-1]
|
58
|
+
assertion_plaintext = auth_cipher.update(data)
|
59
|
+
assertion_plaintext << auth_cipher.final
|
60
|
+
elsif rsa
|
61
|
+
rsa.private_decrypt(cipher_text)
|
62
|
+
elsif oaep
|
63
|
+
oaep.private_decrypt(cipher_text, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
|
64
|
+
else
|
65
|
+
cipher_text
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
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.
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-saml
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.10.
|
19
|
+
version: 1.10.3
|
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.
|
26
|
+
version: 1.10.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.9'
|
48
48
|
type: :development
|
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: '3.
|
54
|
+
version: '3.9'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-test
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,14 +106,14 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.19.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
116
|
+
version: 0.19.0
|
117
117
|
description: Suomi.fi e-Identification service integration for OmniAuth.
|
118
118
|
email:
|
119
119
|
- antti.hukkanen@mainiotech.fi
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- README.md
|
126
126
|
- Rakefile
|
127
127
|
- lib/omniauth-suomifi.rb
|
128
|
+
- lib/omniauth-suomifi/ruby_saml_extensions.rb
|
128
129
|
- lib/omniauth-suomifi/test.rb
|
129
130
|
- lib/omniauth-suomifi/test/certificate_generator.rb
|
130
131
|
- lib/omniauth-suomifi/test/templates/encrypted_data_template.xml
|