Merge pull request #495 from sachaaaaa/fix_unknown_signedkey

[multi-device] Ensure the latest contact signed prekey is used
pull/509/head
sachaaaaa 6 years ago committed by GitHub
commit d17f86679f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1171,7 +1171,7 @@ async function getContactSignedPreKeyById(id) {
} }
async function getContactSignedPreKeyByIdentityKey(key) { async function getContactSignedPreKeyByIdentityKey(key) {
const row = await db.get( const row = await db.get(
`SELECT * FROM ${CONTACT_SIGNED_PRE_KEYS_TABLE} WHERE identityKeyString = $identityKeyString;`, `SELECT * FROM ${CONTACT_SIGNED_PRE_KEYS_TABLE} WHERE identityKeyString = $identityKeyString ORDER BY keyId DESC;`,
{ {
$identityKeyString: key, $identityKeyString: key,
} }

@ -171,6 +171,8 @@
return -1; return -1;
}; };
Whisper.events = _.clone(Backbone.Events); Whisper.events = _.clone(Backbone.Events);
Whisper.events.isListenedTo = eventName =>
Whisper.events._events ? !!Whisper.events._events[eventName] : false;
let accountManager; let accountManager;
window.getAccountManager = () => { window.getAccountManager = () => {
if (!accountManager) { if (!accountManager) {
@ -757,6 +759,10 @@
cb(e); cb(e);
} }
}); });
Whisper.events.on('devicePairingRequestRejected', async pubKey => {
await window.libloki.storage.removeContactPreKeyBundle(pubKey);
});
} }
window.getSyncRequest = () => window.getSyncRequest = () =>

@ -207,6 +207,12 @@
dialog.once('devicePairingRequestAccepted', (pubKey, cb) => dialog.once('devicePairingRequestAccepted', (pubKey, cb) =>
Whisper.events.trigger('devicePairingRequestAccepted', pubKey, cb) Whisper.events.trigger('devicePairingRequestAccepted', pubKey, cb)
); );
dialog.on('devicePairingRequestRejected', pubKey =>
Whisper.events.trigger('devicePairingRequestRejected', pubKey)
);
dialog.once('close', () => {
Whisper.events.off('devicePairingRequestReceived');
});
this.el.append(dialog.el); this.el.append(dialog.el);
}, },
}); });

@ -58,6 +58,7 @@
this.$('.requestAcceptedView .ok').show(); this.$('.requestAcceptedView .ok').show();
}, },
skipDevice() { skipDevice() {
this.trigger('devicePairingRequestRejected', this.pubKey);
this.nextPubKey(); this.nextPubKey();
this.showView(); this.showView();
}, },
@ -91,6 +92,10 @@
}, },
close() { close() {
this.remove(); this.remove();
if (this.pubKey && !this.accepted) {
this.trigger('devicePairingRequestRejected', this.pubKey);
}
this.trigger('close');
}, },
}); });
})(); })();

@ -145,8 +145,6 @@
}, },
async resetRegistration() { async resetRegistration() {
await window.Signal.Data.removeAllIdentityKeys(); await window.Signal.Data.removeAllIdentityKeys();
await window.Signal.Data.removeAllPreKeys();
await window.Signal.Data.removeAllSignedPreKeys();
await window.Signal.Data.removeAllConversations(); await window.Signal.Data.removeAllConversations();
Whisper.Registration.remove(); Whisper.Registration.remove();
// Do not remove all items since they are only set // Do not remove all items since they are only set

@ -1096,11 +1096,15 @@ MessageReceiver.prototype.extend({
async handlePairingRequest(envelope, pairingRequest) { async handlePairingRequest(envelope, pairingRequest) {
const valid = await this.validateAuthorisation(pairingRequest); const valid = await this.validateAuthorisation(pairingRequest);
if (valid) { if (valid) {
await window.libloki.storage.savePairingAuthorisation(pairingRequest); // Pairing dialog is open and is listening
Whisper.events.trigger( if (Whisper.events.isListenedTo('devicePairingRequestReceived')) {
'devicePairingRequestReceived', await window.libloki.storage.savePairingAuthorisation(pairingRequest);
pairingRequest.secondaryDevicePubKey Whisper.events.trigger(
); 'devicePairingRequestReceived',
pairingRequest.secondaryDevicePubKey
);
}
// Ignore requests if the dialog is closed
} }
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
}, },

Loading…
Cancel
Save