more missing awaits

pull/66/head
sachaaaaa 6 years ago
parent df80249cba
commit f2e1b9b8de

@ -1456,6 +1456,10 @@
return this.get('sessionResetStatus') === SessionResetEnum.request_received; return this.get('sessionResetStatus') === SessionResetEnum.request_received;
}, },
isSessionResetOngoing() {
return this.get('sessionResetStatus') !== SessionResetEnum.none;
},
async createAndStoreEndSessionMessage(endSessionType) { async createAndStoreEndSessionMessage(endSessionType) {
const now = Date.now(); const now = Date.now();
const message = this.messageCollection.add({ const message = this.messageCollection.add({

@ -755,20 +755,26 @@ MessageReceiver.prototype.extend({
record.updateSessionState(sessionToKeep); record.updateSessionState(sessionToKeep);
await textsecure.storage.protocol.storeSession(address.toString(), record.serialize()); await textsecure.storage.protocol.storeSession(address.toString(), record.serialize());
}; };
const handleSessionReset = async () => { let handleSessionReset;
if (conversation.isSessionResetOngoing()) {
handleSessionReset = async (result) => {
const currentSessionBaseKey = await getCurrentSessionBaseKey(sessionCipher); const currentSessionBaseKey = await getCurrentSessionBaseKey(sessionCipher);
if (this.activeSessionBaseKey && currentSessionBaseKey !== this.activeSessionBaseKey) { if (this.activeSessionBaseKey && currentSessionBaseKey !== this.activeSessionBaseKey) {
if (conversation.isSessionResetReceived()) { if (conversation.isSessionResetReceived()) {
restoreActiveSession(); await restoreActiveSession();
} else { } else {
deleteAllSessionExcept(currentSessionBaseKey); await deleteAllSessionExcept(currentSessionBaseKey);
conversation.onNewSessionAdopted(); await conversation.onNewSessionAdopted();
} }
} else if (conversation.isSessionResetReceived()) { } else if (conversation.isSessionResetReceived()) {
deleteAllSessionExcept(this.activeSessionBaseKey); await deleteAllSessionExcept(this.activeSessionBaseKey);
conversation.onNewSessionAdopted(); await conversation.onNewSessionAdopted();
} }
return result;
}; };
} else {
handleSessionReset = async (result) => result;
}
switch (envelope.type) { switch (envelope.type) {
case textsecure.protobuf.Envelope.Type.CIPHERTEXT: case textsecure.protobuf.Envelope.Type.CIPHERTEXT:
@ -776,10 +782,7 @@ MessageReceiver.prototype.extend({
promise = captureActiveSession() promise = captureActiveSession()
.then(() => sessionCipher.decryptWhisperMessage(ciphertext)) .then(() => sessionCipher.decryptWhisperMessage(ciphertext))
.then(this.unpad) .then(this.unpad)
.then((plainText) => { .then(handleSessionReset);
handleSessionReset();
return plainText;
});
break; break;
case textsecure.protobuf.Envelope.Type.FRIEND_REQUEST: { case textsecure.protobuf.Envelope.Type.FRIEND_REQUEST: {
window.log.info('friend-request message from ', envelope.source); window.log.info('friend-request message from ', envelope.source);
@ -795,10 +798,7 @@ MessageReceiver.prototype.extend({
sessionCipher, sessionCipher,
address address
)) ))
.then((plainText) => { .then(handleSessionReset);
handleSessionReset();
return plainText;
});
break; break;
case textsecure.protobuf.Envelope.Type.UNIDENTIFIED_SENDER: case textsecure.protobuf.Envelope.Type.UNIDENTIFIED_SENDER:
window.log.info('received unidentified sender message'); window.log.info('received unidentified sender message');
@ -1356,9 +1356,12 @@ MessageReceiver.prototype.extend({
window.log.error('Error getting conversation: ', number); window.log.error('Error getting conversation: ', number);
} }
conversation.onSessionResetReceived(); // Bail early if a session reset is already ongoing
if (conversation.isSessionResetOngoing()) {
return;
}
return Promise.all( await Promise.all(
deviceIds.map(async deviceId => { deviceIds.map(async deviceId => {
const address = new libsignal.SignalProtocolAddress(number, deviceId); const address = new libsignal.SignalProtocolAddress(number, deviceId);
// Instead of deleting the sessions now, // Instead of deleting the sessions now,
@ -1370,7 +1373,7 @@ MessageReceiver.prototype.extend({
textsecure.storage.protocol.loadContactSignedPreKey(number), textsecure.storage.protocol.loadContactSignedPreKey(number),
]); ]);
if (preKey === undefined || signedPreKey === undefined) { if (preKey === undefined || signedPreKey === undefined) {
return null; return;
} }
const device = { identityKey, deviceId, preKey, signedPreKey, registrationId: 0 } const device = { identityKey, deviceId, preKey, signedPreKey, registrationId: 0 }
const builder = new libsignal.SessionBuilder( const builder = new libsignal.SessionBuilder(
@ -1378,9 +1381,9 @@ MessageReceiver.prototype.extend({
address address
); );
builder.processPreKey(device); builder.processPreKey(device);
return null;
}) })
); );
await conversation.onSessionResetReceived();
}, },
processDecrypted(envelope, decrypted, source) { processDecrypted(envelope, decrypted, source) {
/* eslint-disable no-bitwise, no-param-reassign */ /* eslint-disable no-bitwise, no-param-reassign */

Loading…
Cancel
Save