Password-protected files: upload files with hashes V2
This commit is contained in:
@@ -67,23 +67,6 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
// V1
|
||||
/*var getEditHashFromKeys = Hash.getEditHashFromKeys = function (chanKey, keys) {
|
||||
if (typeof keys === 'string') {
|
||||
return chanKey + keys;
|
||||
}
|
||||
if (!keys.editKeyStr) { return; }
|
||||
return '/1/edit/' + hexToBase64(chanKey) + '/'+Crypto.b64RemoveSlashes(keys.editKeyStr)+'/';
|
||||
};
|
||||
var getViewHashFromKeys = Hash.getViewHashFromKeys = function (chanKey, keys) {
|
||||
if (typeof keys === 'string') {
|
||||
return;
|
||||
}
|
||||
return '/1/view/' + hexToBase64(chanKey) + '/'+Crypto.b64RemoveSlashes(keys.viewKeyStr)+'/';
|
||||
};
|
||||
var getFileHashFromKeys = Hash.getFileHashFromKeys = function (fileKey, cryptKey) {
|
||||
return '/1/' + hexToBase64(fileKey) + '/' + Crypto.b64RemoveSlashes(cryptKey) + '/';
|
||||
};*/
|
||||
Hash.getUserHrefFromKeys = function (origin, username, pubkey) {
|
||||
return origin + '/user/#/1/' + username + '/' + pubkey.replace(/\//g, '-');
|
||||
};
|
||||
@@ -108,7 +91,7 @@ define([
|
||||
password: Boolean(password),
|
||||
version: 2,
|
||||
type: type,
|
||||
keys: cryptor.fileKeyStr
|
||||
keys: cryptor
|
||||
});
|
||||
}
|
||||
cryptor = Crypto.createEditCryptor2(void 0, void 0, password);
|
||||
@@ -116,7 +99,7 @@ define([
|
||||
password: Boolean(password),
|
||||
version: 2,
|
||||
type: type,
|
||||
keys: cryptor.editKeyStr
|
||||
keys: cryptor
|
||||
});
|
||||
};
|
||||
|
||||
@@ -374,8 +357,8 @@ Version 1
|
||||
}
|
||||
}
|
||||
} else if (parsed.type === "file") {
|
||||
secret.channel = base64ToHex(secret.keys.chanId);
|
||||
secret.keys = Crypto.createFileCryptor2(parsed.key, password);
|
||||
secret.channel = base64ToHex(secret.keys.chanId);
|
||||
secret.key = secret.keys.fileKeyStr;
|
||||
if (secret.channel.length !== 48 || secret.key.length !== 24) {
|
||||
throw new Error("The channel key and/or the encryption key is invalid");
|
||||
|
||||
@@ -204,8 +204,8 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
common.uploadComplete = function (cb) {
|
||||
postMessage("UPLOAD_COMPLETE", null, function (obj) {
|
||||
common.uploadComplete = function (id, cb) {
|
||||
postMessage("UPLOAD_COMPLETE", id, function (obj) {
|
||||
if (obj && obj.error) { return void cb(obj.error); }
|
||||
cb(null, obj);
|
||||
});
|
||||
@@ -218,8 +218,8 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
common.uploadCancel = function (cb) {
|
||||
postMessage("UPLOAD_CANCEL", null, function (obj) {
|
||||
common.uploadCancel = function (size, cb) {
|
||||
postMessage("UPLOAD_CANCEL", {size: size}, function (obj) {
|
||||
if (obj && obj.error) { return void cb(obj.error); }
|
||||
cb(null, obj);
|
||||
});
|
||||
|
||||
@@ -230,9 +230,9 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
Store.uploadComplete = function (data, cb) {
|
||||
Store.uploadComplete = function (id, cb) {
|
||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||
store.rpc.uploadComplete(function (err, res) {
|
||||
store.rpc.uploadComplete(id, function (err, res) {
|
||||
if (err) { return void cb({error:err}); }
|
||||
cb(res);
|
||||
});
|
||||
@@ -248,7 +248,7 @@ define([
|
||||
|
||||
Store.uploadCancel = function (data, cb) {
|
||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||
store.rpc.uploadCancel(function (err, res) {
|
||||
store.rpc.uploadCancel(data.size, function (err, res) {
|
||||
if (err) { return void cb({error:err}); }
|
||||
cb(res);
|
||||
});
|
||||
|
||||
@@ -13,16 +13,14 @@ define([
|
||||
// if it exists, path contains the new pad location in the drive
|
||||
var path = file.path;
|
||||
|
||||
// XXX
|
||||
// PASSWORD_FILES
|
||||
var password;
|
||||
var password = file.password;
|
||||
var hash = Hash.createRandomHash('file', password);
|
||||
var secret = Hash.getSecrets('file', hash, password);
|
||||
var key = secret.keys.cryptKey;
|
||||
var id = secret.channel;
|
||||
//var key = Nacl.randomBytes(32);
|
||||
|
||||
// XXX provide channel id to "next"
|
||||
// XXX check id here (getFileSize)
|
||||
|
||||
var next = FileCrypto.encrypt(u8, metadata, key);
|
||||
|
||||
var estimate = FileCrypto.computeEncryptedSize(u8.length, metadata);
|
||||
@@ -53,7 +51,7 @@ define([
|
||||
}
|
||||
|
||||
// if not box then done
|
||||
common.uploadComplete(function (e/*, id*/) { // XXX id is given, not asked
|
||||
common.uploadComplete(id, function (e) {
|
||||
if (e) { return void console.error(e); }
|
||||
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
||||
console.log("encrypted blob is now available as %s", uri);
|
||||
@@ -64,11 +62,11 @@ define([
|
||||
|
||||
if (noStore) { return void onComplete(href); }
|
||||
|
||||
// PASSWORD_FILES
|
||||
var data = {
|
||||
title: title || "",
|
||||
href: href,
|
||||
path: path,
|
||||
password: password,
|
||||
channel: id
|
||||
};
|
||||
common.setPadTitle(data, function (err) {
|
||||
@@ -89,11 +87,10 @@ define([
|
||||
if (pending) {
|
||||
return void onPending(function () {
|
||||
// if the user wants to cancel the pending upload to execute that one
|
||||
common.uploadCancel(function (e, res) {
|
||||
common.uploadCancel(estimate, function (e) {
|
||||
if (e) {
|
||||
return void console.error(e);
|
||||
}
|
||||
console.log(res);
|
||||
next(again);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -176,8 +176,8 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
exp.uploadComplete = function (cb) {
|
||||
rpc.send('UPLOAD_COMPLETE', null, function (e, res) {
|
||||
exp.uploadComplete = function (id, cb) {
|
||||
rpc.send('UPLOAD_COMPLETE', id, function (e, res) {
|
||||
if (e) { return void cb(e); }
|
||||
var id = res[0];
|
||||
if (typeof(id) !== 'string') {
|
||||
@@ -203,8 +203,8 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
exp.uploadCancel = function (cb) {
|
||||
rpc.send('UPLOAD_CANCEL', void 0, function (e) {
|
||||
exp.uploadCancel = function (size, cb) {
|
||||
rpc.send('UPLOAD_CANCEL', size, function (e) {
|
||||
if (e) { return void cb(e); }
|
||||
cb();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user