mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
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:
parent
750635db4e
commit
8ceccb678c
@ -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); }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user