Skip to content

Commit

Permalink
[lib] Do not reset a session when getting already decrypted message
Browse files Browse the repository at this point in the history
Summary:
https://linear.app/comm/issue/ENG-9713/mitigate-risk-of-olm-already-decrypted-or-keys-skipped

Depends on D13900

Test Plan:
This scenario is hard to reproduce normally (tunnelbroker connection needs to be broken in just the right moment)
so:
- test on both native and web, the steps are the same
- comment out this code: https://github.com/CommE2E/comm/blob/9360b1f7fff5269dd3b56af42dc711045d546cca/lib/tunnelbroker/use-confirm-peer-to-peer-message.js#L39-L43 and this code: https://github.com/CommE2E/comm/blob/9360b1f7fff5269dd3b56af42dc711045d546cca/lib/tunnelbroker/peer-to-peer-message-handler.js#L94
- send a message
- restart/refresh the app

Reviewers: tomek, kamil

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13901
  • Loading branch information
graszka22 committed Nov 13, 2024
1 parent 34c732a commit 5759f0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/tunnelbroker/use-peer-to-peer-message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,21 @@ function usePeerToPeerMessageHandler(): (
);
return;
}

if (errorMessage.includes(olmSessionErrors.alreadyDecrypted)) {
const sqliteMessages = await sqliteAPI.getInboundP2PMessagesByID([
messageID,
]);
if (sqliteMessages.length > 0) {
console.log(
'Message skipped because it was already decrypted ' +
`messageId: ${messageID} ` +
`sender: ${message.senderInfo.deviceID}.`,
);
return;
}
}

console.log(
'Error decrypting message from device ' +
`${message.senderInfo.deviceID}: ${errorMessage}`,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/olm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const olmSessionErrors = Object.freeze({
// the corresponding .cpp file
// at `native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp`.
invalidSessionVersion: 'INVALID_SESSION_VERSION',
alreadyDecrypted: `${OLM_SESSION_ERROR_PREFIX}ALREADY_DECRYPTED_OR_KEYS_SKIPPED`,
});

function hasHigherDeviceID(
Expand Down

0 comments on commit 5759f0f

Please sign in to comment.