19 Commits

Author SHA1 Message Date
dependabot[bot]
6bc2e508de chore(deps): bump xml-crypto from 4.1.0 to 6.0.0
Bumps [xml-crypto](https://github.com/node-saml/xml-crypto) from 4.1.0 to 6.0.0.
- [Release notes](https://github.com/node-saml/xml-crypto/releases)
- [Changelog](https://github.com/node-saml/xml-crypto/blob/master/CHANGELOG.md)
- [Commits](https://github.com/node-saml/xml-crypto/compare/v4.1.0...v6.0.0)

---
updated-dependencies:
- dependency-name: xml-crypto
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-01 17:06:50 +00:00
Dimitar Nanov
388156a2e4 Merge pull request #92 from node-ebics/fix/request
Fix/request
2024-04-30 03:09:13 +03:00
nanov
231830addc chore: bump version 2024-04-30 03:08:25 +03:00
nanov
475fc58289 chore: align licensces between package.json and LICENSE.MD 2024-04-30 03:06:39 +03:00
nanov
ba997d312b fix: correct rock post signature 2024-04-30 03:05:31 +03:00
Dimitar Nanov
bc4b33f7e4 Merge pull request #89 from node-ebics/dependabot/npm_and_yarn/babel/traverse-7.23.2
chore(deps-dev): bump @babel/traverse from 7.13.13 to 7.23.2
2023-10-17 09:11:19 +03:00
dependabot[bot]
b1abf16864 chore(deps-dev): bump @babel/traverse from 7.13.13 to 7.23.2
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.13.13 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-17 02:59:03 +00:00
nanov
fd7bdfe55d t pushMerge branch 'master' of github.com:node-ebics/node-ebics-client 2023-10-11 22:34:00 +03:00
nanov
e41c0bf74d chore(deps): update lock 2023-10-11 22:32:35 +03:00
Dimitar Nanov
36b8d2999c Update CI.yml 2023-10-11 22:28:23 +03:00
Dimitar Nanov
510654f52e Update CI.yml 2023-10-11 22:27:08 +03:00
Dimitar Nanov
e251cc0e5b Merge pull request #88 from node-ebics/update-deps
Update deps
2023-10-11 22:20:43 +03:00
nanov
8da104515c chore: version number 2023-10-11 22:19:58 +03:00
Dimitar Nanov
f3bd654739 Merge pull request #87 from node-ebics/update-deps
Update dependencies, replace deprecated libs
2023-10-11 22:18:47 +03:00
nanov
b6b27516d5 feat: replace <request> with <rock-req> 2023-10-11 22:15:35 +03:00
nanov
a03ec2283f feat: update dependencies 2023-10-11 21:58:26 +03:00
Dimitar Nanov
66bf57f0dc Merge pull request #75 from get-momo/ci
Add CI
2023-01-06 18:27:36 +02:00
Sonny Piers
3a8dc1da0b chore: Update dev dependency libxmljs
The update is required to run tests on Node.js 18

The massive change to package-lock.json is due to an npm major upgade.

>
> The package-lock.json file was created with an old version of npm,
> so supplemental metadata must be fetched from the registry.
>
> This is a one-time fix-up, please be patient...
>
2022-08-18 15:41:13 +02:00
Sonny Piers
a3ce00eb3e chore: Enable CI
Inspired by
094c36e88e/README.md (matrix-testing)
2022-08-18 15:40:47 +02:00
9 changed files with 4798 additions and 3734 deletions

23
.github/workflows/CI.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: CI
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18, 19, 20 ]
name: Node.js ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm test

View File

@@ -1,8 +1,8 @@
language: node_js
node_js:
- "8"
- "9"
- "10"
- "11"
- "12"
- "16" # maintance lts
- "17"
- "18" # active lts
- "19"
- "20" # current
after_success: npm run coverage

View File

@@ -1,5 +1,21 @@
### Changelog
#### [v4.0.0](https://github.com/node-ebics/node-ebics-client/compare/v3.0.0...v0.4.0)
- Add CI [`#75`](https://github.com/node-ebics/node-ebics-client/pull/75)
- feat: update dependencies [`a03ec22`](https://github.com/node-ebics/node-ebics-client/commit/a03ec2283fdd3dcf750c5ed448f0195d92c5c9f0)
- chore: Update dev dependency libxmljs [`3a8dc1d`](https://github.com/node-ebics/node-ebics-client/commit/3a8dc1da0bac20a6f25a687da0a783f3b52d5163)
- feat: replace &lt;request&gt; with &lt;rock-req&gt; [`b6b2751`](https://github.com/node-ebics/node-ebics-client/commit/b6b27516d5854b38dcdbe56f23967001f844e631)
### [v3.0.0](https://github.com/node-ebics/node-ebics-client/compare/v0.2.1...v3.0.0)
> 4 August 2022
- Update LICENSE [`7520a56`](https://github.com/node-ebics/node-ebics-client/commit/7520a56be8ba446d3466c6dc9202b1d65ea3396f)
- changelog [`fe0f585`](https://github.com/node-ebics/node-ebics-client/commit/fe0f585b277c390415841a343aa86d4533997057)
- chore: update license in package.json, bump version [`b46b214`](https://github.com/node-ebics/node-ebics-client/commit/b46b214e57cf1b4e30455da306b26b3a06dc8a5f)
#### [v0.2.1](https://github.com/node-ebics/node-ebics-client/compare/v0.2.0...v0.2.1)
> 30 March 2021
@@ -84,38 +100,43 @@
#### [v0.1.1](https://github.com/node-ebics/node-ebics-client/compare/v0.1.0...v0.1.1)
> 5 November 2019
> 7 November 2019
- chore: update license [`9aabe93`](https://github.com/node-ebics/node-ebics-client/commit/9aabe933e91b506ea38820b952ce8e5e58b4c2ff)
#### [v0.1.0](https://github.com/node-ebics/node-ebics-client/compare/v0.0.8...v0.1.0)
#### [v0.1.0](https://github.com/node-ebics/node-ebics-client/compare/v0.0.36...v0.1.0)
> 5 November 2019
- Feat: handle unsual exponent migrate to node-forge [`#16`](https://github.com/node-ebics/node-ebics-client/pull/16)
- Add order generation tests and fix linting [`#15`](https://github.com/node-ebics/node-ebics-client/pull/15)
- test script run mocha [`#14`](https://github.com/node-ebics/node-ebics-client/pull/14)
- chore: readme maintenance [`#11`](https://github.com/node-ebics/node-ebics-client/pull/11)
- Provide examples [`#10`](https://github.com/node-ebics/node-ebics-client/pull/10)
- * Add Z53 order type [`#7`](https://github.com/node-ebics/node-ebics-client/pull/7)
- remove eCollect from constant and minor verbose error handeling [`#2`](https://github.com/node-ebics/node-ebics-client/pull/2)
- add iso pain format XCT order type [`#1`](https://github.com/node-ebics/node-ebics-client/pull/1)
- remove eCollect from constant and minor verbose error handaling [`#4`](https://github.com/node-ebics/node-ebics-client/pull/4)
- add iso pain format XCT order type [`#5`](https://github.com/node-ebics/node-ebics-client/pull/5)
- Fix parsing of the bank keys in the HPB response [`#3`](https://github.com/node-ebics/node-ebics-client/pull/3)
- feat: prepare order generation tests [`e40f79c`](https://github.com/node-ebics/node-ebics-client/commit/e40f79cee68a194272c93f07e763175b213a77a1)
- chore: cleanup [`0c01420`](https://github.com/node-ebics/node-ebics-client/commit/0c01420c1e14992a4169098ccd47cd196b899f06)
- Major changes. Separating responsibilities. Orders builder, serializer. [`ff9a3a1`](https://github.com/node-ebics/node-ebics-client/commit/ff9a3a16b47d0a25674134c875bfd651995837e4)
- code optimization [`1876360`](https://github.com/node-ebics/node-ebics-client/commit/187636019c290d757aca77d4c14fb4f2519acd38)
#### [v0.0.36](https://github.com/node-ebics/node-ebics-client/compare/v0.0.35...v0.0.36)
> 1 June 2018
> 7 November 2019
- various modular fixes [`8492d94`](https://github.com/node-ebics/node-ebics-client/commit/8492d940542f61b17aa3a2da7de23f6539ffaad5)
#### [v0.0.35](https://github.com/node-ebics/node-ebics-client/compare/v0.0.3...v0.0.35)
#### [v0.0.35](https://github.com/node-ebics/node-ebics-client/compare/v0.0.8...v0.0.35)
> 31 May 2018
- update License to GPL v3 [`babcf76`](https://github.com/node-ebics/node-ebics-client/commit/babcf76b61af6eb737ab291a301e71bb84621820)
- Add MGF1.js file - mask generation utility class [`7e6e2ff`](https://github.com/node-ebics/node-ebics-client/commit/7e6e2ff142688b0c453369fa7137b49e8b89cd81)
- Add sign, _emsaPSS and _modPowe methods in Key.js file [`5ace213`](https://github.com/node-ebics/node-ebics-client/commit/5ace2137231af9a3563ab31fa0f70fbdf4b148cb)
> 7 November 2019
#### [v0.0.8](https://github.com/node-ebics/node-ebics-client/compare/v0.0.7...v0.0.8)
> 8 October 2019
> 7 November 2019
- chore: readme maintenance [`#11`](https://github.com/node-ebics/node-ebics-client/pull/11)
- Provide examples [`#10`](https://github.com/node-ebics/node-ebics-client/pull/10)
@@ -126,7 +147,7 @@
#### [v0.0.7](https://github.com/node-ebics/node-ebics-client/compare/v0.0.6...v0.0.7)
> 2 August 2019
> 7 November 2019
- * Add Z53 order type [`#7`](https://github.com/node-ebics/node-ebics-client/pull/7)
- remove eCollect from constant and minor verbose error handeling [`#2`](https://github.com/node-ebics/node-ebics-client/pull/2)
@@ -138,7 +159,7 @@
#### [v0.0.6](https://github.com/node-ebics/node-ebics-client/compare/v0.0.5...v0.0.6)
> 24 July 2019
> 7 November 2019
- remove eCollect from constant and minor verbose error handaling [`#4`](https://github.com/node-ebics/node-ebics-client/pull/4)
- add iso pain format XCT order type [`#5`](https://github.com/node-ebics/node-ebics-client/pull/5)
@@ -148,24 +169,24 @@
#### [v0.0.5](https://github.com/node-ebics/node-ebics-client/compare/v0.0.4...v0.0.5)
> 28 June 2019
> 7 November 2019
- Fix parsing of the bank keys in the HPB response [`#3`](https://github.com/node-ebics/node-ebics-client/pull/3)
- tc for bank keys parsing error [`c571ef1`](https://github.com/node-ebics/node-ebics-client/commit/c571ef181bca2e0cbec70bc6df53c706acd6c829)
- #2 corrected bank keys parsing [`5f0b6cd`](https://github.com/node-ebics/node-ebics-client/commit/5f0b6cd3747c4613920d2f71f3c04ce13225d397)
#### [v0.0.4](https://github.com/node-ebics/node-ebics-client/compare/v0.0.36...v0.0.4)
#### [v0.0.4](https://github.com/node-ebics/node-ebics-client/compare/v0.0.3...v0.0.4)
> 3 September 2018
- Major changes. Separating responsibilities. Orders builder, serializer. [`ff9a3a1`](https://github.com/node-ebics/node-ebics-client/commit/ff9a3a16b47d0a25674134c875bfd651995837e4)
- code optimization [`1876360`](https://github.com/node-ebics/node-ebics-client/commit/187636019c290d757aca77d4c14fb4f2519acd38)
- client and order optimization [`9454992`](https://github.com/node-ebics/node-ebics-client/commit/945499290a8698aed504b573019de2c23148006a)
- various modular fixes [`8492d94`](https://github.com/node-ebics/node-ebics-client/commit/8492d940542f61b17aa3a2da7de23f6539ffaad5)
#### v0.0.3
> 17 May 2018
> 7 November 2019
- initial commit [`1f947ff`](https://github.com/node-ebics/node-ebics-client/commit/1f947ff1480c522f89fa1f547581b55e2378d920)
- Initial commit [`cd37de3`](https://github.com/node-ebics/node-ebics-client/commit/cd37de3895e32a61798c79ce3a6447e2f269019d)

View File

@@ -1,6 +1,6 @@
'use strict';
const $request = require('request');
const rock = require('rock-req');
const constants = require('./consts');
const Keys = require('./keymanagers/Keys');
@@ -52,7 +52,6 @@ const stringifyKeys = (keys) => {
* @property {string} storageLocation - Location where to store the files that are downloaded. This can be a network share for example.
*/
module.exports = class Client {
/**
*Creates an instance of Client.
@@ -71,18 +70,17 @@ module.exports = class Client {
languageCode,
storageLocation,
}) {
if (!url)
throw new Error('EBICS URL is required');
if (!partnerId)
throw new Error('partnerId is required');
if (!userId)
throw new Error('userId is required');
if (!hostId)
throw new Error('hostId is required');
if (!passphrase)
throw new Error('passphrase is required');
if (!url) throw new Error('EBICS URL is required');
if (!partnerId) throw new Error('partnerId is required');
if (!userId) throw new Error('userId is required');
if (!hostId) throw new Error('hostId is required');
if (!passphrase) throw new Error('passphrase is required');
if (!keyStorage || typeof keyStorage.read !== 'function' || typeof keyStorage.write !== 'function')
if (
!keyStorage
|| typeof keyStorage.read !== 'function'
|| typeof keyStorage.write !== 'function'
)
throw new Error('keyStorage implementation missing or wrong');
this.url = url;
@@ -99,17 +97,25 @@ module.exports = class Client {
}
async send(order) {
const isInObject = ('operation' in order);
const isInObject = 'operation' in order;
if (!isInObject) throw new Error('Operation for the order needed');
if (order.operation.toUpperCase() === constants.orderOperations.ini) return this.initialization(order);
if (order.operation.toUpperCase() === constants.orderOperations.ini)
return this.initialization(order);
const keys = await this.keys();
if (keys === null) throw new Error('No keys provided. Can not send the order or any other order for that matter.');
if (keys === null)
throw new Error(
'No keys provided. Can not send the order or any other order for that matter.',
);
if (order.operation.toUpperCase() === constants.orderOperations.upload) return this.upload(order);
if (order.operation.toUpperCase() === constants.orderOperations.download) return this.download(order);
if (order.operation.toUpperCase() === constants.orderOperations.upload)
return this.upload(order);
if (
order.operation.toUpperCase() === constants.orderOperations.download
)
return this.download(order);
throw new Error('Wrong order operation provided');
}
@@ -118,8 +124,7 @@ module.exports = class Client {
const keys = await this.keys();
if (keys === null) await this._generateKeys();
if (this.tracesStorage)
this.tracesStorage.new().ofType('ORDER.INI');
if (this.tracesStorage) this.tracesStorage.new().ofType('ORDER.INI');
const res = await this.ebicsRequest(order);
const xml = res.orderData();
@@ -132,7 +137,9 @@ module.exports = class Client {
technicalCode: returnedTechnicalCode,
technicalCodeSymbol: res.technicalSymbol(),
technicalCodeShortText: res.technicalShortText(returnedTechnicalCode),
technicalCodeShortText: res.technicalShortText(
returnedTechnicalCode,
),
technicalCodeMeaning: res.technicalMeaning(returnedTechnicalCode),
businessCode: returnedBusinessCode,
@@ -167,7 +174,9 @@ module.exports = class Client {
technicalCode: returnedTechnicalCode,
technicalCodeSymbol: res.technicalSymbol(),
technicalCodeShortText: res.technicalShortText(returnedTechnicalCode),
technicalCodeShortText: res.technicalShortText(
returnedTechnicalCode,
),
technicalCodeMeaning: res.technicalMeaning(returnedTechnicalCode),
businessCode: returnedBusinessCode,
@@ -178,8 +187,7 @@ module.exports = class Client {
}
async upload(order) {
if (this.tracesStorage)
this.tracesStorage.new().ofType('ORDER.UPLOAD');
if (this.tracesStorage) this.tracesStorage.new().ofType('ORDER.UPLOAD');
let res = await this.ebicsRequest(order);
const transactionId = res.transactionId();
const orderId = res.orderId();
@@ -197,32 +205,46 @@ module.exports = class Client {
return new Promise(async (resolve, reject) => {
const { version } = order;
const keys = await this.keys();
const r = signer.version(version).sign((await serializer.use(order, this)).toXML(), keys.x());
const r = signer
.version(version)
.sign((await serializer.use(order, this)).toXML(), keys.x());
if (this.tracesStorage)
this.tracesStorage.label(`REQUEST.${order.orderDetails.OrderType}`).data(r).persist();
this.tracesStorage
.label(`REQUEST.${order.orderDetails.OrderType}`)
.data(r)
.persist();
$request.post({
url: this.url,
body: r,
headers: { 'content-type': 'text/xml;charset=UTF-8' },
}, (err, res, data) => {
if (err) reject(err);
rock({
method: 'POST',
url: this.url,
body: r,
headers: { 'content-type': 'text/xml;charset=UTF-8' },
},
(err, res, data) => {
if (err) reject(err);
const ebicsResponse = response.version(version)(data, keys);
const ebicsResponse = response.version(version)(data, keys);
if (this.tracesStorage)
this.tracesStorage.label(`RESPONSE.${order.orderDetails.OrderType}`).connect().data(ebicsResponse.toXML()).persist();
if (this.tracesStorage)
this.tracesStorage
.label(`RESPONSE.${order.orderDetails.OrderType}`)
.connect()
.data(ebicsResponse.toXML())
.persist();
resolve(ebicsResponse);
});
resolve(ebicsResponse);
},
);
});
}
async signOrder(order) {
const { version } = order;
const keys = await this.keys();
return signer.version(version).sign((await serializer.use(order, this)).toXML(), keys.x());
return signer
.version(version)
.sign((await serializer.use(order, this)).toXML(), keys.x());
}
async keys() {
@@ -253,6 +275,8 @@ module.exports = class Client {
}
_writeKeys(keysObject) {
return this.keyStorage.write(this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)));
return this.keyStorage.write(
this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)),
);
}
};

View File

@@ -5,7 +5,7 @@ const crypto = require('crypto');
const Crypto = require('../../crypto/Crypto');
const { DOMParser, XMLSerializer } = require('xmldom');
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');
const xpath = require('xpath');
const errors = require('./errors');
@@ -25,45 +25,72 @@ module.exports = (xml, keys) => ({
isSegmented() {
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
const node = select('//xmlns:header/xmlns:mutable/xmlns:SegmentNumber', this.doc);
const node = select(
'//xmlns:header/xmlns:mutable/xmlns:SegmentNumber',
this.doc,
);
return !!node.length;
},
isLastSegment() {
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
const node = select("//xmlns:header/xmlns:mutable/*[@lastSegment='true']", this.doc);
const node = select(
"//xmlns:header/xmlns:mutable/*[@lastSegment='true']",
this.doc,
);
return !!node.length;
},
orderData() {
const orderDataNode = this.doc.getElementsByTagNameNS('urn:org:ebics:H004', 'OrderData');
const orderDataNode = this.doc.getElementsByTagNameNS(
'urn:org:ebics:H004',
'OrderData',
);
if (!orderDataNode.length) return {};
const orderData = orderDataNode[0].textContent;
const decipher = crypto.createDecipheriv('aes-128-cbc', this.transactionKey(), DEFAULT_IV).setAutoPadding(false);
const data = Buffer.from(decipher.update(orderData, 'base64', 'binary') + decipher.final('binary'), 'binary');
const decipher = crypto
.createDecipheriv('aes-128-cbc', this.transactionKey(), DEFAULT_IV)
.setAutoPadding(false);
const data = Buffer.from(
decipher.update(orderData, 'base64', 'binary')
+ decipher.final('binary'),
'binary',
);
return zlib.inflateSync(data);
},
transactionKey() {
const keyNodeText = this.doc.getElementsByTagNameNS('urn:org:ebics:H004', 'TransactionKey')[0].textContent;
return Crypto.privateDecrypt(this.keys.e(), Buffer.from(keyNodeText, 'base64'));
const keyNodeText = this.doc.getElementsByTagNameNS(
'urn:org:ebics:H004',
'TransactionKey',
)[0].textContent;
return Crypto.privateDecrypt(
this.keys.e(),
Buffer.from(keyNodeText, 'base64'),
);
},
transactionId() {
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
const node = select('//xmlns:header/xmlns:static/xmlns:TransactionID', this.doc);
const node = select(
'//xmlns:header/xmlns:static/xmlns:TransactionID',
this.doc,
);
return node.length ? node[0].textContent : '';
},
orderId() {
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
const node = select('.//xmlns:header/xmlns:mutable/xmlns:OrderID', this.doc);
const node = select(
'.//xmlns:header/xmlns:mutable/xmlns:OrderID',
this.doc,
);
return node.length ? node[0].textContent : '';
},
@@ -89,14 +116,20 @@ module.exports = (xml, keys) => ({
technicalCode() {
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
const node = select('//xmlns:header/xmlns:mutable/xmlns:ReturnCode', this.doc);
const node = select(
'//xmlns:header/xmlns:mutable/xmlns:ReturnCode',
this.doc,
);
return node.length ? node[0].textContent : '';
},
technicalSymbol() {
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
const node = select('//xmlns:header/xmlns:mutable/xmlns:ReportText', this.doc);
const node = select(
'//xmlns:header/xmlns:mutable/xmlns:ReportText',
this.doc,
);
return node.length ? node[0].textContent : '';
},
@@ -122,8 +155,14 @@ module.exports = (xml, keys) => ({
for (let i = 0; i < keyNodes.length; i++) {
const type = lastChild(keyNodes[i].parentNode).textContent;
const modulus = xpath.select(".//*[local-name(.)='Modulus']", keyNodes[i])[0].textContent;
const exponent = xpath.select(".//*[local-name(.)='Exponent']", keyNodes[i])[0].textContent;
const modulus = xpath.select(
".//*[local-name(.)='Modulus']",
keyNodes[i],
)[0].textContent;
const exponent = xpath.select(
".//*[local-name(.)='Exponent']",
keyNodes[i],
)[0].textContent;
const mod = Buffer.from(modulus, 'base64');
const exp = Buffer.from(exponent, 'base64');

View File

@@ -1,26 +1,32 @@
'use strict';
// const crypto = require('crypto');
const Crypto = require('../../crypto/Crypto');
const { DOMParser, XMLSerializer } = require('xmldom');
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');
const xpath = require('xpath');
const C14n = require('xml-crypto/lib/c14n-canonicalization').C14nCanonicalization;
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];
// 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;
};
@@ -29,8 +35,15 @@ const sign = (doc, key) => {
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');
}

8195
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "ebics-client",
"version": "0.2.1",
"version": "4.1.0",
"description": "Node.js ISO 20022 Compliant EBICS Client",
"main": "index.js",
"files": [
@@ -57,26 +57,26 @@
"url": "https://github.com/Herrie82"
}
],
"license": "GPL-3.0-only",
"license": "MIT",
"dependencies": {
"handlebars": "^4.7.7",
"js2xmlparser": "^4.0.1",
"node-forge": "^0.10.0",
"request": "^2.88.2",
"uuid": "^8.3.2",
"xml-crypto": "^2.1.1",
"xmldom": "^0.5.0",
"@xmldom/xmldom": "^0.8.10",
"handlebars": "^4.7.8",
"js2xmlparser": "^5.0.0",
"node-forge": "^1.3.1",
"rock-req": "^5.1.3",
"uuid": "^9.0.1",
"xml-crypto": "^6.0.0",
"xpath": "0.0.32"
},
"devDependencies": {
"auto-changelog": "^1.16.2",
"chai": "^4.3.4",
"coveralls": "^3.1.0",
"auto-changelog": "^2.4.0",
"chai": "^4.3.10",
"coveralls": "^3.1.1",
"eslint": "^6.7.2",
"eslint-config-ecollect-base": "^0.1.2",
"eslint-plugin-import": "^2.18.2",
"libxmljs": "^0.19.7",
"mocha": "^7.1.2",
"eslint-plugin-import": "^2.28.1",
"libxmljs": "^1.0.10",
"mocha": "^10.2.0",
"nyc": "^15.1.0"
}
}

View File

@@ -12,7 +12,9 @@ const ebics = require('../../');
const libxml = require('libxmljs');
const schemaPath = path.resolve(__dirname, '../xsd/ebics_H004.xsd');
const schemaDoc = libxml.parseXml(fs.readFileSync(schemaPath, { encoding: 'utf8' }));
const schemaDoc = libxml.parseXml(
fs.readFileSync(schemaPath, { encoding: 'utf8' }),
);
const schemaDir = path.dirname(schemaPath);
const cwd = process.cwd();
@@ -20,7 +22,7 @@ const cwd = process.cwd();
const validateXML = (str) => {
try {
process.chdir(schemaDir);
const isValid = libxml.parseXmlString(str).validate(schemaDoc);
const isValid = libxml.parseXml(str).validate(schemaDoc);
process.chdir(cwd);
return isValid;
} catch (e) {
@@ -35,7 +37,9 @@ const client = new ebics.Client({
userId: 'CRS04381',
hostId: 'CRSISOTB',
passphrase: 'test',
keyStorage: ebics.fsKeysStorage(path.resolve(__dirname, '../support/TEST_KEYS.key')),
keyStorage: ebics.fsKeysStorage(
path.resolve(__dirname, '../support/TEST_KEYS.key'),
),
});
const { Orders } = ebics;
@@ -83,10 +87,8 @@ const fnOrders = {
};
const getOrderObject = (name, order) => {
if (typeof order === 'object')
return order;
if (fnOrders[name])
return fnOrders[name](order);
if (typeof order === 'object') return order;
if (fnOrders[name]) return fnOrders[name](order);
return null;
};
@@ -94,8 +96,7 @@ describe('H004 order generation', () => {
// eslint-disable-next-line no-restricted-syntax
for (const [name, orderDefinition] of Object.entries(Orders)) {
const order = getOrderObject(name, orderDefinition);
if (!order)
continue;
if (!order) continue;
const type = order.orderDetails.OrderType;
const { operation } = order;