feat: update dependencies

This commit is contained in:
nanov
2023-10-11 21:58:26 +03:00
parent 66bf57f0dc
commit a03ec2283f
7 changed files with 2087 additions and 6982 deletions

View File

@@ -1,36 +1,50 @@
'use strict';
"use strict";
// const crypto = require('crypto');
const Crypto = require('../../crypto/Crypto');
const Crypto = require("../../crypto/Crypto");
const { DOMParser, XMLSerializer } = require('xmldom');
const xpath = require('xpath');
const C14n = require('xml-crypto/lib/c14n-canonicalization').C14nCanonicalization;
const { DOMParser, XMLSerializer } = require("@xmldom/xmldom");
const xpath = require("xpath");
const C14n =
require("xml-crypto/lib/c14n-canonicalization").C14nCanonicalization;
const digest = (doc) => {
// get the xml node, where the digested value is supposed to be
const nodeDigestValue = doc.getElementsByTagName('ds:DigestValue')[0];
const nodeDigestValue = doc.getElementsByTagName("ds:DigestValue")[0];
// canonicalize the node that has authenticate='true' attribute
const contentToDigest = xpath.select("//*[@authenticate='true']", doc)
.map(x => new C14n().process(x)).join('');
const contentToDigest = xpath
.select("//*[@authenticate='true']", doc)
.map((x) => new C14n().process(x))
.join("");
// fix the canonicalization
const fixedContent = contentToDigest.replace(/xmlns="urn:org:ebics:H004"/g, 'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"');
const fixedContent = contentToDigest.replace(
/xmlns="urn:org:ebics:H004"/g,
'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"'
);
if (nodeDigestValue)
nodeDigestValue.textContent = Crypto.digestWithHash(fixedContent).toString('base64').trim();
nodeDigestValue.textContent = Crypto.digestWithHash(fixedContent)
.toString("base64")
.trim();
return doc;
};
const sign = (doc, key) => {
const nodeSignatureValue = doc.getElementsByTagName('ds:SignatureValue')[0];
const nodeSignatureValue = doc.getElementsByTagName("ds:SignatureValue")[0];
if (nodeSignatureValue) {
const select = xpath.useNamespaces({ ds: 'http://www.w3.org/2000/09/xmldsig#' });
const contentToSign = (new C14n().process(select('//ds:SignedInfo', doc)[0])).replace('xmlns:ds="http://www.w3.org/2000/09/xmldsig#"', 'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"');
const select = xpath.useNamespaces({
ds: "http://www.w3.org/2000/09/xmldsig#",
});
const contentToSign = new C14n()
.process(select("//ds:SignedInfo", doc)[0])
.replace(
'xmlns:ds="http://www.w3.org/2000/09/xmldsig#"',
'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"'
);
nodeSignatureValue.textContent = Crypto.privateSign(key, contentToSign); // this.keys.x().key.sign(contentToSign, 'base64');
}
@@ -38,11 +52,11 @@ const sign = (doc, key) => {
return doc;
};
const toXML = doc => new XMLSerializer().serializeToString(doc);
const toXML = (doc) => new XMLSerializer().serializeToString(doc);
module.exports = {
sign(data, keyX) {
const doc = new DOMParser().parseFromString(data, 'text/xml');
const doc = new DOMParser().parseFromString(data, "text/xml");
return toXML(sign(digest(doc), keyX));
},