class Util
Public Instance Methods
ejemplo()
click to toggle source
# File lib/utils.rb, line 7 def ejemplo return true end
signXml(input_xml)
click to toggle source
# 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