Merge pull request #412 from mozilla/i151
throw key errors before download begins
This commit is contained in:
commit
434f8b56cc
1 changed files with 41 additions and 37 deletions
|
@ -7,8 +7,23 @@ class FileReceiver extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
return Promise.all([
|
return window.crypto.subtle
|
||||||
new Promise((resolve, reject) => {
|
.importKey(
|
||||||
|
'jwk',
|
||||||
|
{
|
||||||
|
kty: 'oct',
|
||||||
|
k: location.hash.slice(1),
|
||||||
|
alg: 'A128GCM',
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'AES-GCM'
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
['encrypt', 'decrypt']
|
||||||
|
)
|
||||||
|
.then(key => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
xhr.onprogress = event => {
|
xhr.onprogress = event => {
|
||||||
|
@ -27,12 +42,15 @@ class FileReceiver extends EventEmitter {
|
||||||
const fileReader = new FileReader();
|
const fileReader = new FileReader();
|
||||||
fileReader.onload = function() {
|
fileReader.onload = function() {
|
||||||
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
||||||
resolve({
|
resolve([
|
||||||
|
{
|
||||||
data: this.result,
|
data: this.result,
|
||||||
aad: meta.aad,
|
aad: meta.aad,
|
||||||
filename: meta.filename,
|
filename: meta.filename,
|
||||||
iv: meta.id
|
iv: meta.id
|
||||||
});
|
},
|
||||||
|
key
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
fileReader.readAsArrayBuffer(blob);
|
fileReader.readAsArrayBuffer(blob);
|
||||||
|
@ -41,22 +59,8 @@ class FileReceiver extends EventEmitter {
|
||||||
xhr.open('get', '/assets' + location.pathname.slice(0, -1), true);
|
xhr.open('get', '/assets' + location.pathname.slice(0, -1), true);
|
||||||
xhr.responseType = 'blob';
|
xhr.responseType = 'blob';
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}),
|
});
|
||||||
window.crypto.subtle.importKey(
|
})
|
||||||
'jwk',
|
|
||||||
{
|
|
||||||
kty: 'oct',
|
|
||||||
k: location.hash.slice(1),
|
|
||||||
alg: 'A128GCM',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AES-GCM'
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
['encrypt', 'decrypt']
|
|
||||||
)
|
|
||||||
])
|
|
||||||
.then(([fdata, key]) => {
|
.then(([fdata, key]) => {
|
||||||
this.emit('decrypting', true);
|
this.emit('decrypting', true);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
|
Loading…
Reference in a new issue