Class: Spid::Saml2::Utils::QueryParamsSigner

Inherits:
Object
  • Object
show all
Includes:
Spid::Saml2::Utils
Defined in:
lib/spid/saml2/utils/query_params_signer.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Spid::Saml2::Utils

#certificate_from_encoded_der, #decode, #decode_and_inflate, #deflate, #deflate_and_encode, #encode, #escaped_params, #escaped_query_string, #inflate, #query_param, #query_params, #query_string

Constructor Details

#initialize(saml_message:, private_key:, signature_method:, relay_state: nil) ⇒ QueryParamsSigner

Returns a new instance of QueryParamsSigner.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 16

def initialize(
      saml_message:,
      private_key:,
      signature_method:,
      relay_state: nil
    )
  @saml_message = saml_message.delete("\n")
  @private_key = private_key
  @signature_method = signature_method
  @relay_state = relay_state
end

Instance Attribute Details

#private_keyObject (readonly)

Returns the value of attribute private_key.



12
13
14
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 12

def private_key
  @private_key
end

#relay_stateObject (readonly)

Returns the value of attribute relay_state.



14
15
16
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 14

def relay_state
  @relay_state
end

#saml_messageObject (readonly)

Returns the value of attribute saml_message.



11
12
13
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 11

def saml_message
  @saml_message
end

#signature_methodObject (readonly)

Returns the value of attribute signature_method.



13
14
15
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 13

def signature_method
  @signature_method
end

Instance Method Details

#escaped_signed_query_stringObject



45
46
47
48
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 45

def escaped_signed_query_string
  @escaped_signed_query_string ||=
    escaped_query_string(signed_query_params)
end

#params_for_signatureObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 60

def params_for_signature
  @params_for_signature ||=
    begin
      params = {
        "SAMLRequest" => deflate_and_encode(saml_message),
        "RelayState" => relay_state,
        "SigAlg" => signature_method
      }
      params.delete("RelayState") if params["RelayState"].nil?
      params
    end
end

#raw_signatureObject



50
51
52
53
54
55
56
57
58
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 50

def raw_signature
  @raw_signature ||=
    begin
      private_key.sign(
        signature_algorithm,
        escaped_query_string(params_for_signature)
      )
    end
end

#signatureObject



32
33
34
35
36
37
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 32

def signature
  @signature ||=
    begin
      encode(raw_signature)
    end
end

#signature_algorithmObject



28
29
30
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 28

def signature_algorithm
  @signature_algorithm ||= Spid::SIGNATURE_ALGORITHMS[signature_method]
end

#signed_query_paramsObject



39
40
41
42
43
# File 'lib/spid/saml2/utils/query_params_signer.rb', line 39

def signed_query_params
  params_for_signature.merge(
    "Signature" => signature
  )
end