Class: OmniAuth::MPASSid::Test::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth-mpassid/test/utility.rb

Class Method Summary collapse

Class Method Details

.inflate_xml(encoded_deflated_xml) ⇒ Object



7
8
9
10
# File 'lib/omniauth-mpassid/test/utility.rb', line 7

def self.inflate_xml(encoded_deflated_xml)
  deflated_xml = Base64.decode64(encoded_deflated_xml)
  Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(deflated_xml)
end

.sign_xml_element(element, sign_certificate, sign_key) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/omniauth-mpassid/test/utility.rb', line 25

def self.sign_xml_element(element, sign_certificate, sign_key)
  doc = XMLSecurity::Document.new(element)
  doc.sign_document(
    sign_key,
    sign_certificate,
    XMLSecurity::Document::RSA_SHA256,
    XMLSecurity::Document::SHA256
  )
  # Move the signature to the correct position, otherwise schema
  # validation does not work because the internal logic of ruby-saml
  # cannot handle custom element names (saml2:Issuer instead of
  # saml:Issuer).
  signature = doc.delete_element('//ds:Signature')
  issuer = doc.elements['//saml2:Issuer']
  doc.root.insert_after(issuer, signature)

  doc.to_s
end

.signed_xml(raw_xml_file, opts) ⇒ Object



12
13
14
15
# File 'lib/omniauth-mpassid/test/utility.rb', line 12

def self.signed_xml(raw_xml_file, opts)
  raw_xml = IO.read(raw_xml_file)
  signed_xml_from_string(raw_xml, opts)
end

.signed_xml_from_string(raw_xml, opts) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/omniauth-mpassid/test/utility.rb', line 17

def self.signed_xml_from_string(raw_xml, opts)
  sign_xml_element(
    raw_xml,
    opts[:sign_certificate],
    opts[:sign_private_key]
  )
end