I have a namespaced XML document what must bu signed using special browser plugin.
Here is the peace code, that sign document:
var oCertificate = GetCertificateBySubjectName(certificateName);
var token = oCertificate.Export(CADESCOM_ENCODE_BASE64);
var element, xmlDoc;
xmlDoc = $.parseXML(doc.toString());
element = $(xmlDoc).find("o\\:BinarySecurityToken");
element.text(token);
var xmlString = undefined;
if (window.ActiveXObject) {
xmlString = xmlDoc[0];
}
if (xmlString === undefined) {
var oSerializer = new XMLSerializer();
xmlString = (new XMLSerializer()).serializeToString(xmlDoc);
}
var doc = SignCreate(oCertificate, xmlString);
where doc is string that contains XML.
Here is the peace of XML what must be signed:
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:actor="http://smev.gosuslugi.ru/actors/smev">
<o:BinarySecurityToken u:Id="uuid-ee82d445-758b-42cb-996c-666b74b60022-2" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"/>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411" />
<Reference URI="#_1">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr3411" />
<DigestValue/>
</Reference>
</SignedInfo>
<SignatureValue/>
<KeyInfo>
<o:SecurityTokenReference>
<o:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid-ee82d445-758b-42cb-996c-666b74b60022-2" />
</o:SecurityTokenReference>
</KeyInfo>
</Signature>
</o:Security>
</s:Header>
Signing of the document works like this. Using
xmlDoc = $.parseXML(message.toString());
element = $(xmlDoc).find("o\\:BinarySecurityToken");
element.text(token);
I put token from sertificate into <o:BinarySecurityToken> then convert it back to string and send to sign.
In this steps I've got:
<o:BinarySecurityToken u:Id="uuid-ee82d445-758b-42cb-996c-666b74b60022-2" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">!!TOKEN!!</o:BinarySecurityToken>
and then
<o:BinarySecurityToken u:Id="uuid-ee82d445-758b-42cb-996c-666b74b60022-2" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">!!!TOKEN!!!</o:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"/>
<Reference URI="#_1">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr3411"/>
<DigestValue>!!!SIGNATURE DIGEST VALUE!!!</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>!!!SIGNATURE!!!</SignatureValue>
Everything works excellent in FireFox and (!)IE, but doesn't works in Google Chrome. In Chrome code that puts token into leave it empty and all other methods will not work.
So, my question is: What should I do to solve this problem? I try to use https://github.com/rfk/jquery-xmlns to give jQuery some power to work with namespaced XML, but this library didn't run in my code.
Thanks in advance.
P.S. I use jQuery 1.10.2