c# - soap with securityheader calling java webservice -
c# - soap with securityheader calling java webservice -
i'm trying send soap request java webservice signature check retuning false
can help me, please, i've been looking week , still not found solution..
this security-tag example
<wsse:security xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:usernametoken wsu:id="refid> <wsse:username>username</wsse:username> <wsse:password type="wsse:passworddigest">password</wsse:password> <wsse:nonce encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#base64binary">noncedata</wsse:nonce> <wsu:created>2013-02-11t12:53:27z</wsu:created> </wsse:usernametoken> <ds:signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:signedinfo> <ds:canonicalizationmethod algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> <ds:signaturemethod algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> <ds:reference uri="#refid"> <ds:digestmethod algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> <ds:digestvalue>digestvaluedata</ds:digestvalue> </ds:reference> </ds:signedinfo> <ds:signaturevalue>signaturevaluedata</ds:signaturevalue> </ds:signature> </wsse:security> i have custom created security tag. have created usernametokentag multiple xmlelements. need sign usernametokentag certificate verifyxml returns false , phone call java webservice fails due invalid signature. below code how create signed xml
private xmldocument getsignedxml(xmldocument xmldocument) { xmlnamespacemanager nsmgr = new xmlnamespacemanager(xmldocument.nametable); nsmgr.addnamespace(pptluxsoapdocument.prefix, pptluxsoapdocument.namespaceuri); nsmgr.addnamespace(pptluxsoapdocument.header.securityprefix, pptluxsoapdocument.header.securitynamespaceuri); nsmgr.addnamespace(pptluxsoapdocument.header.usernametokenprefix, pptluxsoapdocument.header.usernametokennamespaceuri); nsmgr.addnamespace(pptluxsoapdocument.header.signatureprefix, pptluxsoapdocument.header.signaturenamespaceuri); var usernametokennode = xmldocument.selectnodes("//soapenv:header/wsse:security/wsse:usernametoken", nsmgr); var signedxml = new customsignedxml(xmldocument); string referenceuri = "#refid"; var cert = getclientcertificate(); if (cert != null) { signedxml.signingkey = cert.privatekey; } signedxml.signedinfo.canonicalizationmethod = signedxml.xmldsigexcc14ntransformurl; // add together reference signedxml object. var reference = new reference(); reference.addtransform(new xmldsigenvelopedsignaturetransform()); reference.addtransform(new xmldsigexcc14ntransform()); reference.uri = referenceuri; //var env = new xmldsigenvelopedsignaturetransform(); //env.algorithm = signedxml.xmldsigexcc14ntransformurl; //reference.addtransform(env); //reference.digestmethod = signedxml.xmldsigsha1url; signedxml.addreference(reference); //xmldsigexcc14ntransform canmethod = (xmldsigexcc14ntransform)signedxml.signedinfo.canonicalizationmethodobject; ////canmethod.inclusivenamespacesprefixlist = "wsu"; //canmethod.algorithm = signedxml.xmldsigexcc14ntransformurl; signedxml.signedinfo.signaturemethod = signedxml.xmldsigrsasha1url; // compute signature. signedxml.computesignature(); // xml representation of signature , save // xmlelement object. xmlelement xmldigitalsignature = signedxml.getxml(); foreach (xmlnode node in xmldigitalsignature.selectnodes("descendant-or-self::*[namespace-uri()='http://www.w3.org/2000/09/xmldsig#']")) { node.prefix = pptluxsoapdocument.header.signatureprefix; } if (xmldigitalsignature != null) { string tagreferencename = pptluxsoapdocument.header.signatureprefix + ":reference"; var xmlreferencenodelist = xmldigitalsignature.getelementsbytagname(tagreferencename).item(0).childnodes; if (xmlreferencenodelist != null) { foreach (xmlnode xmlnode in xmlreferencenodelist) { if (xmlnode.localname == "transforms") { xmldigitalsignature.getelementsbytagname(tagreferencename).item(0).removechild(xmlnode); } } } string tagobjectname = pptluxsoapdocument.header.signatureprefix + ":object"; var xmlobjectnode = xmldigitalsignature.getelementsbytagname(tagobjectname).item(0); if (xmlobjectnode != null && xmlobjectnode.localname == "object") { xmldigitalsignature.removechild(xmlobjectnode); } } var signatureelement = xmldocument.createelement(pptluxsoapdocument.header.signatureprefix, "signature", pptluxsoapdocument.header.signaturenamespaceuri); foreach (xmlnode node in xmldigitalsignature.childnodes) { xmlnode imported = xmldocument.importnode(node, true); signatureelement.appendchild(imported); } var securitynode = xmldocument.selectsinglenode("//soapenv:header/wsse:security", nsmgr); securitynode.appendchild(signatureelement); homecoming xmldocument; } here customsignedxml class
public class customsignedxml : signedxml { public customsignedxml(xmldocument document) : base(document) { } public override xmlelement getidelement( xmldocument document, string idvalue) { xmlnamespacemanager nsmgr = new xmlnamespacemanager(document.nametable); nsmgr.addnamespace(pptluxsoapdocument.prefix, pptluxsoapdocument.namespaceuri); nsmgr.addnamespace(pptluxsoapdocument.header.securityprefix, pptluxsoapdocument.header.securitynamespaceuri); nsmgr.addnamespace(pptluxsoapdocument.header.usernametokenprefix, pptluxsoapdocument.header.usernametokennamespaceuri); nsmgr.addnamespace(pptluxsoapdocument.header.signatureprefix, pptluxsoapdocument.header.signaturenamespaceuri); //var xmlelement = (xmlelement)document.selectsinglenode("//*[@myid='" + idvalue + "']"); var xmlelement = (xmlelement)document.selectsinglenode("//*[@wsu:id='" + idvalue + "']", nsmgr); homecoming xmlelement; } } c# xml .net-2.0 xml-signature x509certificate2
Comments
Post a Comment