Skip to content

Commit 81d494a

Browse files
committed
check that our encryption settings are going to work for e2e encryption
Signed-off-by: Matthieu Gallien <[email protected]>
1 parent 32ca06d commit 81d494a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/libsync/clientsideencryption.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,13 @@ void ClientSideEncryption::initializeHardwareTokenEncryption(const AccountPtr &a
12071207
<< "label:" << _tokenPublicKey->label
12081208
<< "need login:" << (_tokenPublicKey->needLogin ? "true" : "false");
12091209

1210+
if (!checkEncryptionIsWorking(account)) {
1211+
qCWarning(lcCse()) << "encryption is not properly setup";
1212+
1213+
failedToInitialize(account);
1214+
return;
1215+
}
1216+
12101217
emit initializationFinished();
12111218
}
12121219

@@ -1277,6 +1284,31 @@ bool ClientSideEncryption::checkPublicKeyValidity(const AccountPtr &account) con
12771284
return true;
12781285
}
12791286

1287+
bool ClientSideEncryption::checkEncryptionIsWorking(const AccountPtr &account) const
1288+
{
1289+
QByteArray data = EncryptionHelper::generateRandom(64);
1290+
1291+
auto encryptedData = EncryptionHelper::encryptStringAsymmetric(*account->e2e(), data);
1292+
if (!encryptedData) {
1293+
qCWarning(lcCse()) << "encryption error";
1294+
return false;
1295+
}
1296+
1297+
const auto decryptionResult = EncryptionHelper::decryptStringAsymmetric(*account->e2e(), *encryptedData);
1298+
if (!decryptionResult) {
1299+
qCWarning(lcCse()) << "encryption error";
1300+
return false;
1301+
}
1302+
QByteArray decryptResult = QByteArray::fromBase64(*decryptionResult);
1303+
1304+
if (data != decryptResult) {
1305+
qCInfo(lcCse()) << "invalid private key";
1306+
return false;
1307+
}
1308+
1309+
return true;
1310+
}
1311+
12801312
bool ClientSideEncryption::checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const
12811313
{
12821314
Bio serverPublicKeyBio;

src/libsync/clientsideencryption.h

+2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ private slots:
238238
[[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const;
239239
[[nodiscard]] bool sensitiveDataRemaining() const;
240240

241+
[[nodiscard]] bool checkEncryptionIsWorking(const AccountPtr &account) const;
242+
241243
void failedToInitialize(const AccountPtr &account);
242244

243245
QByteArray _privateKey;

0 commit comments

Comments
 (0)