Fix session lookup in duplicate prekeymessage case
This commit is contained in:
parent
5040bfbe44
commit
ebcfd4736e
2 changed files with 11 additions and 3 deletions
12
js/crypto.js
12
js/crypto.js
|
@ -536,15 +536,21 @@ window.textsecure.crypto = function() {
|
|||
|
||||
var session = crypto_storage.getSessionOrIdentityKeyByBaseKey(encodedNumber, toArrayBuffer(message.baseKey));
|
||||
var open_session = crypto_storage.getOpenSession(encodedNumber);
|
||||
if (signedPreKeyPair === undefined) {
|
||||
// Session may or may not be the correct one, but if its not, we can't do anything about it
|
||||
if (preKeyPair === undefined || signedPreKeyPair === undefined) {
|
||||
// Session may or may not be the right one, but if its not, we can't do anything about it
|
||||
// ...fall through and let decryptWhisperMessage handle that case
|
||||
if (session !== undefined && session.currentRatchet !== undefined)
|
||||
return Promise.resolve([session, undefined]);
|
||||
else if (preKeyPair === undefined)
|
||||
throw new Error("Missing PreKey for PreKeyWhisperMessage");
|
||||
else
|
||||
throw new Error("Missing signedPreKey for PreKeyWhisperMessage");
|
||||
throw new Error("Missing Signed PreKey for PreKeyWhisperMessage");
|
||||
}
|
||||
if (session !== undefined) {
|
||||
// Duplicate PreKeyMessage for session:
|
||||
if (isEqual(session.indexInfo.baseKey, message.baseKey, false))
|
||||
return Promise.resolve([session, undefined]);
|
||||
|
||||
// We already had a session/known identity key:
|
||||
if (isEqual(session.indexInfo.remoteIdentityKey, message.identityKey, false)) {
|
||||
// If the identity key matches the previous one, close the previous one and use the new one
|
||||
|
|
|
@ -129,6 +129,8 @@ function getStringable(thing) {
|
|||
|
||||
function isEqual(a, b, mayBeShort) {
|
||||
// TODO: Special-case arraybuffers, etc
|
||||
if (a === undefined || b === undefined)
|
||||
return false;
|
||||
a = getString(a);
|
||||
b = getString(b);
|
||||
var maxLength = mayBeShort ? Math.min(a.length, b.length) : Math.max(a.length, b.length);
|
||||
|
|
Loading…
Reference in a new issue