From 176e66712879965af53cdb74b6bb648a6d2e7168 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 28 Oct 2019 18:22:42 +0100 Subject: [PATCH] Add more migration options --- www/common/outer/sharedfolder.js | 22 ++++++++++++++++++++++ www/common/outer/userObject.js | 25 +++++-------------------- www/common/proxy-manager.js | 7 +++++++ www/common/userObject.js | 10 +++++++--- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/www/common/outer/sharedfolder.js b/www/common/outer/sharedfolder.js index ef6a9dddd..888c0b426 100644 --- a/www/common/outer/sharedfolder.js +++ b/www/common/outer/sharedfolder.js @@ -63,6 +63,28 @@ define([ }); }; + // XXX only needed if we want a manual migration from the share modal... + SF.migrate = function (channel) { + var sf = allSharedFolders[channel]; + if (!sf) { return; } + var clients = sf.teams; + if (!Array.isArray(clients) || !clients.length) { return; } + var c = clients[0]; + // No secondaryKey? ==> already migrated ==> abort + if (!c.secondaryKey) { return; } + var f = Util.find(c, ['store', 'manager', 'folders', c.id]); + // Can't find the folder: abort + if (!f) { return; } + // Already migrated: abort + if (!f.proxy || f.proxy.version) { return; } + f.userObject.migrateReadOnly(function () { + clients.forEach(function (obj) { + var uo = Util.find(obj, ['store', 'manager', 'folders', obj.id, 'userObject']); + uo.setReadOnly(false, obj.secondarykey); + }); + }); + }; + SF.load = function (config, id, data, _cb) { var cb = Util.once(_cb); var network = config.network; diff --git a/www/common/outer/userObject.js b/www/common/outer/userObject.js index 55fe8014d..a254911bf 100644 --- a/www/common/outer/userObject.js +++ b/www/common/outer/userObject.js @@ -478,28 +478,13 @@ define([ files.migrateRo = 1; var next = function () { var copy = JSON.parse(JSON.stringify(files)); - exp.reencrypt(null, config.editKey, copy); - // XXX test migration again - /* - Object.keys(copy[FILES_DATA]).forEach(function (id) { - var data = copy[FILES_DATA][id] || {}; - // If this pad has a visible href, encrypt it - // "&& data.roHref" is here to make sure this is not a "file" - if (data.href && data.roHref && !data.fileType && data.href.indexOf('#') !== -1) { - data.href = exp.cryptor.encrypt(data.href); - } + exp.reencrypt(config.editKey, config.editKey, copy); + Object.keys(copy).forEach(function (k) { + files[k] = copy[k]; }); - Object.keys(copy[SHARED_FOLDERS] || {}).forEach(function (id) { - var data = copy[SHARED_FOLDERS][id] || {}; - // If this folder has a visible href, encrypt it - if (data.href && data.roHref && !data.fileType && data.href.indexOf('#') !== -1) { - data.href = exp.cryptor.encrypt(data.href); - } - });*/ - copy.version = 2; - delete copy.migrateRo; + files.version = 2; + delete files.migrateRo; - files = copy; onSync(cb); }; onSync(next); diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index db0d6a258..df5aa131b 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -39,6 +39,13 @@ define([ userObject: userObject, leave: leave }; + if (false) { // XXX allow shared folder migration while using it + // NOTE: this is not needed if we always use the editKey in userObject, even with old version + var path = proxy.drive ? ['drive', 'version'] : ['version']; + proxy.on('change', path, function () { + userObject.setReadOnly(false, editKey); + }); + } return userObject; }; diff --git a/www/common/userObject.js b/www/common/userObject.js index b85075329..f5a1ff705 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -77,7 +77,7 @@ define([ // If this pad has a visible href, encrypt it // "&& data.roHref" is here to make sure this is not a "file" if (data.href && data.roHref && !data.fileType) { - var _href = oldCryptor.decrypt(data.href); + var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href; data.href = newCryptor.encrypt(_href); } }); @@ -85,7 +85,7 @@ define([ var data = obj[SHARED_FOLDERS][id] || {}; // If this folder has a visible href, encrypt it if (data.href) { - var _href = oldCryptor.decrypt(data.href); + var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href; data.href = newCryptor.encrypt(_href); } }); @@ -93,7 +93,7 @@ define([ var data = obj[SHARED_FOLDERS_TEMP][id] || {}; // If this folder has a visible href, encrypt it if (data.href) { - var _href = oldCryptor.decrypt(data.href); + var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href; data.href = newCryptor.encrypt(_href); } }); @@ -102,6 +102,10 @@ define([ module.init = function (files, config) { var exp = {}; + if (false && !files.version) { // XXX if we remove false, old shared folders won't encrypt new hrefs + config.editKey = undefined; + } + exp.cryptor = createCryptor(config.editKey); exp.setReadOnly = function (state, key) {