diff --git a/js/background.js b/js/background.js index c58eaed96e..0909c38196 100644 --- a/js/background.js +++ b/js/background.js @@ -1119,6 +1119,8 @@ details.profileKey ); conversation.setProfileKey(profileKey); + } else { + conversation.dropProfileKey(); } if (typeof details.blocked !== 'undefined') { diff --git a/js/models/conversations.js b/js/models/conversations.js index b998d300c2..a3151c0ba3 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1585,12 +1585,13 @@ // clear the changed fields here so our hasChanged() check is useful. c.changed = {}; + let profile; + try { await c.deriveAccessKeyIfNeeded(); const numberInfo = c.getNumberInfo({ disableMeCheck: true }) || {}; const getInfo = numberInfo[c.id] || {}; - let profile; if (getInfo.accessKey) { try { profile = await textsecure.messaging.getProfile(id, { @@ -1671,11 +1672,6 @@ sealedSender: SEALED_SENDER.DISABLED, }); } - - await c.setProfileName(profile.name); - - // This might throw if we can't pull the avatar down, so we do it last - await c.setProfileAvatar(profile.avatar); } catch (error) { if (error.code !== 403 && error.code !== 404) { window.log.error( @@ -1683,14 +1679,39 @@ id, error && error.stack ? error.stack : error ); + } else { + await c.dropProfileKey(); } - } finally { - if (c.hasChanged()) { - await window.Signal.Data.updateConversation(id, c.attributes, { - Conversation: Whisper.Conversation, + return; + } + + try { + await c.setProfileName(profile.name); + } catch (error) { + window.log.error( + 'getProfile decryption error:', + id, + error && error.stack ? error.stack : error + ); + await c.dropProfileKey(); + return; + } + + try { + await c.setProfileAvatar(profile.avatar); + } catch (error) { + if (error.code === 403 || error.code === 404) { + c.set({ + profileAvatar: null, }); } } + + if (c.hasChanged()) { + await window.Signal.Data.updateConversation(id, c.attributes, { + Conversation: Whisper.Conversation, + }); + } }, async setProfileName(encryptedName) { if (!encryptedName) { @@ -1757,6 +1778,8 @@ this.set({ profileKey, accessKey: null, + profileName: null, + profileAvatar: null, sealedSender: SEALED_SENDER.UNKNOWN, }); @@ -1767,6 +1790,29 @@ }); } }, + async dropProfileKey() { + if (this.get('profileKey')) { + window.log.info( + `Dropping profileKey, setting sealedSender to UNKNOWN for conversation ${this.idForLogging()}` + ); + const profileAvatar = this.get('profileAvatar'); + if (profileAvatar && profileAvatar.path) { + await deleteAttachmentData(profileAvatar.path); + } + + this.set({ + profileAvatar: null, + profileKey: null, + profileName: null, + accessKey: null, + sealedSender: SEALED_SENDER.UNKNOWN, + }); + + await window.Signal.Data.updateConversation(this.id, this.attributes, { + Conversation: Whisper.Conversation, + }); + } + }, async deriveAccessKeyIfNeeded() { const profileKey = this.get('profileKey');