From 3f1e287811dfe1a02c84f9e97e04d2da53b4a076 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 12 Jan 2017 11:09:45 +0100 Subject: [PATCH] Fix an issue causing a user object to be turned into a pad --- customize.dist/fsStore.js | 5 ++++- www/common/cryptpad-common.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/customize.dist/fsStore.js b/customize.dist/fsStore.js index 1afd96063..fd86e4dd3 100644 --- a/customize.dist/fsStore.js +++ b/customize.dist/fsStore.js @@ -138,7 +138,10 @@ define([ var init = function (f, Cryptpad) { if (!Cryptpad || initialized) { return; } initialized = true; - var hash = Cryptpad.getUserHash() || localStorage.FS_hash; + var hash = Cryptpad.getUserHash() || localStorage.FS_hash || Cryptpad.createRandomHash(); + if (!hash) { + throw new Error('[Store.init] Unable to find or create a drive hash. Aborting...'); + } var secret = Cryptpad.getSecrets(hash); var listmapConfig = { data: {}, diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 1761e79f4..87b039e4d 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -171,12 +171,20 @@ define([ var getHashFromKeys = common.getHashFromKeys = getEditHashFromKeys; var specialHashes = common.specialHashes = ['iframe']; + + /* + * Returns all needed keys for a realtime channel + * - no argument: use the URL hash or create one if it doesn't exist + * - secretHash provided: use secretHash to find the keys + */ var getSecrets = common.getSecrets = function (secretHash) { var secret = {}; var generate = function () { secret.keys = Crypto.createEditCryptor(); secret.key = Crypto.createEditCryptor().editKeyStr; }; + // If we have a hash in the URL specifying a path, it means the document was created from + // the drive and should be stored at the selected path. if (/#\?path=/.test(window.location.href)) { var arr = window.location.hash.match(/\?path=(.+)/); common.initialPath = arr[1] || undefined;