mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 21:15:55 +03:00
Move the private key salt handling in its own function
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
parent
d5339265fb
commit
595eb78c8a
3 changed files with 17 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue