|
|
@ -1,8 +1,9 @@
|
|
|
|
define([
|
|
|
|
define([
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
'/common/common-hash.js',
|
|
|
|
'/common/common-hash.js',
|
|
|
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
], function (FileCrypto, Hash) {
|
|
|
|
], function (FileCrypto, Hash, nThen) {
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var module = {};
|
|
|
|
var module = {};
|
|
|
|
|
|
|
|
|
|
|
@ -14,13 +15,29 @@ define([
|
|
|
|
var path = file.path;
|
|
|
|
var path = file.path;
|
|
|
|
|
|
|
|
|
|
|
|
var password = file.password;
|
|
|
|
var password = file.password;
|
|
|
|
var hash = Hash.createRandomHash('file', password);
|
|
|
|
var hash, secret, key, id, href;
|
|
|
|
var secret = Hash.getSecrets('file', hash, password);
|
|
|
|
|
|
|
|
var key = secret.keys.cryptKey;
|
|
|
|
var getNewHash = function () {
|
|
|
|
var id = secret.channel;
|
|
|
|
hash = Hash.createRandomHash('file', password);
|
|
|
|
|
|
|
|
secret = Hash.getSecrets('file', hash, password);
|
|
|
|
|
|
|
|
key = secret.keys.cryptKey;
|
|
|
|
|
|
|
|
id = secret.channel;
|
|
|
|
|
|
|
|
href = '/file/#' + hash;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// XXX check id here (getFileSize)
|
|
|
|
var getValidHash = function (cb) {
|
|
|
|
|
|
|
|
getNewHash();
|
|
|
|
|
|
|
|
common.getFileSize(href, password, function (err, size) {
|
|
|
|
|
|
|
|
if (err || typeof(size) !== "number") { throw new Error(err || "Invalid size!"); }
|
|
|
|
|
|
|
|
if (size === 0) { return void cb(); }
|
|
|
|
|
|
|
|
getValidHash();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
|
|
|
// Generate a hash and check if the resulting id is valid (not already used)
|
|
|
|
|
|
|
|
getValidHash(waitFor());
|
|
|
|
|
|
|
|
}).nThen(function () {
|
|
|
|
var next = FileCrypto.encrypt(u8, metadata, key);
|
|
|
|
var next = FileCrypto.encrypt(u8, metadata, key);
|
|
|
|
|
|
|
|
|
|
|
|
var estimate = FileCrypto.computeEncryptedSize(u8.length, metadata);
|
|
|
|
var estimate = FileCrypto.computeEncryptedSize(u8.length, metadata);
|
|
|
@ -56,7 +73,6 @@ define([
|
|
|
|
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
|
|
|
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
|
|
|
console.log("encrypted blob is now available as %s", uri);
|
|
|
|
console.log("encrypted blob is now available as %s", uri);
|
|
|
|
|
|
|
|
|
|
|
|
var href = '/file/#' + hash;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var title = metadata.name;
|
|
|
|
var title = metadata.name;
|
|
|
|
|
|
|
|
|
|
|
@ -97,6 +113,8 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next(again);
|
|
|
|
next(again);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return module;
|
|
|
|
return module;
|
|
|
|
});
|
|
|
|
});
|
|
|
|