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

Changed HMAC library from sodium to crypto #208

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Message: {"context":{"domain":"retail","action":"search","bap_id":"retail.bap","

Shared Key: juWDOTzzK7Eyrzm6hZwQmlJkolesm8x0

HMAC: HMAC-SHA-256 8d2b129d83512b53ddd6e3657748a2e22cd05de3f7c4780cdf39da564a843884
HMAC: HMAC-SHA-256 287662f35c63bb66710d96749ea87b5a8fa8073f919c8da628451a3c8567a1ff
```


Expand Down
9 changes: 4 additions & 5 deletions src/utils/auth.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _sodium, { base64_variants } from "libsodium-wrappers";
import * as crypto from 'crypto';
import { writeFile } from "fs/promises";
import logger from "./logger.utils";
import { Request, Response } from "express";
Expand Down Expand Up @@ -210,12 +211,10 @@ export const createAuthHeaderConfig = async (request: any) => {
};

const createBppWebhookAuthHeader = async (request: any) => {
const sodium = _sodium;
const key = getConfig().app.sharedKeyForWebhookHMAC || "";
const keyUint8Array = sodium.from_string(key);
const messageUint8Array = sodium.from_string(JSON.stringify(request));
const hmac = sodium.crypto_auth(messageUint8Array, keyUint8Array);
return sodium.to_hex(hmac);
const hmac = crypto.createHmac('sha256', key);
hmac.update(JSON.stringify(request));
return hmac.digest('hex');
};

export const createBppWebhookAuthHeaderConfig = async (request: any) => {
Expand Down
Loading