Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch client side encryption to use sha256 hash algorithm #7780

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "clientsideencryption.h"

Check notice on line 1 in src/libsync/clientsideencryption.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/clientsideencryption.cpp

File src/libsync/clientsideencryption.cpp does not conform to Custom style guidelines. (lines 240, 241, 242, 252, 260, 261, 262, 263, 264, 265, 290, 1447)

#include <openssl/rsa.h>
#include <openssl/evp.h>
Expand Down Expand Up @@ -237,7 +237,32 @@
(const unsigned char *)salt.constData(),// const unsigned char *salt,
salt.size(), // int saltlen,
iterationCount, // int iterations,
EVP_sha1(), // digest algorithm
EVP_sha1(), // deprecated digest algorithm
keyLength, // int keylen,
unsignedData(secretKey)); // unsigned char *out

if (ret != 1) {
qCWarning(lcCse()) << "Failed to generate encryption key";
// Error out?
}

return secretKey;
}

QByteArray deprecatedSha1GeneratePassword(const QString& wordlist, const QByteArray& salt)
{
const auto iterationCount = 600000;
const auto keyStrength = 256;
const auto keyLength = keyStrength / 8;

QByteArray secretKey(keyLength, '\0');

const auto ret = PKCS5_PBKDF2_HMAC(wordlist.toLocal8Bit().constData(), // const char *password,
wordlist.size(), // int password length,
(const unsigned char *)salt.constData(),// const unsigned char *salt,
salt.size(), // int saltlen,
iterationCount, // int iterations,
EVP_sha1(), // deprecated digest algorithm
keyLength, // int keylen,
unsignedData(secretKey)); // unsigned char *out

Expand All @@ -262,7 +287,7 @@
(const unsigned char *)salt.constData(),// const unsigned char *salt,
salt.size(), // int saltlen,
iterationCount, // int iterations,
EVP_sha1(), // digest algorithm
EVP_sha256(), // digest algorithm
keyLength, // int keylen,
unsignedData(secretKey)); // unsigned char *out

Expand Down Expand Up @@ -1419,7 +1444,7 @@
return {result, std::move(keyPair)};
}

ret = X509_REQ_sign(x509_req, privateKey, EVP_sha1()); // return x509_req->signature->length
ret = X509_REQ_sign(x509_req, privateKey, EVP_sha256()); // return x509_req->signature->length
if (ret <= 0){
qCWarning(lcCse()) << "Error signing the csr with the private key";
return {result, std::move(keyPair)};
Expand Down Expand Up @@ -1661,13 +1686,19 @@
const auto salt = EncryptionHelper::extractPrivateKeySalt(key);

const auto deprecatedPassword = EncryptionHelper::deprecatedGeneratePassword(mnemonic, salt);
const auto deprecatedSha1Password = EncryptionHelper::deprecatedSha1GeneratePassword(mnemonic, salt);
const auto password = EncryptionHelper::generatePassword(mnemonic, salt);

const auto privateKey = EncryptionHelper::decryptPrivateKey(password, key);
if (!privateKey.isEmpty()) {
_privateKey = privateKey;
} else {
_privateKey = EncryptionHelper::decryptPrivateKey(deprecatedPassword, key);
const auto deprecatedSha1PrivateKey = EncryptionHelper::decryptPrivateKey(deprecatedSha1Password, key);
if (!privateKey.isEmpty()) {
_privateKey = deprecatedSha1PrivateKey;
} else {
_privateKey = EncryptionHelper::decryptPrivateKey(deprecatedPassword, key);
}
}

if (!_privateKey.isNull() && checkPublicKeyValidity(account)) {
Expand Down
Loading