Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
verification errors
Browse files Browse the repository at this point in the history
  • Loading branch information
janfabian committed Apr 23, 2020
1 parent 328f205 commit 0d6a24c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@topmonks/csob-paymentgate",
"version": "0.2.0",
"version": "0.2.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion payment/config/v1.8.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const testConfig = {
csobPublicKey: fs.readFileSync(
path.resolve(
__dirname,
"../../paymentgateway/keys/mips_platebnibrana.csob.cz.pub"
"../../paymentgateway/keys/mips_iplatebnibrana.csob.cz.pub"
),
{ encoding: "utf8" }
),
Expand Down
29 changes: 28 additions & 1 deletion payment/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ const sign = (text, privateKey, hashFn, encoding) => {
return signer.sign(privateKey, encoding);
};

class VERIFICATION_ERROR extends Error {
constructor(message) {
super(message);

this.name = this.constructor.name;
this.status = 400;
}

statusCode() {
return this.status;
}
}

const verify = (text, signature, publicKey, hashFn, encoding) => {
const verifier = crypto.createVerify(hashFn);
verifier.update(text);
Expand All @@ -29,7 +42,21 @@ const verifyResponse = (
optional: [...optional, noPayId ? "payId" : undefined],
});

return verify(text, response.signature, csobPublicKey, hashFn, encoding);
const verification = verify(
text,
response.signature,
csobPublicKey,
hashFn,
encoding
);

if (!verification) {
throw new VERIFICATION_ERROR(
"CSOB response signature verification failed."
);
}

return verification;
};

const dttm = () => moment().format("YYYYMMDDHHmmss");
Expand Down

0 comments on commit 0d6a24c

Please sign in to comment.