You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
685 B

11 months ago
  1. const { CommunicationKey } = require("../utils/comKey");
  2. function verifyPayloadIntegrity(request, response, next) {
  3. const comKey = new CommunicationKey();
  4. if (process.env.NODE_ENV === "development") {
  5. comKey.log('verifyPayloadIntegrity is skipped in development.')
  6. next();
  7. return;
  8. }
  9. const signature = request.header("X-Integrity");
  10. if (!signature) return response.status(400).json({ msg: 'Failed integrity signature check.' })
  11. const validSignedPayload = comKey.verify(signature, request.body);
  12. if (!validSignedPayload) return response.status(400).json({ msg: 'Failed integrity signature check.' })
  13. next();
  14. }
  15. module.exports = {
  16. verifyPayloadIntegrity
  17. }