Skip to content

Commit 9812dcd

Browse files
author
Paul Naszalyi
committed
Improve debug signatures
1 parent bc2f8fa commit 9812dcd

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/api/controllers/file.controller.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ const streamToBuffer = (stream: PassThrough): Promise<Buffer> => {
2121
});
2222
};
2323

24-
const checkSignature = async (file: FileProps, stream: PassThrough): Promise<boolean> => {
24+
const checkSignature = async (file: FileProps, stream: PassThrough): Promise<{isValidSignature: boolean; originSignature: string | null}> => {
2525
try {
2626
const buffer = await streamToBuffer(stream);
2727
const signature = calculateSHA256(buffer);
28-
return file.signature === signature;
28+
return {
29+
isValidSignature: file.signature === signature,
30+
originSignature: signature
31+
};
2932
} catch (error) {
3033
logger.error('Error checking signature:', error);
31-
return false;
34+
return {
35+
isValidSignature: false,
36+
originSignature: null
37+
}
3238
}
3339
};
3440

@@ -67,9 +73,10 @@ export const getAsset = async (req: Request, res: Response & { locals: Locals })
6773
return res.status(500).end();
6874
});
6975

70-
const isValidSignature = await checkSignature(item, streamForSignature);
76+
const { isValidSignature, originSignature } = await checkSignature(item, streamForSignature);
7177

7278
if (!isValidSignature) {
79+
logger.error(`Invalid signatures (catalog: ${item.signature}, origin: ${originSignature})`);
7380
return res.status(418).end();
7481
}
7582

0 commit comments

Comments
 (0)