Provide the secondaryKey to userObject

pull/1/head
yflory 5 years ago
parent dd2f0bd417
commit cf0d0e8e4b

@ -420,39 +420,6 @@ Version 1
}; };
// STORAGE // STORAGE
Hash.findWeaker = function (href, channel, recents) {
var parsed = parsePadUrl(href);
if (!parsed.hash) { return false; }
// We can't have a weaker hash if we're already in view mode
if (parsed.hashData && parsed.hashData.mode === 'view') { return; }
var weaker;
Object.keys(recents).some(function (id) {
var pad = recents[id];
if (pad.href || !pad.roHref) {
// This pad has an edit link, so it can't be weaker
return;
}
var p = parsePadUrl(pad.roHref);
if (p.type !== parsed.type) { return; } // Not the same type
if (p.hash === parsed.hash) { return; } // Same hash, not stronger
if (channel !== pad.channel) { return; } // Not the same channel
var pHash = p.hashData;
var parsedHash = parsed.hashData;
if (!parsedHash || !pHash) { return; }
// We don't have stronger/weaker versions of files or users
if (pHash.type !== 'pad' && parsedHash.type !== 'pad') { return; }
if (pHash.version !== parsedHash.version) { return; }
if (pHash.mode === 'view' && parsedHash.mode === 'edit') {
weaker = pad;
return true;
}
return;
});
return weaker;
};
Hash.findStronger = function (href, channel, recents) { Hash.findStronger = function (href, channel, recents) {
var parsed = parsePadUrl(href); var parsed = parsePadUrl(href);
if (!parsed.hash) { return false; } if (!parsed.hash) { return false; }
@ -472,6 +439,7 @@ Version 1
if (channel !== pad.channel) { return; } if (channel !== pad.channel) { return; }
// If this pad doesn't have an edit link, it can't be stronger // If this pad doesn't have an edit link, it can't be stronger
// XXX encrypted href
if (!pad.href || !pad.roHref) { return; } if (!pad.href || !pad.roHref) { return; }
// This is a pad with an EDIT href and using the same channel as our target // This is a pad with an EDIT href and using the same channel as our target

@ -542,7 +542,10 @@ define([
Object.keys(folders).forEach(function (id) { Object.keys(folders).forEach(function (id) {
var f = folders[id]; var f = folders[id];
manager.addProxy(id, f); var sfData = files.sharedFolders[id] || {};
var parsed = Hash.parsePadUrl(sfData.href);
var secret = Hash.getSecrets('drive', parsed.hash, sfData.password);
manager.addProxy(id, f, null, secret.keys.secondaryKey);
}); });
// UI containers // UI containers

@ -38,6 +38,7 @@ define([
var data = oldFo.getFileData(id); var data = oldFo.getFileData(id);
var channel = data.channel; var channel = data.channel;
// XXX encrypted href: we need to be able to change the value here
var datas = manager.findChannel(channel, true); var datas = manager.findChannel(channel, true);
// Do not migrate a pad if we already have it, it would create a duplicate // Do not migrate a pad if we already have it, it would create a duplicate
// in the drive // in the drive

@ -249,6 +249,7 @@ define([
if (msg.author !== content.user.curvePublic) { return void cb(true); } if (msg.author !== content.user.curvePublic) { return void cb(true); }
var channel = content.channel; var channel = content.channel;
// XXX encrypted href
var res = ctx.store.manager.findChannel(channel); var res = ctx.store.manager.findChannel(channel);
var title; var title;

@ -27,13 +27,14 @@ define([
var parsed = Hash.parsePadUrl(data.href); var parsed = Hash.parsePadUrl(data.href);
var secret = Hash.getSecrets('drive', parsed.hash, data.password); var secret = Hash.getSecrets('drive', parsed.hash, data.password);
var secondaryKey = secret.keys.secondaryKey;
var sf = allSharedFolders[secret.channel]; var sf = allSharedFolders[secret.channel];
if (sf && sf.ready && sf.rt) { if (sf && sf.ready && sf.rt) {
// The shared folder is already loaded, return its data // The shared folder is already loaded, return its data
setTimeout(function () { setTimeout(function () {
var leave = function () { SF.leave(secret.channel, teamId); }; var leave = function () { SF.leave(secret.channel, teamId); };
store.manager.addProxy(id, sf.rt.proxy, leave); store.manager.addProxy(id, sf.rt.proxy, leave, secondaryKey);
cb(sf.rt, sf.metadata); cb(sf.rt, sf.metadata);
}); });
sf.team.push(teamId); sf.team.push(teamId);
@ -84,7 +85,7 @@ define([
} }
sf.queue.forEach(function (obj) { sf.queue.forEach(function (obj) {
var leave = function () { SF.leave(secret.channel, teamId); }; var leave = function () { SF.leave(secret.channel, teamId); };
obj.store.manager.addProxy(obj.id, rt.proxy, leave); obj.store.manager.addProxy(obj.id, rt.proxy, leave, secondaryKey);
obj.cb(rt, info.metadata); obj.cb(rt, info.metadata);
}); });
sf.leave = info.leave; sf.leave = info.leave;

@ -215,6 +215,11 @@ define([
cb(id, rt); cb(id, rt);
}); });
}; };
var teamData = ctx.store.proxy.teams[team.id];
var secret;
if (teamData) {
secret = Hash.getSecrets('team', teamData.hash, teamData.password);
}
var manager = team.manager = ProxyManager.create(proxy.drive, { var manager = team.manager = ProxyManager.create(proxy.drive, {
onSync: function (cb) { ctx.Store.onSync(id, cb); }, onSync: function (cb) { ctx.Store.onSync(id, cb); },
edPublic: keys.drive.edPublic, edPublic: keys.drive.edPublic,
@ -223,7 +228,8 @@ define([
loadSharedFolder: loadSharedFolder, loadSharedFolder: loadSharedFolder,
settings: { settings: {
drive: Util.find(ctx.store, ['proxy', 'settings', 'drive']) drive: Util.find(ctx.store, ['proxy', 'settings', 'drive'])
} },
editKey: secret && secret.keys.secondaryKey
}, { }, {
outer: true, outer: true,
removeOwnedChannel: function (channel, cb) { removeOwnedChannel: function (channel, cb) {

@ -36,7 +36,7 @@ define([
var id = exp.getIdFromHref(href); var id = exp.getIdFromHref(href);
if (!id) { return void cb("E_INVAL_HREF"); } if (!id) { return void cb("E_INVAL_HREF"); }
if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); } if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); }
var data = exp.getFileData(id); var data = exp.getFileData(id, true);
data[attr] = clone(value); data[attr] = clone(value);
cb(null); cb(null);
}; };

@ -14,10 +14,11 @@ define([
}; };
// Add a shared folder to the list // Add a shared folder to the list
var addProxy = function (Env, id, proxy, leave) { var addProxy = function (Env, id, proxy, leave, editKey) {
var cfg = getConfig(Env); var cfg = getConfig(Env);
cfg.sharedFolder = true; cfg.sharedFolder = true;
cfg.id = id; cfg.id = id;
cfg.editKey = editKey;
var userObject = UserObject.init(proxy, cfg); var userObject = UserObject.init(proxy, cfg);
if (userObject.fixFiles) { if (userObject.fixFiles) {
// Only in outer // Only in outer

@ -5,8 +5,9 @@ define([
'/common/common-realtime.js', '/common/common-realtime.js',
'/common/common-constants.js', '/common/common-constants.js',
'/common/outer/userObject.js', '/common/outer/userObject.js',
'/customize/messages.js' '/customize/messages.js',
], function (AppConfig, Util, Hash, Realtime, Constants, OuterFO, Messages) { '/bower_components/chainpad-crypto/crypto.js',
], function (AppConfig, Util, Hash, Realtime, Constants, OuterFO, Messages, Crypto) {
var module = {}; var module = {};
var ROOT = module.ROOT = "root"; var ROOT = module.ROOT = "root";
@ -31,6 +32,19 @@ define([
module.init = function (files, config) { module.init = function (files, config) {
var exp = {}; var exp = {};
exp.cryptor = {
encrypt : function (x) { return x; },
decrypt : function (x) { return x; },
};
if (config.editKey) {
try {
exp.cryptor = Crypto.createEncryptor(config.editKey);
} catch (e) {
console.error(e);
}
}
exp.getDefaultName = module.getDefaultName; exp.getDefaultName = module.getDefaultName;
var sframeChan = config.sframeChan; var sframeChan = config.sframeChan;
@ -205,9 +219,14 @@ define([
}; };
// Get data from AllFiles (Cryptpad_RECENTPADS) // Get data from AllFiles (Cryptpad_RECENTPADS)
var getFileData = exp.getFileData = function (file) { var getFileData = exp.getFileData = function (file, noCopy) {
if (!file) { return; } if (!file) { return; }
return files[FILES_DATA][file] || {}; var data = files[FILES_DATA][file] || {};
if (!noCopy) {
// XXX encrypted href: decrypt or remove "href"
data = JSON.parse(JSON.stringify(data));
}
return data;
}; };
exp.getFolderData = function (folder) { exp.getFolderData = function (folder) {

@ -3,6 +3,7 @@ define([
'/common/toolbar3.js', '/common/toolbar3.js',
'/common/drive-ui.js', '/common/drive-ui.js',
'/common/common-util.js', '/common/common-util.js',
'/common/common-hash.js',
'/common/common-interface.js', '/common/common-interface.js',
'/common/common-feedback.js', '/common/common-feedback.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
@ -19,6 +20,7 @@ define([
Toolbar, Toolbar,
DriveUI, DriveUI,
Util, Util,
Hash,
UI, UI,
Feedback, Feedback,
nThen, nThen,
@ -41,13 +43,16 @@ define([
var oldIds = Object.keys(folders); var oldIds = Object.keys(folders);
nThen(function (waitFor) { nThen(function (waitFor) {
Object.keys(drive.sharedFolders).forEach(function (fId) { Object.keys(drive.sharedFolders).forEach(function (fId) {
var sfData = drive.sharedFolders[id] || {};
var parsed = Hash.parsePadUrl(sfData.href);
var secret = Hash.getSecrets('drive', parsed.hash, sfData.password);
sframeChan.query('Q_DRIVE_GETOBJECT', { sframeChan.query('Q_DRIVE_GETOBJECT', {
sharedFolder: fId sharedFolder: fId
}, waitFor(function (err, newObj) { }, waitFor(function (err, newObj) {
folders[fId] = folders[fId] || {}; folders[fId] = folders[fId] || {};
copyObjectValue(folders[fId], newObj); copyObjectValue(folders[fId], newObj);
if (manager && oldIds.indexOf(fId) === -1) { if (manager && oldIds.indexOf(fId) === -1) {
manager.addProxy(fId, folders[fId]); manager.addProxy(fId, folders[fId], null, secret.keys.secondaryKey);
} }
})); }));
}); });

@ -52,13 +52,16 @@ define([
var oldIds = Object.keys(folders); var oldIds = Object.keys(folders);
nThen(function (waitFor) { nThen(function (waitFor) {
Object.keys(drive.sharedFolders).forEach(function (fId) { Object.keys(drive.sharedFolders).forEach(function (fId) {
var sfData = drive.sharedFolders[id] || {};
var parsed = Hash.parsePadUrl(sfData.href);
var secret = Hash.getSecrets('drive', parsed.hash, sfData.password);
sframeChan.query('Q_DRIVE_GETOBJECT', { sframeChan.query('Q_DRIVE_GETOBJECT', {
sharedFolder: fId sharedFolder: fId
}, waitFor(function (err, newObj) { }, waitFor(function (err, newObj) {
folders[fId] = folders[fId] || {}; folders[fId] = folders[fId] || {};
copyObjectValue(folders[fId], newObj); copyObjectValue(folders[fId], newObj);
if (manager && oldIds.indexOf(fId) === -1) { if (manager && oldIds.indexOf(fId) === -1) {
manager.addProxy(fId, folders[fId]); manager.addProxy(fId, folders[fId], null, secret.keys.secondaryKey);
} }
})); }));
}); });
@ -260,13 +263,21 @@ define([
$limitContainer.attr('title', Messages.team_quota); $limitContainer.attr('title', Messages.team_quota);
}, true); }, true);
driveAPP.team = id; driveAPP.team = id;
// Provide secondaryKey
var teamData = (proxy.teams || {})[id];
var secret;
if (teamData) {
secret = Hash.getSecrets('team', teamData.hash, teamData.password);
}
var drive = DriveUI.create(common, { var drive = DriveUI.create(common, {
proxy: proxy, proxy: proxy,
folders: folders, folders: folders,
updateObject: updateObject, updateObject: updateObject,
updateSharedFolders: updateSharedFolders, updateSharedFolders: updateSharedFolders,
APP: driveAPP, APP: driveAPP,
edPublic: APP.teamEdPublic edPublic: APP.teamEdPublic,
editKey: secret && secret.keys.secondaryKey
}); });
APP.drive = drive; APP.drive = drive;
driveAPP.refresh = drive.refresh; driveAPP.refresh = drive.refresh;

Loading…
Cancel
Save