[ad_1]
I'm doing a soap signed request on Ruby on Rails using the gem signer. My client gave a format and somehow my output is different from that. Here's the sample one:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-d018f635-7453-4341-8d11-bcf5f490a649">
It has an Id attribute but on my ds:Signature
on my result doesn't have. Here's my code on soap signing
signer = Signer.new(request.body)
signer.cert = OpenSSL::X509::Certificate.new(File.read(CERT))
signer.private_key = OpenSSL::PKey::RSA.new(File.read(WS_CLIENT_KEY))
signer.digest_algorithm = :sha256 # Set algorithm for node digesting
signer.signature_digest_algorithm = :sha256 # Set algorithm for message digesting for signing
signer.document.root.add_namespace 'wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
signer.ds_namespace_prefix = 'ds'
envelope_node = Nokogiri::XML::Node.new "soap:Envelope", signer.document
envelope_node["xmlns:soap"] = "http://schemas.xmlsoap.org/soap/envelope/"
header_node = Nokogiri::XML::Node.new "soap:Header", signer.document
soapBody = signer.document.xpath("//soap:Body").first
soapBody.add_previous_sibling(header_node)
security_node = Nokogiri::XML::Node.new "Security", signer.document
security_node["xmlns:wsse"] = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
security_node["xmlns:wsu"] = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
security_node["soap:mustUnderstand"] = "1"
security_node.namespace = signer.document.root.namespace_definitions.find ns.prefix=="wsse"
header_node.add_child(security_node)
node = signer.document.xpath("//soap:Body").first
node.add_namespace_definition("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
signature_node = signer.document.xpath("//wsse:Security").first.children.first
signer.digest!(node)
signer.sign!(inclusive_namespaces: ['soap'], prefix_list: 'soap', :security_token => true, id: 'Id')
request.body = signer.document.to_s
request
Hope someone would help me. Thanks!
[ad_2]
لینک منبع