xml-crypto
xml-crypto copied to clipboard
Basic xades support
Finally I managed to understand minimum changes required for xades support:
- Add <Object><xadesQualifyingProperties>...</Object> between KeyInfo and Signature tags. I defined xadesQualifyingProperties function which should be redefined by user.
- Support reference to SignedProperties node which is inside xadesQualifyingProperties node.
- Reference to SignedProperties should have Type="http://uri.etsi.org/01903#SignedProperties" attribute.
Proposed usage example:
const sig = new SignedXml({publicCert: ..., privateKey: ..., etc.});
sig.addReference({ //your main reference to xml part needed to be signed
xpath: "//*[local-name() = 'Body']/*[1]",
transforms: ["http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/2001/10/xml-exc-c14n#"],
digestAlgorithm: "your algorithm",
});
sig.addReference({ //additional reference needed for xades compliance
xpath: "//*[name()='xades:SignedProperties']",
transforms: ["http://www.w3.org/2001/10/xml-exc-c14n#"],
digestAlgorithm: "your algorithm",
});
const cdate=new Date().toISOString();
sig.xadesQualifyingProperties = function () { //your xadesQualifyingProperties part creation
return '<xades:QualifyingProperties Target="#xmldsig-001'+'" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#">'+
'<xades:SignedProperties Id="xmldsig-001-signedprops">' +
'<xades:SignedSignatureProperties>'+
'<xades:SigningTime>' + cdate + '</xades:SigningTime>'+
'<xades:SigningCertificate>'+
'<xades:Cert>'+
...
'</xades:Cert>'+
'</xades:SigningCertificate>'+
'</xades:SignedSignatureProperties>'+
'</xades:SignedProperties>'+
'</xades:QualifyingProperties>';
}
const sigpar = {location: { reference: "//*[local-name() = 'Body']/*[1]/*[1]", action: "before" }, attrs: { Id: 'xmldsig-001'}, prefix:"ds" }; //additional preferences
sig.computeSignature(your_xml, sigpar);
const result = sig.getSignedXml();
Thank you for putting this up. Please include some tests so that this doesn't break in the future. Also, please make sure that you run npm test
and npm run lint:fix
, otherwise your PR might not pass the checks. After you do that, I'll review the code.
Codecov Report
Attention: 10 lines
in your changes are missing coverage. Please review.
Comparison is base (
627d83f
) 73.05% compared to head (f1ac51c
) 72.47%.
Files | Patch % | Lines |
---|---|---|
src/signed-xml.ts | 28.57% | 7 Missing and 3 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #444 +/- ##
==========================================
- Coverage 73.05% 72.47% -0.59%
==========================================
Files 9 9
Lines 902 912 +10
Branches 239 244 +5
==========================================
+ Hits 659 661 +2
- Misses 143 149 +6
- Partials 100 102 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Do you need help with this?