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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ class Storage {
const k = this.engine.key(i);
if (isFile(k)) {
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) {
f.id = f.fileId;
}