move SESSION_REQUEST processing to handleSessionRequestMessage()

pull/1172/head
Audric Ackermann 5 years ago
parent d1518f8233
commit d7e9d6cfb8
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -20,7 +20,7 @@
/* global ConversationController: false */
/* global Signal: false */
/* global log: false */
/* global session: false */
/* global libsession: false */
/* eslint-disable more/no-then */
/* eslint-disable no-unreachable */
@ -1547,24 +1547,60 @@ MessageReceiver.prototype.extend({
}
},
async handleSessionRequestMessage(envelope, content) {
const shouldProcessSessionRequest = await session.Protocols.SessionProtocol.shouldProcessSessionRequest(
const shouldProcessSessionRequest = await libsession.Protocols.SessionProtocol.shouldProcessSessionRequest(
envelope.source,
envelope.timestamp
);
if (shouldProcessSessionRequest) {
if (content.preKeyBundleMessage) {
await this.savePreKeyBundleMessage(
try {
// TODO remember to remove savePreKeyBundleMessage() from the codebase if it's actually irrelevant
// if (content.preKeyBundleMessage) {
// await this.savePreKeyBundleMessage(
// envelope.source,
// content.preKeyBundleMessage
// );
// }
// device id are always 1 with Session
const deviceId = 1;
const address = new libsignal.SignalProtocolAddress(
envelope.source,
content.preKeyBundleMessage
deviceId
);
// Instead of deleting the sessions now,
// we process the new prekeys and initiate a new session.
// The old sessions will get deleted once the correspondant
// has switch to the new session.
const { preKey, signedKey, identityKey } = content.preKeyBundleMessage;
if (preKey === undefined || signedKey === undefined) {
window.console.warn(
"Couldn't process prekey bundle without preKey or signedKey"
);
return;
}
const device = {
identityKey,
deviceId,
preKey,
signedPreKey: signedKey,
registrationId: 0,
};
const builder = new libsignal.SessionBuilder(
textsecure.storage.protocol,
address
);
await builder.processPreKey(device);
await libsession.Protocols.SessionProtocol.onSessionRequestProcessed(
envelope.source
);
window.log.debug('sending session established to', envelope.source);
// We don't need to await the call below because we just want to send it off
window.libloki.api.sendSessionEstablishedMessage(envelope.source);
} catch (e) {
window.log.warn('Failed to process session request');
// TODO how to handle a failed session request?
}
await session.Protocols.SessionProtocol.onSessionRequestProcessed(
envelope.source
);
window.log.info('sending session established to', envelope.source);
// We don't need to await the call below because we just want to send it off
window.libloki.api.sendSessionEstablishedMessage(envelope.source);
}
},
async innerHandleContentMessage(envelope, plaintext) {
@ -1574,7 +1610,7 @@ MessageReceiver.prototype.extend({
if (envelope.type === SESSION_REQUEST) {
await this.handleSessionRequestMessage(envelope, content);
} else {
await session.Protocols.SessionProtocol.onSessionEstablished(
await libsession.Protocols.SessionProtocol.onSessionEstablished(
envelope.source
);
// TODO process sending queue for this device now that we have a session
@ -1915,43 +1951,12 @@ MessageReceiver.prototype.extend({
},
async handleEndSession(number) {
window.log.info('got end session');
const deviceIds = await textsecure.storage.protocol.getDeviceIds(number);
const identityKey = StringView.hexToArrayBuffer(number);
let conversation;
try {
conversation = window.ConversationController.get(number);
} catch (e) {
window.log.error('Error getting conversation: ', number);
}
await Promise.all(
deviceIds.map(async deviceId => {
const address = new libsignal.SignalProtocolAddress(number, deviceId);
// Instead of deleting the sessions now,
// we process the new prekeys and initiate a new session.
// The old sessions will get deleted once the correspondant
// has switch the the new session.
const [preKey, signedPreKey] = await Promise.all([
textsecure.storage.protocol.loadContactPreKey(number),
textsecure.storage.protocol.loadContactSignedPreKey(number),
]);
if (preKey === undefined || signedPreKey === undefined) {
return;
}
const device = {
identityKey,
deviceId,
preKey,
signedPreKey,
registrationId: 0,
};
const builder = new libsignal.SessionBuilder(
textsecure.storage.protocol,
address
);
await builder.processPreKey(device);
})
);
await conversation.onSessionResetReceived();
},
processDecrypted(envelope, decrypted) {

@ -159,7 +159,7 @@ window.setPassword = (passPhrase, oldPhrase) =>
});
window.passwordUtil = require('./app/password_util');
window.session = require('./ts/session');
window.libsession = require('./ts/session');
// We never do these in our code, so we'll prevent it everywhere
window.open = () => null;

Loading…
Cancel
Save