aboutsummaryrefslogtreecommitdiff
path: root/lib/e2ee
AgeCommit message (Collapse)Author
2022-09-26Wrap error reporting into facility macrosAlexey Rusakov
Facility macros to report Olm errors: QOLM_INTERNAL_ERROR[_X], QOLM_FAIL_OR_LOG[_X]
2022-09-26RandomBufferAlexey Rusakov
A convenient abstraction swallowing all the type casts and, more importantly, cleanup on destruction (previous code only cleaned up the buffer upon a successful call to Olm API but not upon an error).
2022-09-26Cleanup across E2EE codeAlexey Rusakov
Notably: - simplified unnecessarily verbose constructs; - formally aligned (no re-numeration was necessary) QOlmMessage::Type with corresponding OLM_ constants; - dropped QOlmSession::encryptMessageType() because it's very sensitive to the order of calling with QOlmSession::encrypt() (and encrypt() itself already calls it and returns the message type); - simplify the return type of pickle() calls that can only fail due to an internal error; - replace const QString& with QStringView or const QByteArray& where appropriate; - use '\0' where it was meant to be instead of '0'.
2022-09-26Replace QOlmError with OlmErrorCodeAlexey Rusakov
QOlmError represents a subset of OlmErrorCode, and the associated fromString() function uses undocumented strings produced inside Olm; meanwhile OlmErrorCode is documented in its own header file. Each QOlm* class now has lastErrorCode() next to lastError() (that, from now, returns a textual representation straight from Olm, not QOlmError enum). Also: including olm/error.h in e2ee/e2ee.h required some rearrangement of the code to make sure non-E2EE configuration still builds.
2022-06-24Fix the just introduced Sonar warningAlexey Rusakov
Too many parameters of the same type in a row.
2022-06-24Start using C++20's designated initializersAlexey Rusakov
2022-06-24Code cleanup and reformattingAlexey Rusakov
2022-06-24Rework SignedOneTimeKey as a QJsonObject wrapperAlexey Rusakov
Since this object has to be verified against a signature it also carries there's a rather specific procedure described in The Spec for that. That procedure basically assumes handling the signed one-time key object as a JSON object, not as a C++ object. And originally Quotient E2EE code was exactly like that (obtaining the right QJsonObject from the job result and handling it as specced) but then one enthusiastic developer (me) decided it's better to use a proper C++ structure - breaking the verification logic along the way. After a couple attempts to fix it, here we are again: SignedOneTimeKey is a proper QJsonObject, and even provides a method returning its JSON in the form prepared for verification (according to the spec).
2022-06-24Fix copy-pasta in signed one-time key JSON dumperAlexey Rusakov
2022-06-22Fix signature verificationAlexey Rusakov
toJson(SignedOneTimeKey) incorrectly generated a "signatures" key mapped to an empty object when no signatures were in the C++ value. Also: fallback keys have an additional flag that also has to be taken into account when verifying signatures.
2022-06-19Add a missing #includeAlexey Rusakov
2022-06-18Move C++-only macros to util.hAlexey Rusakov
This pertains to QUO_IMPLICIT and DECL_DEPRECATED_ENUMERATOR - both can be used with no connection to Qt meta-type system (which is what quotient_common.h is for).
2022-06-18Drop make_array(); use std::to_array() where neededAlexey Rusakov
make_array() has been introduced to cover for shortcomings on macOS and Windows. These shortcomings are no more there, so we can just use the standardrlibrary.
2022-06-04Address Sonar warningsAlexey Rusakov
2022-05-31Merge branch 'dev' into update-api-updateAlexey Rusakov
2022-05-31Tweak QOlmAccount and data structures aroundAlexey Rusakov
This is mainly to plug the definition of a string-to-variant map for one-time keys (see https://spec.matrix.org/v1.2/client-server-api/#key-algorithms) into the CS API generated code (see the "shortcut OneTimeKeys" commit for gtad.yaml); but along with it came considerable streamlining of code in qolmaccount.cpp. Using std::variant to store that map also warranted converters.h to gain support for that type (even wider than toJson() that is already in dev - a non-trivial merge from dev is in order).
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-16Fix build failuresTobias Fella
2022-05-16Save and load outgoing megolm sessionTobias Fella
2022-05-16QOlmExpected and associated refactoringAlexey Rusakov
As mentioned in the commit introducing `Expected`, `QOlmExpected` is simply an alias for `Expected<T, QOlmError>`. This simplifies quite a few function signatures in `QOlm*` classes and collapses unwieldy `std::holds_alternative<>`/`std::get<>` constructs into a neat contextual bool cast and an invocation of `operator*` or `value()`/`error()` accessors that don't need to specify the type. While refactoring the code, I found a couple of cases of mismatching `uint32_t` and `qint32_t` in return values; a couple of cases where `decrypt()` returns `QString` which is in fact `QByteArray` (e.g., in `QOlmSession::decrypt()`); there's a repetitive algorithm in `Connection::Private::sessionDecryptPrekey()` and `sessionDecryptGeneral()`
2022-05-16Simplify QOlmSession::matchesInboundSession*()Alexey Rusakov
There's no particular use in letting `QOlmError` out, only to confirm that, well, `QOlmError` is just another form of no-match.
2022-05-16QOlmAccount::needsSave() shouldn't be constAlexey Rusakov
Making Qt signals const is an impossible commitment - once the signal is out, you can't control if any called slot will change the emitting class or not. The code compiles but const-ness is not preserved.
2022-05-16Optimise #includes for QOlm* classesAlexey Rusakov
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-04-23SLICE()Alexey Rusakov
Add a macro to make slicing clear in the code and quiet for static analysis.
2022-04-09Prepare for MSC 3700Tobias Fella
2022-02-27Update lib/e2ee/qolmutility.cppTobias Fella
Co-authored-by: Carl Schwan <carl@carlschwan.eu>
2022-02-27Return false instead of error for failed signature checksTobias Fella
2022-02-26Use QOlmMessage::Type in more placesTobias Fella
Make sure that the enum values correspond to the values used in the spec and use them instead of magic constants
2022-02-16isSupportedAlgorithm()Alexey Rusakov
That's a better primitive than just exposing SupportedAlgorithms list.
2022-02-16Use QHash instead of QMapAlexey Rusakov
We don't seem to need sorted associative containers in those cases.
2022-02-16CleanupAlexey Rusakov
A note on switching to QLatin1String for JSON key constants - this is more concise and barely affects (if at all) runtime performance (padding each QChar with zeros is trivial for assignment; and comparison can be done directly with the same performance as for two QStrings).
2022-02-16Add a few missing QUOTIENT_API stanzasAlexey Rusakov
Also, removed Q_GADGET macros from key verification events as those don't seem to do anything (no Q_ENUM/Q_FLAG things, namely).
2022-02-07Remove encryptionmanager and various fixesTobias Fella
2022-02-06Update lib/e2ee/qolmaccount.cppTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2022-02-06Port to QRandomGeneratorTobias Fella
2022-02-06Update lib/e2ee/qolminboundsession.cppTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2021-12-25Remove assertTobias Fella
2021-12-25Update lib/e2ee/qolmoutboundsession.hTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2021-12-25Update lib/e2ee/qolmoutboundsession.hTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2021-12-25Apply suggestionsTobias Fella
2021-12-25Update lib/e2ee/qolmoutboundsession.cppTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2021-12-24Apply suggestionsTobias Fella
2021-12-07Rename "crypto" -> "e2ee"Tobias Fella