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 EventEmitter = require('events');
const { hexToArray } = require('./utils'); const { hexToArray } = require('./utils');
const Raven = window.Raven;
class FileReceiver extends EventEmitter { class FileReceiver extends EventEmitter {
constructor() { constructor() {
super(); super();
@ -34,7 +32,7 @@ class FileReceiver extends EventEmitter {
const blob = new Blob([this.response]); const blob = new Blob([this.response]);
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,

View File

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

View File

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

View File

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

View File

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

View File

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