Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement loading old megolm keys from SSSS #687

Merged
merged 61 commits into from
Mar 16, 2024
Merged

Implement loading old megolm keys from SSSS #687

merged 61 commits into from
Mar 16, 2024

Conversation

TobiasFella
Copy link
Member

@TobiasFella TobiasFella commented Jul 29, 2023

Some security checks are still missing, also a bunch of refactoring and cleanup

Best enjoyed with https://invent.kde.org/network/neochat/-/merge_requests/1111

@sonarcloud
Copy link

sonarcloud bot commented Jul 29, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 13 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@KitsuneRal KitsuneRal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't reviewed the code in detail yet but got one thing to begin with, please.

Quotient/connection.cpp Outdated Show resolved Hide resolved
@TobiasFella TobiasFella changed the title Implement loading key backup from security phrase Implement loading old megolm keys from SSSS Aug 6, 2023
@TobiasFella
Copy link
Member Author

I think this is ready from my side. What's "missing" for a complete SSSS implementation is the "other side" of the whole thing - uploading keys to the backup, etc. - I'll do that in a different merge request.

One thing I'm not sure about is the verified status of the megolm sessions - thing like the is_verified and forwarded fields of the keys from the backup. I fail to see how those would be useful and we thus ignore them entirely so far. When replacing an existing, verified session with a session from the backup (which we only do if the session from the backup has a lower first message index), we manually keep the verified status - This probably won't really happen in practice, though.

@TobiasFella TobiasFella marked this pull request as ready for review August 6, 2023 20:27
@KitsuneRal KitsuneRal mentioned this pull request Aug 8, 2023
TobiasFella and others added 5 commits October 24, 2023 21:02
Using an iterator instead of repeated hashmap lookups is not only
slightly more efficient but also allows to make QOlmInboundSession
constructor private again.
Kitsune Ral and others added 7 commits December 26, 2023 18:38
aesCtr256En/Decrypt used FixedBuffer for the target (encrypted and
decrypted, respectively) buffer. FixedBuffer uses secure memory, and
it is purposefully limited to 64k, because it's meant to be used for
secrets, not for payloads (for now at least). This commit reverts to
using normal QByteArray to store the result, using asWritableCBytes()
to get a span adapter that is more convenient to work with in OpenSSL.
...to work with QUOTIENT_FORCE_NAMESPACED_INCLUDES
1. Instead of templating decryptKey (which effectively emits the same
   function 4 times), just pass the event type as a parameter.
2. Similarly, just use event type strings instead of full-blown Event
   derivatives.
3. requestKeyFromDevices() is pretty much all about doing stuff in
   the Connection context, so move it there.
1. The rename is because it does so much more than just default key
   calculation.
2. Speaking of the default key, it's now only retrieved once, not 5
   times.
3. The default key "event" type definition can be removed now that
   usage of it becomes one-time access of a single key.
Copy link
Member

@KitsuneRal KitsuneRal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more things discovered while messing with refactoring the code.

Quotient/e2ee/sssshandler.cpp Show resolved Hide resolved
Quotient/e2ee/sssshandler.cpp Outdated Show resolved Hide resolved
The method became rather large and with additional error checking would
get even larger - so now the initial preparations concerned with
default key and key description retrieval are put out to
UnlockData::prepare() - a static factory method returning the loaded
information that is used further in the process. That allows to put
the piece concerned with making the key out of the passphrase to
unlockSSSSWithPassphrase() (formerly not quite correctly named as
unlockSSSSFromPassword). More byte_views are introduced, to ensure
correct payload sizes as early (preferably at compile time) as possible.
Fixes building on macOS.
Also: fix failing to jump over the result-using code in case of failing
to decrypt the session.
@KitsuneRal
Copy link
Member

This now looks ready from my side, too. Sorry for taking plenty of time to polish the code, I trust it was worth it though. Let me know if you're good to go with this.

KitsuneRal
KitsuneRal previously approved these changes Mar 14, 2024
@KitsuneRal KitsuneRal merged commit 58d3445 into dev Mar 16, 2024
8 of 12 checks passed
@KitsuneRal KitsuneRal deleted the tobias/ssss branch March 16, 2024 07:45
@KitsuneRal KitsuneRal linked an issue Mar 20, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or change request for the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support pulling older Megolm sessions from other parties/devices
3 participants