-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding xmlns where i don't want to #176
Comments
I used existingPrefixes before coming here, thought it would solve it. But the xmlns doesn't go away... const SignedXml = require('xml-crypto').SignedXml;
class XmlSignatureController {
constructor() {
}
addSignatureToXml (xml, certificate, tagBeforeSignature) {
return new Promise ((resolve, reject) => {
try {
let x509 = certificate.cert.replace(/\n/g, '');
x509 = x509.replace(/-----END CERTIFICATE-----/g, '');
x509 = x509.split('-----BEGIN CERTIFICATE-----')[1];
const sig = new SignedXml();
sig.keyInfoProvider = new myKeyInfo(x509);
sig.addReference("//*[local-name(.)='" + tagBeforeSignature + "']", ["http://www.w3.org/2000/09/xmldsig#enveloped-signature", 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315']);
sig.canonicalizationAlgorithm = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315';
sig.signingKey = certificate;
sig.computeSignature(xml, {
existingPrefixes: {
ns4: 'http://www.ginfes.com.br/tipos_v03.xsd'
}
});
resolve(sig.getSignedXml());
} catch (error) {
reject(error);
}
})
}
}
module.exports = XmlSignatureController;
function myKeyInfo(x509Certificate){
this.getKeyInfo = function(key) {
return '<X509Data><X509Certificate>'+x509Certificate+'</X509Certificate></X509Data>';
};
this.getKey = function(keyInfo) {
// return the public key in pem format
return getPublicKeyPemFromCertificate(x509Certificate).toString();
};
} It keeps returning "<ns4:Rps xmlns:ns4="">" in the xml... :( |
Can you reproduce your package.json and package-lock.json so that I can have a look? Only version 1.2.0 onwards should have support for |
I know that. I am using 1.2.. here it goes package.json
and package-lock.json:
|
If you leave an example message for me to try it out against your code snippet, i might have some to troubleshoot this when I have time. |
Trying to better illustrate it... The deal is I don't want crypto to add a namespace to it, but it is always returning: It is being nested inside this: And I'm using crypto existingPrefixes like this:
|
@LoneRifle @ryzzan I have the same problem here. I have <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SignatureSP"> and I want <ds:Signature Id="SignatureSP"> I am trying Any idea? |
Were you able to solve this? I am getting the same problem |
I have been trying to figure the problem for the past few hours and it seems it lies with the Specifically with this function: I am not sure why, but in my use case it adds the root |
@tiagosolci the issue is with the xmldom library xmldom/xmldom#96. |
(late) update: This issue was fixed since #236 was merged, see xmldom/xmldom#96 (comment) So it can be closed |
I'm creating an xml string inside a loop, and over each xml created inside of it I'm supposed to make a signature.
Its elements (inside the loop) has a prefix (ns4), but this prefix xmlns is described outside the loop.
xml-crypto forces the xmlns (to ns4 prefix) everytime the element is created inside the loop.
How do I prevent it?
The text was updated successfully, but these errors were encountered: