removed references to checksums in frontend tests

This commit is contained in:
Abhinav Adduri 2017-08-07 14:58:22 -07:00
parent 5844a9a03c
commit 4db7fc6db3
3 changed files with 295 additions and 2128 deletions

2200
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ const driver = new webdriver.Builder().forBrowser('firefox').build();
driver.get(path.join('file:///', __dirname, '/frontend.test.html')); driver.get(path.join('file:///', __dirname, '/frontend.test.html'));
driver.wait(until.titleIs('Mocha Tests')); driver.wait(until.titleIs('Mocha Tests'));
driver.wait(until.titleMatches(/^[0-1]$/)); driver.wait(until.titleMatches(/^[0-9]$/));
driver.getTitle().then(title => { driver.getTitle().then(title => {
driver.quit().then(() => { driver.quit().then(() => {

View File

@ -9,7 +9,6 @@ const sinon = window.sinon;
let file; let file;
let encryptedIV; let encryptedIV;
let fileHash;
let secretKey; let secretKey;
let originalBlob; let originalBlob;
@ -59,28 +58,6 @@ describe('File Sender', function() {
}); });
}); });
it('Should get a hashing event emission', function() {
const file = new FakeFile('hello_world.txt', ['This is some data.']);
const fs = new FileSender(file);
let testHashing = true;
fs.on('hashing', isStillHashing => {
assert(!(!testHashing && isStillHashing));
testHashing = isStillHashing;
});
return fs
.upload()
.then(info => {
assert(info);
assert(!testHashing);
})
.catch(err => {
console.log(err, err.stack);
assert.fail();
});
});
it('Should get a encrypting event emission', function() { it('Should get a encrypting event emission', function() {
const file = new FakeFile('hello_world.txt', ['This is some data.']); const file = new FakeFile('hello_world.txt', ['This is some data.']);
const fs = new FileSender(file); const fs = new FileSender(file);
@ -116,45 +93,40 @@ describe('File Sender', function() {
readRaw.onload = function(event) { readRaw.onload = function(event) {
const rawArray = new Uint8Array(this.result); const rawArray = new Uint8Array(this.result);
originalBlob = rawArray; originalBlob = rawArray;
window.crypto.subtle
window.crypto.subtle.digest('SHA-256', rawArray).then(hash => { .importKey(
fileHash = hash; 'jwk',
window.crypto.subtle {
.importKey( kty: 'oct',
'jwk', k: key,
{ alg: 'A128GCM',
kty: 'oct', ext: true
k: key, },
alg: 'A128GCM', {
ext: true name: 'AES-GCM'
}, },
{ true,
name: 'AES-GCM' ['encrypt', 'decrypt']
}, )
true, .then(cryptoKey => {
['encrypt', 'decrypt'] window.crypto.subtle
) .encrypt(
.then(cryptoKey => { {
window.crypto.subtle name: 'AES-GCM',
.encrypt( iv: hexToArray(IV),
{ tagLength: 128
name: 'AES-GCM', },
iv: hexToArray(IV), cryptoKey,
additionalData: hash, rawArray
tagLength: 128 )
}, .then(encrypted => {
cryptoKey, assert(
rawArray new Uint8Array(encrypted).toString() ===
) new Uint8Array(file).toString()
.then(encrypted => { );
assert( done();
new Uint8Array(encrypted).toString() === });
new Uint8Array(file).toString() });
);
done();
});
});
});
}; };
readRaw.readAsArrayBuffer(newFile); readRaw.readAsArrayBuffer(newFile);
@ -179,7 +151,6 @@ describe('File Receiver', function() {
FakeXHR.prototype.getResponseHeader = function() { FakeXHR.prototype.getResponseHeader = function() {
return JSON.stringify({ return JSON.stringify({
aad: arrayToHex(new Uint8Array(fileHash)),
filename: 'hello_world.txt', filename: 'hello_world.txt',
id: encryptedIV id: encryptedIV
}); });
@ -198,7 +169,6 @@ describe('File Receiver', function() {
if ( if (
file === undefined || file === undefined ||
encryptedIV === undefined || encryptedIV === undefined ||
fileHash === undefined ||
secretKey === undefined secretKey === undefined
) { ) {
assert.fail( assert.fail(
@ -246,10 +216,6 @@ describe('File Receiver', function() {
testDecrypting = isStillDecrypting; testDecrypting = isStillDecrypting;
}); });
fr.on('safe', isSafe => {
assert(isSafe);
});
return fr return fr
.download() .download()
.then(([decrypted, name]) => { .then(([decrypted, name]) => {
@ -262,123 +228,4 @@ describe('File Receiver', function() {
assert.fail(); assert.fail();
}); });
}); });
it('Should emit hashing events', function() {
const fr = new FileReceiver();
location.hash = secretKey;
let testHashing = true;
fr.on('hashing', isStillHashing => {
assert(!(!testHashing && isStillHashing));
testHashing = isStillHashing;
});
fr.on('safe', isSafe => {
assert(isSafe);
});
return fr
.download()
.then(([decrypted, name]) => {
assert(decrypted);
assert(name);
assert(!testHashing);
})
.catch(err => {
assert.fail();
});
});
it('Should catch fraudulent checksums', function(done) {
// Use the secret key and file hash of the previous file to encrypt,
// which has a different hash than this one (different strings).
const newFile = new FakeFile('hello_world.txt', [
'This is some data, with a changed hash.'
]);
const readRaw = new FileReader();
readRaw.onload = function(event) {
const plaintext = new Uint8Array(this.result);
window.crypto.subtle
.importKey(
'jwk',
{
kty: 'oct',
k: secretKey,
alg: 'A128GCM',
ext: true
},
{
name: 'AES-GCM'
},
true,
['encrypt', 'decrypt']
)
.then(key => {
// The file hash used here is the hash of the fake
// file from the previous test; it's a phony checksum.
return window.crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv: hexToArray(encryptedIV),
additionalData: fileHash,
tagLength: 128
},
key,
plaintext
);
})
.then(encrypted => {
file = encrypted;
const fr = new FileReceiver();
location.hash = secretKey;
fr.on('unsafe', isUnsafe => {
assert(isUnsafe);
});
fr.on('safe', () => {
// This event should not be emitted.
assert.fail();
});
fr
.download()
.then(() => {
assert.fail();
done();
})
.catch(err => {
assert(1);
done();
});
});
};
readRaw.readAsArrayBuffer(newFile);
});
it('Should not decrypt with an incorrect checksum', function() {
FakeXHR.prototype.getResponseHeader = function() {
return JSON.stringify({
aad: 'some_bad_hashz',
filename: 'hello_world.txt',
id: encryptedIV
});
};
const fr = new FileReceiver();
location.hash = secretKey;
return fr
.download()
.then(([decrypted, name]) => {
assert(decrypted);
assert(name);
assert.fail();
})
.catch(err => {
assert(1);
});
});
}); });