From 9a44ae1fa59d09ae83a05149b4f16b4633ab28af Mon Sep 17 00:00:00 2001 From: blue Date: Sun, 17 Nov 2024 20:25:33 +0200 Subject: [PATCH] SimpleCrypt password jamming is now optional --- CMakeLists.txt | 9 +++++-- core/squawk.cpp | 22 ++++++++++++++--- core/squawk.h | 1 - shared/global.cpp | 44 ++++++++++++++++++--------------- shared/global.h | 2 +- ui/widgets/accounts/account.cpp | 23 +++++++++-------- 6 files changed, 62 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b00bfc..b537fe0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ option(WITH_KWALLET "Build KWallet support module" ON) option(WITH_KIO "Build KIO support module" ON) option(WITH_KCONFIG "Build KConfig support module" ON) option(WITH_OMEMO "Build OMEMO support module" OFF) #it should be off by default untill I sort the problems out +option(WITH_SIMPLE_CRYPT "Builds with SimpleCrypt to obfuscate password" ON) # Dependencies ## Qt @@ -176,13 +177,18 @@ target_link_libraries(squawk Qt${QT_VERSION_MAJOR}::Xml LMDBAL::LMDBAL QXmpp::QXmpp - simpleCrypt ) if (WITH_OMEMO) target_link_libraries(squawk PRIVATE QXmpp::Omemo) endif () +if (WITH_SIMPLE_CRYPT) + target_compile_definitions(squawk PRIVATE WITH_SIMPLE_CRYPT) + add_subdirectory(external/simpleCrypt) + target_link_libraries(squawk PRIVATE simpleCrypt) +endif () + ## Link thread libraries on Linux if(UNIX AND NOT APPLE) set(THREADS_PREFER_PTHREAD_FLAG ON) @@ -219,7 +225,6 @@ add_compile_definitions(PLUGIN_PATH="${PLUGIN_PATH}") add_subdirectory(main) add_subdirectory(core) -add_subdirectory(external/simpleCrypt) add_subdirectory(packaging) add_subdirectory(plugins) add_subdirectory(resources) diff --git a/core/squawk.cpp b/core/squawk.cpp index 1888487..5978651 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -22,6 +22,10 @@ #include #include +#ifdef WITH_SIMPLE_CRYPT +#include "external/simpleCrypt/simplecrypt.h" +#endif + Core::Squawk::Squawk(QObject* parent): QObject(parent), accounts(), @@ -71,7 +75,6 @@ void Core::Squawk::stop() { QSettings settings; settings.beginGroup("core"); settings.beginWriteArray("accounts"); - SimpleCrypt crypto(passwordHash); for (std::deque::size_type i = 0; i < accounts.size(); ++i) { settings.setArrayIndex(i); Account* acc = accounts[i]; @@ -84,7 +87,13 @@ void Core::Squawk::stop() { password = acc->getPassword(); break; case Shared::AccountPassword::jammed: - password = crypto.encryptToString(acc->getPassword()); +#ifdef WITH_SIMPLE_CRYPT2 + password = SimpleCrypt(passwordHash).encryptToString(acc->getPassword()); +#else + qDebug() << "The password for account" << acc->getName() << "is set to be jammed, but Squawk was compiled without SimpleCrypt support"; + qDebug("Can not encode password, setting this account to always ask password mode"); + ap = Shared::AccountPassword::alwaysAsk; +#endif break; default: break; @@ -697,17 +706,24 @@ void Core::Squawk::readSettings() { settings.value("passwordType", static_cast(Shared::AccountPassword::plain)).toInt() ); + QString name = settings.value("name").toString(); QString password = settings.value("password", "").toString(); if (passwordType == Shared::AccountPassword::jammed) { +#ifdef WITH_SIMPLE_CRYPT SimpleCrypt crypto(passwordHash); password = crypto.decryptToString(password); +#else + qDebug() << "The password for account" << name << "is jammed, but Squawk was compiled without SimpleCrypt support"; + qDebug("Can not decode password, setting this account to always ask password mode"); + passwordType = Shared::AccountPassword::alwaysAsk; +#endif } addAccount( settings.value("login").toString(), settings.value("server").toString(), password, - settings.value("name").toString(), + name, settings.value("resource").toString(), settings.value("active").toBool(), passwordType diff --git a/core/squawk.h b/core/squawk.h index f00500e..8586498 100644 --- a/core/squawk.h +++ b/core/squawk.h @@ -33,7 +33,6 @@ #include "shared/global.h" #include "shared/info.h" #include "shared/clientinfo.h" -#include "external/simpleCrypt/simplecrypt.h" #include #include diff --git a/shared/global.cpp b/shared/global.cpp index 8277ff5..efa85cf 100644 --- a/shared/global.cpp +++ b/shared/global.cpp @@ -21,6 +21,13 @@ #include "enums.h" #include "ui/models/roster.h" + +#ifdef WITH_SIMPLE_CRYPT +#define SIMPLE_CRYPT_ENABLED true +#else +#define SIMPLE_CRYPT_ENABLED false +#endif + #ifdef WITH_OMEMO constexpr bool OMEMO_SUPPORT = true; #else @@ -36,11 +43,10 @@ QFont getFont (QFontDatabase::SystemFont type, bool bold = false, bool italic = if (factor != 1.0) { float ps = font.pointSizeF(); - if (ps != -1) { + if (ps != -1) font.setPointSizeF(ps * factor); - } else { + else font.setPointSize(font.pointSize() * factor); - } } return font; @@ -148,10 +154,11 @@ Shared::Global::Global(): smallFontMetrics(smallFont), headerFontMetrics(headerFont), titleFontMetrics(titleFont), - pluginSupport({ + optionalFeatures({ {"KWallet", false}, {"openFileManagerWindowJob", false}, - {"colorSchemeTools", false} + {"colorSchemeTools", false}, + {"simpleCryptJammedPassword", SIMPLE_CRYPT_ENABLED} }), fileCache() { @@ -197,8 +204,7 @@ Shared::Global::Global(): static const QSize defaultIconFileInfoHeight(50, 50); -Shared::Global::FileInfo Shared::Global::getFileInfo(const QString& path) -{ +Shared::Global::FileInfo Shared::Global::getFileInfo(const QString& path) { std::map::const_iterator itr = instance->fileCache.find(path); if (itr == instance->fileCache.end()) { QMimeDatabase db; @@ -275,17 +281,17 @@ QString Shared::Global::getName(EncryptionProtocol ep) { } void Shared::Global::setSupported(const QString& pluginName, bool support) { - std::map::iterator itr = instance->pluginSupport.find(pluginName); - if (itr != instance->pluginSupport.end()) { + std::map::iterator itr = instance->optionalFeatures.find(pluginName); + if (itr != instance->optionalFeatures.end()) { itr->second = support; } } bool Shared::Global::supported(const QString& pluginName) { - std::map::iterator itr = instance->pluginSupport.find(pluginName); - if (itr != instance->pluginSupport.end()) { + std::map::iterator itr = instance->optionalFeatures.find(pluginName); + if (itr != instance->optionalFeatures.end()) return itr->second; - } + return false; } @@ -325,11 +331,10 @@ void Shared::Global::highlightInFileManager(const QString& path) QString output = proc.readLine().simplified(); QString folder; - if (info.isDir()) { + if (info.isDir()) folder = info.canonicalFilePath(); - } else { + else folder = info.canonicalPath(); - } if (output.contains(dolphinReg)) { //there is a bug on current (21.04.0) dolphin, it works correct only if you already have dolphin launched @@ -389,20 +394,19 @@ void Shared::Global::setTheme(const QString& path) { } void Shared::Global::setStyle(const QString& style) { - if (style.toLower() == "system") { + if (style.toLower() == "system") QApplication::setStyle(getInstance()->defaultSystemStyle); - } else { + else QApplication::setStyle(style); - } } #define FROM_INT_INPL(Enum) \ template<> \ Enum Shared::Global::fromInt(int src) \ { \ - if (src < static_cast(Enum##Lowest) || src > static_cast(Enum##Highest)) { \ + if (src < static_cast(Enum##Lowest) || src > static_cast(Enum##Highest)) \ throw EnumOutOfRange(#Enum); \ - } \ + \ return static_cast(src); \ } \ template<> \ diff --git a/shared/global.h b/shared/global.h index 6d23c2f..627903f 100644 --- a/shared/global.h +++ b/shared/global.h @@ -135,7 +135,7 @@ namespace Shared { private: static Global* instance; - std::map pluginSupport; + std::map optionalFeatures; std::map fileCache; #ifdef WITH_KIO diff --git a/ui/widgets/accounts/account.cpp b/ui/widgets/accounts/account.cpp index 164af6c..2d70603 100644 --- a/ui/widgets/accounts/account.cpp +++ b/ui/widgets/accounts/account.cpp @@ -26,6 +26,7 @@ Account::Account(): m_ui->setupUi(this); connect(m_ui->passwordType, qOverload(&QComboBox::currentIndexChanged), this, &Account::onComboboxChange); + QStandardItemModel *model = static_cast(m_ui->passwordType->model()); for (int i = static_cast(Shared::AccountPasswordLowest); i < static_cast(Shared::AccountPasswordHighest) + 1; ++i) { Shared::AccountPassword ap = static_cast(i); @@ -34,18 +35,19 @@ Account::Account(): m_ui->passwordType->setCurrentIndex(static_cast(Shared::AccountPassword::plain)); if (!Shared::Global::supported("KWallet")) { - QStandardItemModel *model = static_cast(m_ui->passwordType->model()); QStandardItem *item = model->item(static_cast(Shared::AccountPassword::kwallet)); item->setFlags(item->flags() & ~Qt::ItemIsEnabled); } + + if (!Shared::Global::supported("simpleCryptJammedPassword")) { + QStandardItem *item = model->item(static_cast(Shared::AccountPassword::jammed)); + item->setFlags(item->flags() & ~Qt::ItemIsEnabled); + } } -Account::~Account() -{ -} +Account::~Account() {} -QMap Account::value() const -{ +QMap Account::value() const { QMap map; map["login"] = m_ui->login->text(); map["password"] = m_ui->password->text(); @@ -58,13 +60,11 @@ QMap Account::value() const return map; } -void Account::lockId() -{ +void Account::lockId() { m_ui->name->setReadOnly(true);; } -void Account::setData(const QMap& data) -{ +void Account::setData(const QMap& data) { m_ui->login->setText(data.value("login").toString()); m_ui->password->setText(data.value("password").toString()); m_ui->server->setText(data.value("server").toString()); @@ -73,8 +73,7 @@ void Account::setData(const QMap& data) m_ui->passwordType->setCurrentIndex(data.value("passwordType").toInt()); } -void Account::onComboboxChange(int index) -{ +void Account::onComboboxChange(int index) { QString description = Shared::Global::getDescription(Shared::Global::fromInt(index)); m_ui->comment->setText(description); }