Move the private key salt handling in its own function

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
Kevin Ottens 2020-08-10 11:26:52 +02:00
parent d5339265fb
commit 595eb78c8a
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
3 changed files with 17 additions and 3 deletions

View file

@ -448,6 +448,19 @@ QByteArray decryptPrivateKey(const QByteArray& key, const QByteArray& data) {
return QByteArray::fromBase64(result);
}
QByteArray extractPrivateKeySalt(const QByteArray &data)
{
const auto parts = data.split('|');
qCInfo(lcCse()) << "found parts:" << parts;
if (parts.size() < 3) {
qCInfo(lcCse()) << "Not enough parts found";
return QByteArray();
}
return QByteArray::fromBase64(parts.at(2));
}
QByteArray decryptStringSymmetric(const QByteArray& key, const QByteArray& data) {
qCInfo(lcCse()) << "decryptStringSymmetric key: " << key;
qCInfo(lcCse()) << "decryptStringSymmetric data: " << data;
@ -1135,9 +1148,7 @@ void ClientSideEncryption::decryptPrivateKey(const QByteArray &key) {
qCInfo(lcCse()) << "mnemonic:" << mnemonic;
// split off salt
// Todo better place?
auto pos = key.lastIndexOf('|');
QByteArray salt = QByteArray::fromBase64(key.mid(pos + 1));
const auto salt = EncryptionHelper::extractPrivateKeySalt(key);
auto pass = EncryptionHelper::generatePassword(mnemonic, salt);
qCInfo(lcCse()) << "Generated key:" << pass;

View file

@ -38,6 +38,7 @@ namespace EncryptionHelper {
const QByteArray& key,
const QByteArray& data
);
OWNCLOUDSYNC_EXPORT QByteArray extractPrivateKeySalt(const QByteArray &data);
OWNCLOUDSYNC_EXPORT QByteArray encryptStringSymmetric(
const QByteArray& key,
const QByteArray& data

View file

@ -52,9 +52,11 @@ private slots:
// WHEN
const auto privateKey = EncryptionHelper::decryptPrivateKey(encryptionKey, cipher);
const auto salt = EncryptionHelper::extractPrivateKeySalt(cipher);
// THEN
QCOMPARE(privateKey, originalPrivateKey);
QCOMPARE(salt, originalSalt);
}
void shouldSymmetricEncryptStrings()