saml-kit 0.2.9 → 0.2.10
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 +4 -4
- data/lib/saml/kit/bindings/http_redirect.rb +29 -9
- data/lib/saml/kit/trustable.rb +3 -2
- data/lib/saml/kit/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e2deef2c819d3c504c5f5555e8a23aa0acb264f6770873262749454ebfdbd196
         | 
| 4 | 
            +
              data.tar.gz: d626b0565324c8395bc8d13d5952e798919cabb1462ac64101a04f696b5842b0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
                       | 
| 20 | 
            -
                       | 
| 21 | 
            -
                      document | 
| 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[ | 
| 33 | 
            +
                      return if params[:Signature].blank? || params[:SigAlg].blank?
         | 
| 35 34 |  | 
| 36 | 
            -
                      signature = decode(params[ | 
| 37 | 
            -
                      canonical_form = [ | 
| 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 | 
            -
                       | 
| 43 | 
            -
                       | 
| 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
         | 
    
        data/lib/saml/kit/trustable.rb
    CHANGED
    
    | @@ -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 | 
| 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
         | 
    
        data/lib/saml/kit/version.rb
    CHANGED