aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/e2ee.h21
-rw-r--r--lib/encryptionmanager.cpp26
-rw-r--r--lib/events/encryptionevent.cpp15
3 files changed, 39 insertions, 23 deletions
diff --git a/lib/e2ee.h b/lib/e2ee.h
new file mode 100644
index 00000000..f663ddc3
--- /dev/null
+++ b/lib/e2ee.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <QtCore/QStringList>
+
+namespace QMatrixClient
+{
+ static const auto AlgorithmKeyL = "algorithm"_ls;
+ static const auto RotationPeriodMsKeyL = "rotation_period_ms"_ls;
+ static const auto RotationPeriodMsgsKeyL = "rotation_period_msgs"_ls;
+
+ static const auto AlgorithmKey = QStringLiteral("algorithm");
+ static const auto RotationPeriodMsKey = QStringLiteral("rotation_period_ms");
+ static const auto RotationPeriodMsgsKey = QStringLiteral("rotation_period_msgs");
+
+ static const auto Ed25519Key = QStringLiteral("ed25519");
+ static const auto Curve25519Key = QStringLiteral("curve25519");
+ static const auto SignedCurve25519Key = QStringLiteral("signed_curve25519");
+ static const auto OlmV1Curve25519AesSha2AlgoKey = QStringLiteral("m.olm.v1.curve25519-aes-sha2");
+ static const auto MegolmV1AesSha2AlgoKey = QStringLiteral("m.megolm.v1.aes-sha2");
+ static const QStringList SupportedAlgorithms = { OlmV1Curve25519AesSha2AlgoKey, MegolmV1AesSha2AlgoKey };
+} // namespace QMatrixClient
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index 50db9889..08b68911 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -8,18 +8,12 @@
#include "csapi/keys.h"
#include "connection.h"
+#include "e2ee.h"
using namespace QMatrixClient;
using namespace QtOlm;
using std::move;
-static const auto ed25519Name = QStringLiteral("ed25519");
-static const auto Curve25519Name = QStringLiteral("curve25519");
-static const auto SignedCurve25519Name = QStringLiteral("signed_curve25519");
-static const auto OlmV1Curve25519AesSha2AlgoName = QStringLiteral("m.olm.v1.curve25519-aes-sha2");
-static const auto MegolmV1AesSha2AlgoName = QStringLiteral("m.megolm.v1.aes-sha2");
-static const QStringList SupportedAlgorithms = { OlmV1Curve25519AesSha2AlgoName, MegolmV1AesSha2AlgoName };
-
class EncryptionManager::Private
{
public:
@@ -49,8 +43,8 @@ class EncryptionManager::Private
targetKeysNumber = olmAccount->maxOneTimeKeys(); // 2 // see note below
targetOneTimeKeyCounts =
{
- {SignedCurve25519Name, qRound(signedKeysProportion * targetKeysNumber)},
- {Curve25519Name, qRound((1-signedKeysProportion) * targetKeysNumber)}
+ {SignedCurve25519Key, qRound(signedKeysProportion * targetKeysNumber)},
+ {Curve25519Key, qRound((1-signedKeysProportion) * targetKeysNumber)}
};
}
~Private() = default;
@@ -104,11 +98,11 @@ void EncryptionManager::uploadIdentityKeys(Connection* connection)
*/
{
{
- Curve25519Name + QStringLiteral(":") + connection->deviceId(),
+ Curve25519Key + QStringLiteral(":") + connection->deviceId(),
d->olmAccount->curve25519IdentityKey()
},
{
- ed25519Name + QStringLiteral(":") + connection->deviceId(),
+ Ed25519Key + QStringLiteral(":") + connection->deviceId(),
d->olmAccount->ed25519IdentityKey()
}
},
@@ -133,7 +127,7 @@ void EncryptionManager::uploadIdentityKeys(Connection* connection)
connection->userId(),
{
{
- ed25519Name + QStringLiteral(":") + connection->deviceId(),
+ Ed25519Key + QStringLiteral(":") + connection->deviceId(),
d->olmAccount->sign(deviceKeysJsonObject)
}
}
@@ -158,8 +152,8 @@ void EncryptionManager::uploadOneTimeKeys(Connection* connection, bool forceUpda
}
- int signedKeysToUploadCount = d->oneTimeKeysToUploadCounts.value(SignedCurve25519Name, 0);
- int unsignedKeysToUploadCount = d->oneTimeKeysToUploadCounts.value(Curve25519Name, 0);
+ int signedKeysToUploadCount = d->oneTimeKeysToUploadCounts.value(SignedCurve25519Key, 0);
+ int unsignedKeysToUploadCount = d->oneTimeKeysToUploadCounts.value(Curve25519Key, 0);
d->olmAccount->generateOneTimeKeys(signedKeysToUploadCount + unsignedKeysToUploadCount);
@@ -179,11 +173,11 @@ void EncryptionManager::uploadOneTimeKeys(Connection* connection, bool forceUpda
{QStringLiteral("key"), it.value().toString()}
};
key = d->olmAccount->sign(message);
- keyType = SignedCurve25519Name;
+ keyType = SignedCurve25519Key;
} else {
key = it.value();
- keyType = Curve25519Name;
+ keyType = Curve25519Key;
}
++oneTimeKeysCounter;
oneTimeKeys.insert(QString("%1:%2").arg(keyType).arg(keyId), key);
diff --git a/lib/events/encryptionevent.cpp b/lib/events/encryptionevent.cpp
index b8e2b575..ee6c92b1 100644
--- a/lib/events/encryptionevent.cpp
+++ b/lib/events/encryptionevent.cpp
@@ -7,11 +7,12 @@
#include "converters.h"
#include "logging.h"
+#include "e2ee.h"
#include <array>
static const std::array<QString, 1> encryptionStrings = { {
- QStringLiteral("m.megolm.v1.aes-sha2")
+ QMatrixClient::MegolmV1AesSha2AlgoKey
} };
namespace QMatrixClient {
@@ -36,9 +37,9 @@ using namespace QMatrixClient;
EncryptionEventContent::EncryptionEventContent(const QJsonObject& json)
: encryption(fromJson<EncryptionType>(json["algorithm"_ls]))
- , algorithm(sanitized(json["algorithm"_ls].toString()))
- , rotationPeriodMs(json["rotation_period_ms"_ls].toInt(604800000))
- , rotationPeriodMsgs(json["rotation_period_msgs"_ls].toInt(100))
+ , algorithm(sanitized(json[AlgorithmKeyL].toString()))
+ , rotationPeriodMs(json[RotationPeriodMsKeyL].toInt(604800000))
+ , rotationPeriodMsgs(json[RotationPeriodMsgsKeyL].toInt(100))
{ }
void EncryptionEventContent::fillJson(QJsonObject* o) const
@@ -47,7 +48,7 @@ void EncryptionEventContent::fillJson(QJsonObject* o) const
Q_ASSERT_X(encryption != EncryptionType::Undefined, __FUNCTION__,
"The key 'algorithm' must be explicit in EncryptionEventContent");
if (encryption != EncryptionType::Undefined)
- o->insert(QStringLiteral("algorithm"), algorithm);
- o->insert(QStringLiteral("rotation_period_ms"), rotationPeriodMs);
- o->insert(QStringLiteral("rotation_period_msgs"), rotationPeriodMsgs);
+ o->insert(AlgorithmKey, algorithm);
+ o->insert(RotationPeriodMsKey, rotationPeriodMs);
+ o->insert(RotationPeriodMsgsKey, rotationPeriodMsgs);
}