This commit is contained in:
Danny Coates 2017-06-29 10:30:08 -07:00
parent 05fe534e14
commit 67f586b65c
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
6 changed files with 40 additions and 32 deletions

View File

@ -1,8 +1,6 @@
const EventEmitter = require('events');
const { hexToArray } = require('./utils');
const Raven = window.Raven;
class FileReceiver extends EventEmitter {
constructor() {
super();
@ -34,7 +32,7 @@ class FileReceiver extends EventEmitter {
const blob = new Blob([this.response]);
const fileReader = new FileReader();
fileReader.onload = function() {
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'))
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
resolve({
data: this.result,
aad: meta.aad,

View File

@ -38,14 +38,18 @@ class FileSender extends EventEmitter {
upload() {
return Promise.all([
window.crypto.subtle.generateKey(
{
name: 'AES-GCM',
length: 128
},
true,
['encrypt', 'decrypt']
).catch(err => console.log('There was an error generating a crypto key')),
window.crypto.subtle
.generateKey(
{
name: 'AES-GCM',
length: 128
},
true,
['encrypt', 'decrypt']
)
.catch(err =>
console.log('There was an error generating a crypto key')
),
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsArrayBuffer(this.file);
@ -56,15 +60,17 @@ class FileSender extends EventEmitter {
])
.then(([secretKey, plaintext]) => {
return Promise.all([
window.crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv: this.iv,
additionalData: this.aad
},
secretKey,
plaintext
).catch(err => console.log('Error with encrypting.')),
window.crypto.subtle
.encrypt(
{
name: 'AES-GCM',
iv: this.iv,
additionalData: this.aad
},
secretKey,
plaintext
)
.catch(err => console.log('Error with encrypting.')),
window.crypto.subtle.exportKey('jwk', secretKey)
]);
})
@ -100,7 +106,14 @@ class FileSender extends EventEmitter {
};
xhr.open('post', '/upload/' + fileId, true);
xhr.setRequestHeader('X-File-Metadata', JSON.stringify({ aad: arrayToHex(this.aad), iv: fileId, filename: file.name }))
xhr.setRequestHeader(
'X-File-Metadata',
JSON.stringify({
aad: arrayToHex(this.aad),
iv: fileId,
filename: file.name
})
);
xhr.send(fd);
});
})

View File

@ -20,7 +20,6 @@ function hexToArray(str) {
return iv;
}
function notify(str) {
if (!('Notification' in window)) {
return;

View File

@ -1,6 +1,6 @@
const conf = require('./config.js');
const isProduction = conf.env === 'production'
const isProduction = conf.env === 'production';
const mozlog = require('mozlog')({
app: 'FirefoxFileshare',

View File

@ -78,10 +78,10 @@ app.get('/assets/download/:id', (req, res) => {
return;
}
storage.metadata(id)
storage
.metadata(id)
.then(meta => {
storage.length(id).then(contentLength => {
res.writeHead(200, {
'Content-Disposition': 'attachment; filename=' + meta.filename,
'Content-Type': 'application/octet-stream',
@ -142,7 +142,7 @@ app.post('/upload/:id', (req, res, next) => {
return;
}
const meta = JSON.parse(req.header('X-File-Metadata'));
log.info('meta', meta)
log.info('meta', meta);
req.pipe(req.busboy);
req.busboy.on('file', (fieldname, file, filename) => {
@ -157,8 +157,6 @@ app.post('/upload/:id', (req, res, next) => {
});
});
});
});
app.get('/__lbheartbeat__', (req, res) => {

View File

@ -58,8 +58,8 @@ function metadata(id) {
} else {
reject(err);
}
})
})
});
});
}
function filename(id) {
@ -98,8 +98,8 @@ function aad(id) {
} else {
reject();
}
})
})
});
});
}
function localLength(id) {