diff --git a/www/common/outer/mailbox-handlers.js b/www/common/outer/mailbox-handlers.js index 0b98bbe9f..906be2843 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -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); }