sender no longer needs file nonce

This commit is contained in:
Danny Coates 2018-01-31 11:12:36 -08:00
parent 545da556d2
commit 4fb4041f13
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
5 changed files with 20 additions and 28 deletions

View File

@ -98,7 +98,7 @@ export default function(state, emitter) {
await delay(200); await delay(200);
try { try {
metrics.startedUpload({ size, type }); metrics.startedUpload({ size, type });
const ownedFile = await sender.upload(state.storage); const ownedFile = await sender.upload();
state.storage.totalUploads += 1; state.storage.totalUploads += 1;
metrics.completedUpload(ownedFile); metrics.completedUpload(ownedFile);

View File

@ -49,7 +49,7 @@ export default class FileSender extends Nanobus {
}); });
} }
async upload(storage) { async upload() {
const start = Date.now(); const start = Date.now();
const plaintext = await this.readFile(); const plaintext = await this.readFile();
if (this.cancelled) { if (this.cancelled) {
@ -81,23 +81,20 @@ export default class FileSender extends Nanobus {
this.uploadRequest = null; this.uploadRequest = null;
this.progress = [1, 1]; this.progress = [1, 1];
const secretKey = arrayToB64(this.keychain.rawSecret); const secretKey = arrayToB64(this.keychain.rawSecret);
const ownedFile = new OwnedFile( const ownedFile = new OwnedFile({
{ id: result.id,
id: result.id, url: `${result.url}#${secretKey}`,
url: `${result.url}#${secretKey}`, name: this.file.name,
name: this.file.name, size: this.file.size,
size: this.file.size, type: this.file.type, //TODO 'click' ?
type: this.file.type, //TODO 'click' ? time: time,
time: time, speed: this.file.size / (time / 1000),
speed: this.file.size / (time / 1000), createdAt: Date.now(),
createdAt: Date.now(), expiresAt: Date.now() + EXPIRE_SECONDS * 1000,
expiresAt: Date.now() + EXPIRE_SECONDS * 1000, secretKey: secretKey,
secretKey: secretKey, nonce: this.keychain.nonce,
nonce: this.keychain.nonce, ownerToken: result.ownerToken
ownerToken: result.ownerToken });
},
storage
);
return ownedFile; return ownedFile;
} catch (e) { } catch (e) {
this.msg = 'errorPageHeader'; this.msg = 'errorPageHeader';

View File

@ -1,12 +1,10 @@
import Nanobus from 'nanobus';
import { arrayToB64, b64ToArray } from './utils'; import { arrayToB64, b64ToArray } from './utils';
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const decoder = new TextDecoder(); const decoder = new TextDecoder();
export default class Keychain extends Nanobus { export default class Keychain {
constructor(secretKeyB64, nonce, ivB64) { constructor(secretKeyB64, nonce, ivB64) {
super('Keychain');
this._nonce = nonce || 'yRCdyQ1EMSA3mo4rqSkuNQ=='; this._nonce = nonce || 'yRCdyQ1EMSA3mo4rqSkuNQ==';
if (ivB64) { if (ivB64) {
this.iv = b64ToArray(ivB64); this.iv = b64ToArray(ivB64);
@ -85,7 +83,6 @@ export default class Keychain extends Nanobus {
set nonce(n) { set nonce(n) {
if (n && n !== this._nonce) { if (n && n !== this._nonce) {
this._nonce = n; this._nonce = n;
this.emit('nonceChanged');
} }
} }

View File

@ -3,7 +3,7 @@ import { arrayToB64 } from './utils';
import { del, fileInfo, setParams, setPassword } from './api'; import { del, fileInfo, setParams, setPassword } from './api';
export default class OwnedFile { export default class OwnedFile {
constructor(obj, storage) { constructor(obj) {
this.id = obj.id; this.id = obj.id;
this.url = obj.url; this.url = obj.url;
this.name = obj.name; this.name = obj.name;
@ -16,8 +16,7 @@ export default class OwnedFile {
this.ownerToken = obj.ownerToken; this.ownerToken = obj.ownerToken;
this.dlimit = obj.dlimit || 1; this.dlimit = obj.dlimit || 1;
this.dtotal = obj.dtotal || 0; this.dtotal = obj.dtotal || 0;
this.keychain = new Keychain(obj.secretKey, obj.nonce); this.keychain = new Keychain(obj.secretKey);
this.keychain.on('nonceChanged', () => storage.writeFile(this));
this._hasPassword = !!obj.hasPassword; this._hasPassword = !!obj.hasPassword;
} }
@ -69,7 +68,6 @@ export default class OwnedFile {
createdAt: this.createdAt, createdAt: this.createdAt,
expiresAt: this.expiresAt, expiresAt: this.expiresAt,
secretKey: arrayToB64(this.keychain.rawSecret), secretKey: arrayToB64(this.keychain.rawSecret),
nonce: this.keychain.nonce,
ownerToken: this.ownerToken, ownerToken: this.ownerToken,
dlimit: this.dlimit, dlimit: this.dlimit,
dtotal: this.dtotal, dtotal: this.dtotal,

View File

@ -43,7 +43,7 @@ class Storage {
const k = this.engine.key(i); const k = this.engine.key(i);
if (isFile(k)) { if (isFile(k)) {
try { try {
const f = new OwnedFile(JSON.parse(this.engine.getItem(k)), this); const f = new OwnedFile(JSON.parse(this.engine.getItem(k)));
if (!f.id) { if (!f.id) {
f.id = f.fileId; f.id = f.fileId;
} }