fix(sqlite): Encrypt EventIds in the Event Cache SQLite database#6739
Open
Hywan wants to merge 10 commits into
Open
fix(sqlite): Encrypt EventIds in the Event Cache SQLite database#6739Hywan wants to merge 10 commits into
EventIds in the Event Cache SQLite database#6739Hywan wants to merge 10 commits into
Conversation
7676cf5 to
caf0080
Compare
Merging this PR will not alter performance
Comparing |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6739 +/- ##
==========================================
- Coverage 89.92% 89.92% -0.01%
==========================================
Files 398 398
Lines 111310 111378 +68
Branches 111310 111378 +68
==========================================
+ Hits 100101 100159 +58
- Misses 7410 7421 +11
+ Partials 3799 3798 -1 ☔ View full report in Codecov by Harness. |
caf0080 to
9a578d3
Compare
This patch removes useless `super` visibility selector. The `Caches` type is not public, so we don't need to restrict the visibility of these methods here.
This patch introduces the `EncryptableValue` trait to represent usual operations on a value to be encoded by `encrypt_value_data`.
This patch replaces the serialization of the gap's token (in `handle_linked_chunk_updates`) by using the raw string bytes directly.
… adding `Encryption`. Basically, this patch removes the `let this = self.clone()`. This patch solves the following problem: when we need to decode values in a `with_transaction` context, one had to clone `self` to solve the lifetime issues. This was sub-optimal as it clones the entire `SqliteEventCacheStore`. Instead, we introduce the `Encryption` type, that can be cloned cheaply and serve this specific role. The `SqliteEventCacheStore::encode_event` method moved to `Encryption`. Finally, this patch adds `Encryption::decode_event` for the sake of symmetry.
This is an intermediate patch about many small stuff I've fixed in the code.
…s` tables for the Event Cache. This patch encrypts the `EventId` value in the `events` and `event_chunks` tables for the Event Cache database. The `EventId` is transformed as a `String`, and encoded as is. This patch also adds `Encryption::encode_event_id` and `Encryption::encode_room_id` to centralise these operations. The _table name_ for the room ID encoding changes from `keys::LINKED_CHUNKS` to `keys::EVENTS`. This is not a big change but since we are erasing all the data for the Event Cache database, we can do this small change. The biggest change is in `filter_duplicated_events` where we can no longer use the `event_id` value from the `SELECT` as the returned value because it is encrypted and cannot be decrypted. To achieve that, we use the data provided as the parameter of the method to _map_ the encoded value the other way. Before, the algorithm was: - `Vec<EventId>` were the event we want to find duplicates, - run the SQL query selecting all events matching the `event_id`s, - returning the `event_id` from the SQL query And now, the algorithm is: - `Vec<EventId>` were the event we want to find duplicates, - transform it to `Vec<(EventId, Key)>` where `Key` is the encoded event ID, - run the SQl query selecting all events matching the encoded flavour of the `event_id`s, - when found, the SQL query returns the encoded flavour, so we look back in `Vec<(EventId, Key)>` to find the `EventId` from the `Key`.
9a578d3 to
b2ce993
Compare
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch aims at encrypting the
EventIdvalue in the Event Cache database (in the SQLite backend).Best to review this PR one patch at a time.
Signed-off-by: