Page MenuHomePhabricator

[lib] Restart session when any Olm error is thrown
AcceptedPublic

Authored by angelika on Mon, Oct 21, 6:20 AM.
Tags
None
Referenced Files
F3030585: D13757.id.diff
Mon, Oct 21, 9:09 AM
F3029539: D13757.id45289.diff
Mon, Oct 21, 7:43 AM
F3029446: D13757.id45289.diff
Mon, Oct 21, 7:41 AM
F3029444: D13757.id.diff
Mon, Oct 21, 7:40 AM
F3029114: D13757.diff
Mon, Oct 21, 7:12 AM
F3029113: D13757.diff
Mon, Oct 21, 7:12 AM
Subscribers

Details

Reviewers
kamil
tomek
ashoat
Summary

This diff restarts session when any Olm error is thrown by throwing an exception with OLM_ERROR flag set if error occured when decrypting the message.
If flag is included in the exception then the session is reset.

https://linear.app/comm/issue/ENG-9729/session-not-reset-after-getting-bad-message-mac

Test Plan
  1. Simulate BAD_MESSAGE_MAC by changing the last 3 characters of the message passed to session.decrypt() in the code
  2. Verify in the logs that BAD_MESSAGE_MAC is thrown and session is reset.

Diff Detail

Repository
rCOMM Comm
Branch
graszka22/ENG-9729
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

lib/tunnelbroker/use-peer-to-peer-message-handler.js
307 ↗(On Diff #45289)

I realize that this issue existed before, but there is a risk here... if the code throws a primitive (eg. throw 5), then we will get an error when trying to dereference 5.message

This can be mitigated by using getMessageForException. Given this pattern exists in the DMs code in more places than just here, perhaps it should be handled in a separate diff.

native/cpp/CommonCpp/CryptoTools/Session.cpp
177 ↗(On Diff #45289)

Given that OLM_ERROR has some magical importance, I think we should do more to make sure that somebody doesn't change it.

When we have two constants that need to match between two parts of the codebase, usually we add a code comment referring to the other location, and telling the reader to not change one location without changing the other.

Could you:

  1. Factor this out into a constant
  2. Add a code comment to the constant's definition, as well as the definition in olm-utils.js. Each comment should point to the other location, and should caution the reader to not change one without changing the other

Extract OLM_ERROR_FLAG to constant and add comments

ashoat added inline comments.
native/cpp/CommonCpp/CryptoTools/Session.h
20

Should this be static?

This revision is now accepted and ready to land.Mon, Oct 21, 1:35 PM