From 89bc51c821728d1f8f4bddc9d751f9a1aadc3d0e Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Thu, 13 Jul 2017 09:53:59 -0700 Subject: [PATCH] added unsafe and safe events instead of console logging when a checksum is tampered with --- frontend/src/fileReceiver.js | 21 +++++++++++---------- test/frontend/frontend.test.js | 12 ++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/frontend/src/fileReceiver.js b/frontend/src/fileReceiver.js index 0404bda8..3a4931da 100644 --- a/frontend/src/fileReceiver.js +++ b/frontend/src/fileReceiver.js @@ -91,20 +91,21 @@ class FileReceiver extends EventEmitter { this.emit('hashing', false); const integrity = new Uint8Array(calculatedHash).toString() === proposedHash.toString(); if (!integrity) { + this.emit('unsafe', true) return new Promise((resolve, reject) => { - console.log('This file has been tampered with.') reject(); }) + } else { + this.emit('safe', true); + return Promise.all([ + new Promise((resolve, reject) => { + resolve(decrypted); + }), + new Promise((resolve, reject) => { + resolve(fname); + }) + ]); } - - return Promise.all([ - new Promise((resolve, reject) => { - resolve(decrypted); - }), - new Promise((resolve, reject) => { - resolve(fname); - }) - ]); }) }) } diff --git a/test/frontend/frontend.test.js b/test/frontend/frontend.test.js index ff7441d6..2ec69bf3 100644 --- a/test/frontend/frontend.test.js +++ b/test/frontend/frontend.test.js @@ -235,6 +235,10 @@ describe('File Receiver', function() { testDecrypting = isStillDecrypting; }); + fr.on('safe', isSafe => { + assert(isSafe); + }) + return fr.download().then(([decrypted, name]) => { assert(decrypted); assert(name); @@ -256,6 +260,10 @@ describe('File Receiver', function() { testHashing = isStillHashing; }); + fr.on('safe', isSafe => { + assert(isSafe); + }) + return fr.download().then(([decrypted, name]) => { assert(decrypted); assert(name); @@ -305,6 +313,10 @@ describe('File Receiver', function() { const fr = new FileReceiver(); location.hash = secretKey; + fr.on('unsafe', isUnsafe => { + assert(isUnsafe) + }) + fr.download().then(() => { assert.fail(); done();