saml-kit 0.2.9 → 0.2.10

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: 0bf388798a57928e726edb29bf5a4998f43a62139b4cb5da662a73e434b23dae
4
- data.tar.gz: 3c5d2bc07e37dcc6f95779bde81cfdff175f5f61929370dcd7fa6950e3614676
3
+ metadata.gz: e2deef2c819d3c504c5f5555e8a23aa0acb264f6770873262749454ebfdbd196
4
+ data.tar.gz: d626b0565324c8395bc8d13d5952e798919cabb1462ac64101a04f696b5842b0
5
5
  SHA512:
6
- metadata.gz: ee450ff950b85fa7f4d6c6f32a97015eb0cb6ddf530560a243b97a9c5bab3f488f32be5a94bf439614f3d3378eeb8f5bbcbc92d9935d2bdf3f161d08a29ee466
7
- data.tar.gz: 81eceb240153a8095a00f82e315b1b623ad3b1c27bb86ce59b2294ebf143d7bc4a57193d2a6ca2a1e31b251e19991d9f0b99d11f914f457972ebc7d27f58a04e
6
+ metadata.gz: 8f9c61f5c92f27893418dd16bf79e6eb092374c88083a7f1764e758484182f55624c6b6956b14dc9ff78b14175313fbca9492873996488309ed6ba4ab4076f6d
7
+ data.tar.gz: 247d482f32aa92924cc8601d773d3d988b6d3646c08c28911ce6f25449d8264ffa141fd28cf431dd64807acdf6473e41c034222a1585de0acd80e9fdc49047a5
@@ -16,9 +16,9 @@ module Saml
16
16
  end
17
17
 
18
18
  def deserialize(params, configuration: Saml::Kit.configuration)
19
- document = deserialize_document_from!(params, configuration)
20
- ensure_valid_signature!(params, document)
21
- document.signature_verified!
19
+ parameters = normalize(params)
20
+ document = deserialize_document_from!(parameters, configuration)
21
+ ensure_valid_signature!(parameters, document)
22
22
  document
23
23
  end
24
24
 
@@ -26,21 +26,24 @@ module Saml
26
26
 
27
27
  def deserialize_document_from!(params, configuration)
28
28
  xml = inflate(decode(unescape(saml_param_from(params))))
29
- Saml::Kit.logger.debug(xml)
30
29
  Saml::Kit::Document.to_saml_document(xml, configuration: configuration)
31
30
  end
32
31
 
33
32
  def ensure_valid_signature!(params, document)
34
- return if params['Signature'].blank? || params['SigAlg'].blank?
33
+ return if params[:Signature].blank? || params[:SigAlg].blank?
35
34
 
36
- signature = decode(params['Signature'])
37
- canonical_form = ['SAMLRequest', 'SAMLResponse', 'RelayState', 'SigAlg'].map do |key|
35
+ signature = decode(params[:Signature])
36
+ canonical_form = [:SAMLRequest, :SAMLResponse, :RelayState, :SigAlg].map do |key|
38
37
  value = params[key]
39
38
  value.present? ? "#{key}=#{value}" : nil
40
39
  end.compact.join('&')
41
40
 
42
- valid = document.provider.verify(algorithm_for(params['SigAlg']), signature, canonical_form)
43
- raise ArgumentError.new("Invalid Signature") unless valid
41
+ return if document.provider.nil?
42
+ if document.provider.verify(algorithm_for(params[:SigAlg]), signature, canonical_form)
43
+ document.signature_verified!
44
+ else
45
+ raise ArgumentError.new("Invalid Signature")
46
+ end
44
47
  end
45
48
 
46
49
  def algorithm_for(algorithm)
@@ -55,6 +58,23 @@ module Saml
55
58
  OpenSSL::Digest::SHA1.new
56
59
  end
57
60
  end
61
+
62
+ def normalize(params)
63
+ if params.respond_to? :inject
64
+ params.inject({}) do |memo, (key, value)|
65
+ memo[key.to_sym] = value
66
+ memo
67
+ end
68
+ else
69
+ {
70
+ SAMLRequest: params['SAMLRequest'] || params[:SAMLRequest],
71
+ SAMLResponse: params['SAMLResponse'] || params[:SAMLResponse],
72
+ RelayState: params['RelayState'] || params[:RelayState],
73
+ Signature: params['Signature'] || params[:Signature],
74
+ SigAlg: params['SigAlg'] || params[:SigAlg],
75
+ }
76
+ end
77
+ end
58
78
  end
59
79
  end
60
80
  end
@@ -6,11 +6,11 @@ module Saml
6
6
  included do
7
7
  validate :must_have_valid_signature, unless: :signature_manually_verified
8
8
  validate :must_be_registered
9
- validate :must_be_trusted, unless: :signature_manually_verified
9
+ validate :must_be_trusted
10
10
  end
11
11
 
12
12
  def signed?
13
- signature.present?
13
+ signature_manually_verified || signature.present?
14
14
  end
15
15
 
16
16
  def signature
@@ -19,6 +19,7 @@ module Saml
19
19
  end
20
20
 
21
21
  def trusted?
22
+ return true if signature_manually_verified
22
23
  return false unless signed?
23
24
  signature.trusted?(provider)
24
25
  end
@@ -1,5 +1,5 @@
1
1
  module Saml
2
2
  module Kit
3
- VERSION = "0.2.9"
3
+ VERSION = "0.2.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saml-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan