Skip to content
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

Basic xades support #444

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

GauriSpears
Copy link

@GauriSpears GauriSpears commented Jan 17, 2024

Finally I managed to understand minimum changes required for xades support:

  1. Add ... between KeyInfo and Signature tags. I defined xadesQualifyingProperties function which should be redefined by user.
  2. Support reference to SignedProperties node which is inside xadesQualifyingProperties node.
  3. 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();

@cjbarth
Copy link
Contributor

cjbarth commented Jan 17, 2024

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.

@GauriSpears GauriSpears marked this pull request as draft January 18, 2024 13:35
Copy link

codecov bot commented Jan 26, 2024

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 ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shunkica
Copy link
Contributor

Do you need help with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants