Skip to content
Open
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
69 changes: 40 additions & 29 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QDebug>
#include <QThread>
#include <QRegularExpression>
#include <QSettings>

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -478,41 +479,51 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted

// Being in a while loop, we don't want to check the same file multiple times
if (!isDotenvChecked) {
QFile databaseFile(filePath);
QFileInfo databaseFileInfo(databaseFile);
const QFileInfo databaseFileInfo(filePath);

QString databaseDirectoryPath = databaseFileInfo.dir().path();
QString databaseFileName(databaseFileInfo.fileName());
QDir searchDirectory(databaseFileInfo.absoluteDir());
const QString databaseFileName(databaseFileInfo.fileName());

QString dotenvFilePath = databaseDirectoryPath + "/.env";
QSettings dotenv(dotenvFilePath, QSettings::IniFormat);
while (true)
Comment thread
revolter marked this conversation as resolved.
{
const QString dotenvFilePath = searchDirectory.filePath(".env");
if (QFile::exists(dotenvFilePath))
{
const QSettings dotenv(dotenvFilePath, QSettings::IniFormat);
const QVariant passwordValue = dotenv.value(databaseFileName);

QVariant passwordValue = dotenv.value(databaseFileName);
foundDotenvPassword = !passwordValue.isNull();

foundDotenvPassword = !passwordValue.isNull();
isDotenvChecked = true;
if (foundDotenvPassword)
{
const std::string password = passwordValue.toString().toStdString();

const QVariant keyFormatValue = dotenv.value(databaseFileName + "_keyFormat", QVariant(CipherSettings::KeyFormats::Passphrase));
const CipherSettings::KeyFormats keyFormat = CipherSettings::getKeyFormat(keyFormatValue.toInt());

const int pageSize = dotenv.value(databaseFileName + "_pageSize", enc_default_page_size).toInt();
const int kdfIterations = dotenv.value(databaseFileName + "_kdfIter", enc_default_kdf_iter).toInt();
const int plaintextHeaderSize = dotenv.value(databaseFileName + "_plaintextHeaderSize", enc_default_plaintext_header_size).toInt();
const std::string hmacAlgorithm = dotenv.value(databaseFileName + "_hmacAlgorithm", QString::fromStdString(enc_default_hmac_algorithm)).toString().toStdString();
const std::string kdfAlgorithm = dotenv.value(databaseFileName + "_kdfAlgorithm", QString::fromStdString(enc_default_kdf_algorithm)).toString().toStdString();

cipherSettings->setKeyFormat(keyFormat);
cipherSettings->setPassword(password);
cipherSettings->setPageSize(pageSize);
cipherSettings->setKdfIterations(kdfIterations);
cipherSettings->setHmacAlgorithm("HMAC_" + hmacAlgorithm);
cipherSettings->setKdfAlgorithm("PBKDF2_HMAC_" + kdfAlgorithm);
cipherSettings->setPlaintextHeaderSize(plaintextHeaderSize);

break;
}
}

if (foundDotenvPassword)
{
std::string password = passwordValue.toString().toStdString();

QVariant keyFormatValue = dotenv.value(databaseFileName + "_keyFormat", QVariant(CipherSettings::KeyFormats::Passphrase));
CipherSettings::KeyFormats keyFormat = CipherSettings::getKeyFormat(keyFormatValue.toInt());

int pageSize = dotenv.value(databaseFileName + "_pageSize", enc_default_page_size).toInt();
int kdfIterations = dotenv.value(databaseFileName + "_kdfIter", enc_default_kdf_iter).toInt();
int plaintextHeaderSize = dotenv.value(databaseFileName + "_plaintextHeaderSize", enc_default_plaintext_header_size).toInt();
std::string hmacAlgorithm = dotenv.value(databaseFileName + "_hmacAlgorithm", QString::fromStdString(enc_default_hmac_algorithm)).toString().toStdString();
std::string kdfAlgorithm = dotenv.value(databaseFileName + "_kdfAlgorithm", QString::fromStdString(enc_default_kdf_algorithm)).toString().toStdString();

cipherSettings->setKeyFormat(keyFormat);
cipherSettings->setPassword(password);
cipherSettings->setPageSize(pageSize);
cipherSettings->setKdfIterations(kdfIterations);
cipherSettings->setHmacAlgorithm("HMAC_" + hmacAlgorithm);
cipherSettings->setKdfAlgorithm("PBKDF2_HMAC_" + kdfAlgorithm);
cipherSettings->setPlaintextHeaderSize(plaintextHeaderSize);
if (!searchDirectory.cdUp())
break;
}

isDotenvChecked = true;
}

if(foundDotenvPassword)
Expand Down
Loading