Class: Util

Inherits:
Object
  • Object
show all
Defined in:
lib/utils.rb

Instance Method Summary collapse

Instance Method Details

#ejemploObject



7
8
9
# File 'lib/utils.rb', line 7

def ejemplo
  return true
end

#signXml(input_xml) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/utils.rb', line 11

def signXml (input_xml)

  document = Nokogiri::XML(input_xml.body)
  envelope = document.at_xpath("//env:Envelope")
  envelope.prepend_child("<env:Header><wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' wsse:mustUnderstand='1'/></env:Header>")
  xml = document.to_s

  signer = Signer.new(xml)

  signer.cert = OpenSSL::X509::Certificate.new(@public_cert)
  signer.private_key = OpenSSL::PKey::RSA.new(@private_key)

  signer.document.xpath("//soapenv:Body", { "soapenv" => "http://schemas.xmlsoap.org/soap/envelope/" }).each do |node|
    signer.digest!(node)
  end

  signer.sign!(:issuer_serial => true)
  signed_xml = signer.to_xml

  document = Nokogiri::XML(signed_xml)
  x509data = document.at_xpath("//*[local-name()='X509Data']")
  new_data = x509data.clone()
  new_data.set_attribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")

  n = Nokogiri::XML::Node.new('wsse:SecurityTokenReference', document)
  n.add_child(new_data)
  x509data.add_next_sibling(n)

  return document
end