aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.h
AgeCommit message (Collapse)Author
2022-09-05sendToDevice: fix unintended slicingAlexey Rusakov
Ironically, this slicing would not break anything as all the necessary data are saved in the Event parent class; but the code is very fragile and scary.
2022-09-04concept EventClassAlexey Rusakov
Constrain types to derive from Event (or the chosen class), where applicable.
2022-09-04DEFINE_SIMPLE_EVENT: support custom JSON keysAlexey Rusakov
2022-08-26Merge #547: Implement device verificationAlexey Rusakov
2022-08-25CleanupAlexey Rusakov
2022-08-25More code reorganisationAlexey Rusakov
- Common switchOnType() piece for key verification events is factored out into processIfVerificationEvent() - Bare event JSON removed from KeyVerificationSession into constructors of respective events - Connection::sendToDevice() uses assembleEncryptedContent() introduced in the previous commit - commonSupportedMethods() moved out to .cpp; error/string converters made static
2022-08-25KeyVerificationSession: cleanupAlexey Rusakov
- Use std::chrono for the timeout (it's more readable and less ambiguous) and make it a local variable - Only pass a Connection object once to constructors - Ensure buildability even without E2EE (key verification is disabled in that case) - Reorder #includes - Other cleanup following clang-tidy warnings
2022-08-24Merge branch 'dev' into device-verificationAlexey Rusakov
# Conflicts: # autotests/testfilecrypto.cpp # lib/connection.cpp # lib/connection.h # lib/database.cpp # lib/database.h # lib/e2ee/qolmoutboundsession.cpp # lib/e2ee/qolmoutboundsession.h # lib/eventitem.h # lib/events/encryptedevent.cpp # lib/events/encryptedevent.h # lib/events/encryptedfile.cpp # lib/events/encryptedfile.h # lib/events/keyverificationevent.cpp # lib/events/keyverificationevent.h # lib/events/roomkeyevent.h # lib/room.cpp # lib/room.h
2022-08-05Fix Connection::accountData<>()Alexey Rusakov
The template version has never worked, to the point where instantiating it would immediately lead to FTBFS. The new version returns an event pointer as a simpler fix that would make it usable - in particular, there's no more need to have separate Connection::Private::unpackAccountData(). To simplify the fix, eventCast() has been made more tolerating - passing nullptr to it is processed in an expected (no-op) way now.
2022-06-17Make Connection::sendToDevices() an actual slotAlexey Rusakov
Although Qt 5 didn't complain about that, you could never really use sendToDevices() in its slot (or even invocable) capacity because Qt's meta-type system could not handle move-only UsersToDevicesToEvents. Qt 6 is more stringent; the build fails at trying to instantiate QMetaType for that type (with a rather unhelpful error message thrown by Clang, and more helpful but very verbose diagnostic from MSVC) because it does not provide a copy constructor. However, sendToDevice doesn't really need to have full-blown events in that parameter; just the content of the event is equally fine. This commit does exactly that: replaces UsersToDevicesToEvents with UsersToDevicesToContent that contains QJsonObject's instead of EventPtr's. The code around is updated accordingly. Also: factor out the key event JSON creation from makeMessageEventForSessionKey() because it's the same JSON for each target device; the function therefore is called encryptSessionKeyEvent() now.
2022-05-29Move some Meg/Olm session logic from Room::Private to Connection::PrivateAlexey Rusakov
Functions (Room::Private::)createOlmSession, payloadForUserDevice and sendRoomKeyToDevices don't have a lot to do with the given Room object but deal with quite a few things stored in Connection. This commit moves them to Connection::Private, exposing sendSessionKeyToDevices (the new name for sendRoomKeyToDevices) in Connection so that Room could call it from Room::P::sendMegolmSession(). While moving these over, a few additional things were adjusted: - more functions marked as const - a few functions could be moved now from Connection to Connection::Private - false slots in Connection (such as picklingMode) are moved out of the slots block - keys.yml in Matrix CS API definitions has been adjusted to match the real structure of `/claim` response (see quotient-im/matrix-spec repo); csapi/keys.h has been regenerated accordingly.
2022-05-29Refactor creation of Megolm sessions in RoomAlexey Rusakov
Notably, replace a multi-level hash map with QMultiHash and factor out Room::P::createOlmSession().
2022-05-29Cleanup and address Sonar warningsAlexey Rusakov
2022-05-29Cleanup and fix Sonar warningsAlexey Rusakov
2022-05-29Refactor EncryptedFile and EC::FileInfo::fileAlexey Rusakov
Besides having a misleading name (and it goes back to the spec), EncryptedFile under `file` key preempts the `url` (or `thumbnail_url`) string value so only one of the two should exist. This is a case for using std::variant<> - despite its clumsy syntax, it can actually simplify and streamline code when all the necessary bits are in place (such as conversion to JSON and getting the common piece - the URL - out of it). This commit replaces `FileInfo::url` and `FileInfo::file` with a common field `source` of type `FileSourceInfo` that is an alias for a variant type covering both underlying types; and `url()` is reintroduced as a function instead, to allow simplified access to whichever URL is available inside the variant. Oh, and EncryptedFile is EncryptedFileMetadata now, to clarify that it does not represent the file payload itself but rather the data necessary to obtain that payload.
2022-05-18Make database independent of {Room, User, Connection}Tobias Fella
2022-05-18Apply suggestions from code reviewTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2022-05-16More work; Update olm pickle & timestamps in database; Remove TODOsTobias Fella
2022-05-16Save and load outgoing megolm sessionTobias Fella
2022-05-16Implement sending encrypted messagesTobias Fella
2022-05-14Cleanup across the boardAlexey Rusakov
Mainly driven by clang-tidy and SonarCloud warnings (sadly, SonarCloud doesn't store historical reports so no link can be provided here).
2022-05-02Implement key verificationTobias Fella
2022-04-16Merge branch 'dev' into sendmessagesTobias Fella
2022-04-09Prepare for MSC 3700Tobias Fella
2022-04-09Make sure devices are known before decrypting olm messagesTobias Fella
2022-03-10More work; Update olm pickle & timestamps in database; Remove TODOsTobias Fella
2022-03-10Save and load outgoing megolm sessionTobias Fella
2022-03-10Implement sending encrypted messagesTobias Fella
2022-03-07Store the device's ed25519 in the databaseTobias Fella
2022-02-26Add convenience functions for querying user devices and keys from cacheTobias Fella
2022-02-13Merge branch 'dev'Alexey Rusakov
The result is FTBFS as yet; next commits will fix that, along with a few other things.
2022-02-12Replace QPair with std::pairTobias Fella
2022-02-11Implement more suggestionsTobias Fella
2022-02-07Remove encryptionmanager and various fixesTobias Fella
2022-01-23Omittable: split out from util.h and refreshAlexey Rusakov
Improvements: - Quotient::lift() - a way to invoke a function on an optional (including Omittable) or a pointer if it's 'truthy'. Doesn't need enhanced function_traits<>, only the standard library; works on any number of arguments that can be dereferenced and casted to bool. - then() - the version of lift() as a member function. - edit() was renamed to ensure() (edit() might become a read-write counterpart of then() at some point). It's not really used across libQuotient codebase (or elsewhere) but is staying there just in case. It can also accept an initializer, removing the requirement of default-constructibility. - Quotient::merge() is simplified, with one universal implementation covering both Omittable/optional and plain values. - All that now lives in its dedicated pair of files, further decluttering util.h
2022-01-06Brush up SsoSession; document Connection::prepareForSsoAlexey Rusakov
Although parented to Connection, SsoSession was pretty leaky in that unsuccessful login attempts didn't delete the object and in some errors didn't even close the local HTTP socket (though new connections would no more be accepted). Also, without the documentation it wasn't clear who owns the object returned by Connection::prepareForSso(). Now it is. Unfortunately, it's not easy to cover SsoSession with tests. Basically, it takes a homeserver and a mock "SSO agent" that would check the SSO URL for validity and then both send the login authorisation to the homeserver as well as ping the callback given by SsoSession. Maybe for another time.
2022-01-02Add ImplPtr and makeImplAlexey Rusakov
The original (more complex and comprehensive) solution belongs to https://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html - this commit only provides a small wrapper for non-copyable Private class implementations common throughout libQuotient. Unlike the original, default initialisation is made explicit - you have to pass ZeroImpl<Private>() instead (and I firmly believe it's a good thing: normally pointers to Private should not remain nullptr). The reason ZeroImpl<> is not a template variable is quite simple: unique_ptr is non-copyable and so cannot be initialised from; while a template function will initialise the value in-place thanks to copy elision.
2022-01-02Manage symbols visibility for dynamic linkingAlexey Rusakov
2021-12-29Add QUOTIENT_API throughout non-generated codeAlexey Rusakov
This include all (hopefully) classes/structures and functions that have non-inline definitions, as well as namespaces with Q_NAMESPACE since those have non-inline (as of Qt 5.15) QMetaObject - for that a new macro, QUO_NAMESPACE, has been devised to accommodate the lack of Q_NAMESPACE_EXPORT in Qt before 5.14.
2021-12-28Convert struct LoginFlows to namespaceAlexey Rusakov
Because that's what it really is.
2021-12-27Connection: Simplify room/user factory codeAlexey Rusakov
There's no need to return lambdas where pointers to specialised function templates would work just fine.
2021-12-25Make canChangePassword available from QMLCarl Schwan
2021-12-10Use individual databases for each connectionTobias Fella
2021-12-07Rename "crypto" -> "e2ee"Tobias Fella
2021-12-01Apply more suggestionsTobias Fella
2021-12-01Add function to decrypt notificationsTobias Fella
2021-12-01Move non-cache data to a non-cache locationTobias Fella
2021-12-01Save olm account on shutdownTobias Fella
2021-12-01Add mxc protocol to the networkaccessmanagerTobias Fella
2021-12-01Implement download and decryption of encrypted filesTobias Fella