Cleaning code: use a function to encrypt the password

- Use a function to encrypt the password for later use in URLs as it is
  used both to share a password-protected pad and share ownership of a
  password-protected pad;
- related do #1270 and #1522.
This commit is contained in:
Fabrice Mouhartem 2024-07-19 12:10:05 +02:00
parent 750635db4e
commit 8ceccb678c
No known key found for this signature in database
GPG Key ID: 90579C24FD123C93

View File

@ -238,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 = {};
@ -266,10 +274,7 @@ define([
}
if (content.password) {
let uHash = ctx.store.data.blockHash;
let uSecret = Block.parseBlockHash(uHash);
let key = uSecret.keys.symmetric;
content.password = Crypto.encrypt(content.password, key);
content.password = encryptPassword(ctx, content.password);
}
// Update the data
@ -387,11 +392,8 @@ define([
var channel = content.channel || content.teamChannel;
if (content.password) {
let uHash = ctx.store.data.blockHash;
let uSecret = Block.parseBlockHash(uHash);
let key = uSecret.keys.symmetric;
content.pw = content.password;
content.password = Crypto.encrypt(content.password, key);
content.password = encryptPassword(ctx, content.password);
}
if (addOwners[channel]) { return void cb(true); }