Merge pull request #1565 from Chouhartem/fix-owner-share

Fix ownership/sharing issues with password-protected pads
This commit is contained in:
yflory 2024-08-28 17:05:29 +02:00 committed by GitHub
commit dab44da0a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 10 deletions

View File

@ -3559,7 +3559,7 @@ define([
$(link).click(function (e) {
e.preventDefault();
e.stopPropagation();
var obj = { pw: msg.content.password || '' };
var obj = { pw: msg.content.password || '', f: 1 };
common.openURL(Hash.getNewPadURL(msg.content.href, obj));
});
@ -3615,7 +3615,7 @@ define([
// Add the pad to your drive
// This command will also add your mailbox to the metadata log
// The callback is called when the pad is stored, independantly of the metadata command
// The callback is called when the pad is stored, independently of the metadata command
if (data.calendar) {
var calendarModule = common.makeUniversal('calendar');
var calendarData = data.calendar;

View File

@ -2619,7 +2619,8 @@ define([
disableCache: localStorage['CRYPTPAD_STORE|disableCache'],
driveEvents: !rdyCfg.noDrive, //rdyCfg.driveEvents // Boolean
lastVisit: Number(localStorage.lastVisit) || undefined,
blockId: blockId
blockId: blockId,
blockHash: blockHash
};
common.userHash = userHash || LocalStore.getUserHash();

View File

@ -129,6 +129,7 @@ define([
var obj = {
p: msg.content.isTemplate ? ['template'] : undefined,
t: teamNotification || undefined,
f: 1,
pw: msg.content.password || ''
};
common.openURL(Hash.getNewPadURL(msg.content.href, obj));

View File

@ -8,7 +8,8 @@ define([
'/common/common-hash.js',
'/common/common-util.js',
'/components/chainpad-crypto/crypto.js',
], function (ApiConfig, Messaging, Hash, Util, Crypto) {
'/common/outer/login-block.js',
], function (ApiConfig, Messaging, Hash, Util, Crypto, Block) {
// Random timeout between 10 and 30 times your sync time (lag + chainpad sync)
var getRandomTimeout = function (ctx) {
@ -237,6 +238,14 @@ define([
cb(true);
};
// Encrypt the password under the right key before sending it via URL hash
var encryptPassword = function(ctx, password) {
let uHash = ctx.store.data.blockHash;
let uSecret = Block.parseBlockHash(uHash);
let key = uSecret.keys.symmetric;
return Crypto.encrypt(password, key);
};
// Hide duplicates when receiving a SHARE_PAD notification:
// Keep only one notification per channel: the stronger and more recent one
var channels = {};
@ -265,8 +274,7 @@ define([
}
if (content.password) {
var key = ctx.store.driveSecret.keys.cryptKey;
content.password = Crypto.encrypt(content.password, key);
content.password = encryptPassword(ctx, content.password);
}
// Update the data
@ -384,8 +392,8 @@ define([
var channel = content.channel || content.teamChannel;
if (content.password) {
var key = ctx.store.driveSecret.keys.cryptKey;
content.password = Crypto.encrypt(content.password, key);
content.pw = content.password;
content.password = encryptPassword(ctx, content.password);
}
if (addOwners[channel]) { return void cb(true); }

View File

@ -1083,7 +1083,7 @@ define([
Cryptpad.addSharedFolder(null, secret, cb);
} else {
var _data = {
password: data.password,
password: data.pw || data.password,
href: data.href,
channel: data.channel,
title: data.title,
@ -1359,7 +1359,7 @@ define([
var viewH = Utils.Hash.getViewHashFromKeys(_secret);
var href = Utils.Hash.hashToHref(editH, parsed.type);
var roHref = Utils.Hash.hashToHref(viewH, parsed.type);
Cryptpad.setPadAttribute('password', password, w(), parsed.getUrl());
Cryptpad.setPadAttribute('password', pw, w(), parsed.getUrl());
Cryptpad.setPadAttribute('channel', chan, w(), parsed.getUrl());
Cryptpad.setPadAttribute('href', href, w(), parsed.getUrl());
Cryptpad.setPadAttribute('roHref', roHref, w(), parsed.getUrl());