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

adding debug logs for hmac secret verification of /savekey endpoint #148

Merged
merged 2 commits into from
Nov 21, 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 backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arka",
"version": "1.6.7",
"version": "1.6.8",
"description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software",
"type": "module",
"directories": {
Expand Down
7 changes: 7 additions & 0 deletions backend/src/routes/admin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
const privateKey = wallet.privateKey;
const publicAddress = await wallet.getAddress();

request.log.info(`-----------headers---------- ${JSON.stringify(request.headers)}`);
request.log.info(`-----------hmac secret---------- ${server.config.HMAC_SECRET}`);


if(!unsafeMode) {
const { 'x-signature': signature, 'x-timestamp': timestamp } = request.headers as IncomingHttpHeaders & AuthDto;
request.log.info(`-----------signature---------- ${signature}`);
request.log.info(`-----------timestamp---------- ${timestamp}`);

if(!signature || !timestamp)
return reply.code(ReturnCode.NOT_AUTHORIZED).send({ error: ErrorMessage.INVALID_SIGNATURE_OR_TIMESTAMP });
if(!verifySignature(signature, request.body as string, timestamp, server.config.HMAC_SECRET))
Expand Down
6 changes: 5 additions & 1 deletion backend/src/utils/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto, { BinaryToTextEncoding } from 'crypto';
import { KmsKeyringNode, buildClient, CommitmentPolicy } from '@aws-crypto/client-node';
import { server } from 'server';

function createDigest(encodedData: string, format: BinaryToTextEncoding, hmacSecret: string) {
return crypto
Expand Down Expand Up @@ -65,13 +66,16 @@ export async function decodeSafe(value: string, hmacSecret: string) {
export function verifySignature(signature: string, data: string, timestamp: string, hmacSecret: string) {
// unauthorize signature if signed before 10s or signed in future.
const now = Date.now();
server.log.info(`-----------now---------- ${now}`);
server.log.info(`-----------hmacSecret---------- ${hmacSecret}`);
if(
now < parseInt(timestamp) ||
now - parseInt(timestamp) > 10000
) {
return false;
}
const computedSignature = createDigest(data + timestamp, 'hex', hmacSecret);

server.log.info(`-----------computedSignature----------${computedSignature}`);
server.log.info(`-----------signature----------${signature} ${computedSignature === signature}`);
return signature === computedSignature;
}
Loading