Drop profile on missing profile key, drop avatar on download 403

This commit is contained in:
Scott Nonnenberg 2019-06-05 16:26:07 -07:00 committed by Ken Powers
parent f4cb1194c6
commit 3505ab9198
2 changed files with 58 additions and 10 deletions

View file

@ -1119,6 +1119,8 @@
details.profileKey details.profileKey
); );
conversation.setProfileKey(profileKey); conversation.setProfileKey(profileKey);
} else {
conversation.dropProfileKey();
} }
if (typeof details.blocked !== 'undefined') { if (typeof details.blocked !== 'undefined') {

View file

@ -1585,12 +1585,13 @@
// clear the changed fields here so our hasChanged() check is useful. // clear the changed fields here so our hasChanged() check is useful.
c.changed = {}; c.changed = {};
let profile;
try { try {
await c.deriveAccessKeyIfNeeded(); await c.deriveAccessKeyIfNeeded();
const numberInfo = c.getNumberInfo({ disableMeCheck: true }) || {}; const numberInfo = c.getNumberInfo({ disableMeCheck: true }) || {};
const getInfo = numberInfo[c.id] || {}; const getInfo = numberInfo[c.id] || {};
let profile;
if (getInfo.accessKey) { if (getInfo.accessKey) {
try { try {
profile = await textsecure.messaging.getProfile(id, { profile = await textsecure.messaging.getProfile(id, {
@ -1671,11 +1672,6 @@
sealedSender: SEALED_SENDER.DISABLED, 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) { } catch (error) {
if (error.code !== 403 && error.code !== 404) { if (error.code !== 403 && error.code !== 404) {
window.log.error( window.log.error(
@ -1683,14 +1679,39 @@
id, id,
error && error.stack ? error.stack : error error && error.stack ? error.stack : error
); );
} else {
await c.dropProfileKey();
} }
} finally { 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()) { if (c.hasChanged()) {
await window.Signal.Data.updateConversation(id, c.attributes, { await window.Signal.Data.updateConversation(id, c.attributes, {
Conversation: Whisper.Conversation, Conversation: Whisper.Conversation,
}); });
} }
}
}, },
async setProfileName(encryptedName) { async setProfileName(encryptedName) {
if (!encryptedName) { if (!encryptedName) {
@ -1757,6 +1778,8 @@
this.set({ this.set({
profileKey, profileKey,
accessKey: null, accessKey: null,
profileName: null,
profileAvatar: null,
sealedSender: SEALED_SENDER.UNKNOWN, 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() { async deriveAccessKeyIfNeeded() {
const profileKey = this.get('profileKey'); const profileKey = this.get('profileKey');