Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #193 from mozilla/frontend_tests
Browse files Browse the repository at this point in the history
Frontend tests
  • Loading branch information
abhinadduri authored Jul 17, 2017
2 parents 6970e92 + b88cf22 commit 4122f4d
Show file tree
Hide file tree
Showing 12 changed files with 1,058 additions and 2,512 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
public/bundle.js
public/webcrypto-shim.js
test/frontend/bundle.js
firefox
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ public/bundle.js
public/version.json
static/*
!static/info.txt
test/frontend/bundle.js
7 changes: 7 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ machine:
services:
- docker
- redis
environment:
PATH: "/home/ubuntu/send/firefox:$PATH"

dependencies:
pre:
- npm i -g get-firefox geckodriver
- get-firefox --platform linux --extract --target /home/ubuntu/send

deployment:
latest:
Expand Down
88 changes: 34 additions & 54 deletions frontend/src/fileReceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,61 +58,41 @@ class FileReceiver extends EventEmitter {
true,
['encrypt', 'decrypt']
)
])
.then(([fdata, key]) => {
this.emit('decrypting', true);
return Promise.all([
window.crypto.subtle
.decrypt(
{
name: 'AES-GCM',
iv: hexToArray(fdata.iv),
additionalData: hexToArray(fdata.aad),
tagLength: 128
},
key,
fdata.data
)
.then(decrypted => {
this.emit('decrypting', false);
return new Promise((resolve, reject) => {
resolve(decrypted);
});
}),
new Promise((resolve, reject) => {
resolve(fdata.filename);
}),
new Promise((resolve, reject) => {
resolve(hexToArray(fdata.aad));
})
]);
]).then(([fdata, key]) => {
this.emit('decrypting', true);
return Promise.all([
window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: hexToArray(fdata.iv),
additionalData: hexToArray(fdata.aad)
},
key,
fdata.data
).then(decrypted => {
this.emit('decrypting', false);
return Promise.resolve(decrypted)
}),
fdata.filename,
hexToArray(fdata.aad)
]);
}).then(([decrypted, fname, proposedHash]) => {
this.emit('hashing', true);
return window.crypto.subtle.digest('SHA-256', decrypted).then(calculatedHash => {
this.emit('hashing', false);
const integrity = new Uint8Array(calculatedHash).toString() === proposedHash.toString();
if (!integrity) {
this.emit('unsafe', true)
return Promise.reject();
} else {
this.emit('safe', true);
return Promise.all([
decrypted,
fname
]);
}
})
.then(([decrypted, fname, proposedHash]) => {
this.emit('hashing', true);
return window.crypto.subtle
.digest('SHA-256', decrypted)
.then(calculatedHash => {
this.emit('hashing', false);
const integrity =
new Uint8Array(calculatedHash).toString() ===
proposedHash.toString();
if (!integrity) {
return new Promise((resolve, reject) => {
console.log('This file has been tampered with.');
reject();
});
}

return Promise.all([
new Promise((resolve, reject) => {
resolve(decrypted);
}),
new Promise((resolve, reject) => {
resolve(fname);
})
]);
});
});
})
}
}

Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function arrayToHex(iv) {
hexStr += iv[i].toString(16);
}
}
window.hexStr = hexStr;
return hexStr;
}

Expand Down
Loading

0 comments on commit 4122f4d

Please sign in to comment.