1
0
forked from blue/squawk

SimpleCrypt password jamming is now optional

This commit is contained in:
Blue 2024-11-17 20:25:33 +02:00
parent 85ff6c25ba
commit 9a44ae1fa5
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
6 changed files with 62 additions and 39 deletions

View File

@ -35,6 +35,7 @@ option(WITH_KWALLET "Build KWallet support module" ON)
option(WITH_KIO "Build KIO support module" ON) option(WITH_KIO "Build KIO support module" ON)
option(WITH_KCONFIG "Build KConfig 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_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 # Dependencies
## Qt ## Qt
@ -176,13 +177,18 @@ target_link_libraries(squawk
Qt${QT_VERSION_MAJOR}::Xml Qt${QT_VERSION_MAJOR}::Xml
LMDBAL::LMDBAL LMDBAL::LMDBAL
QXmpp::QXmpp QXmpp::QXmpp
simpleCrypt
) )
if (WITH_OMEMO) if (WITH_OMEMO)
target_link_libraries(squawk PRIVATE QXmpp::Omemo) target_link_libraries(squawk PRIVATE QXmpp::Omemo)
endif () 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 ## Link thread libraries on Linux
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
@ -219,7 +225,6 @@ add_compile_definitions(PLUGIN_PATH="${PLUGIN_PATH}")
add_subdirectory(main) add_subdirectory(main)
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(external/simpleCrypt)
add_subdirectory(packaging) add_subdirectory(packaging)
add_subdirectory(plugins) add_subdirectory(plugins)
add_subdirectory(resources) add_subdirectory(resources)

View File

@ -22,6 +22,10 @@
#include <QDir> #include <QDir>
#include <QStandardPaths> #include <QStandardPaths>
#ifdef WITH_SIMPLE_CRYPT
#include "external/simpleCrypt/simplecrypt.h"
#endif
Core::Squawk::Squawk(QObject* parent): Core::Squawk::Squawk(QObject* parent):
QObject(parent), QObject(parent),
accounts(), accounts(),
@ -71,7 +75,6 @@ void Core::Squawk::stop() {
QSettings settings; QSettings settings;
settings.beginGroup("core"); settings.beginGroup("core");
settings.beginWriteArray("accounts"); settings.beginWriteArray("accounts");
SimpleCrypt crypto(passwordHash);
for (std::deque<Account*>::size_type i = 0; i < accounts.size(); ++i) { for (std::deque<Account*>::size_type i = 0; i < accounts.size(); ++i) {
settings.setArrayIndex(i); settings.setArrayIndex(i);
Account* acc = accounts[i]; Account* acc = accounts[i];
@ -84,7 +87,13 @@ void Core::Squawk::stop() {
password = acc->getPassword(); password = acc->getPassword();
break; break;
case Shared::AccountPassword::jammed: 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; break;
default: default:
break; break;
@ -697,17 +706,24 @@ void Core::Squawk::readSettings() {
settings.value("passwordType", static_cast<int>(Shared::AccountPassword::plain)).toInt() settings.value("passwordType", static_cast<int>(Shared::AccountPassword::plain)).toInt()
); );
QString name = settings.value("name").toString();
QString password = settings.value("password", "").toString(); QString password = settings.value("password", "").toString();
if (passwordType == Shared::AccountPassword::jammed) { if (passwordType == Shared::AccountPassword::jammed) {
#ifdef WITH_SIMPLE_CRYPT
SimpleCrypt crypto(passwordHash); SimpleCrypt crypto(passwordHash);
password = crypto.decryptToString(password); 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( addAccount(
settings.value("login").toString(), settings.value("login").toString(),
settings.value("server").toString(), settings.value("server").toString(),
password, password,
settings.value("name").toString(), name,
settings.value("resource").toString(), settings.value("resource").toString(),
settings.value("active").toBool(), settings.value("active").toBool(),
passwordType passwordType

View File

@ -33,7 +33,6 @@
#include "shared/global.h" #include "shared/global.h"
#include "shared/info.h" #include "shared/info.h"
#include "shared/clientinfo.h" #include "shared/clientinfo.h"
#include "external/simpleCrypt/simplecrypt.h"
#include <core/components/clientcache.h> #include <core/components/clientcache.h>
#include <core/components/networkaccess.h> #include <core/components/networkaccess.h>

View File

@ -21,6 +21,13 @@
#include "enums.h" #include "enums.h"
#include "ui/models/roster.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 #ifdef WITH_OMEMO
constexpr bool OMEMO_SUPPORT = true; constexpr bool OMEMO_SUPPORT = true;
#else #else
@ -36,11 +43,10 @@ QFont getFont (QFontDatabase::SystemFont type, bool bold = false, bool italic =
if (factor != 1.0) { if (factor != 1.0) {
float ps = font.pointSizeF(); float ps = font.pointSizeF();
if (ps != -1) { if (ps != -1)
font.setPointSizeF(ps * factor); font.setPointSizeF(ps * factor);
} else { else
font.setPointSize(font.pointSize() * factor); font.setPointSize(font.pointSize() * factor);
}
} }
return font; return font;
@ -148,10 +154,11 @@ Shared::Global::Global():
smallFontMetrics(smallFont), smallFontMetrics(smallFont),
headerFontMetrics(headerFont), headerFontMetrics(headerFont),
titleFontMetrics(titleFont), titleFontMetrics(titleFont),
pluginSupport({ optionalFeatures({
{"KWallet", false}, {"KWallet", false},
{"openFileManagerWindowJob", false}, {"openFileManagerWindowJob", false},
{"colorSchemeTools", false} {"colorSchemeTools", false},
{"simpleCryptJammedPassword", SIMPLE_CRYPT_ENABLED}
}), }),
fileCache() fileCache()
{ {
@ -197,8 +204,7 @@ Shared::Global::Global():
static const QSize defaultIconFileInfoHeight(50, 50); 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<QString, FileInfo>::const_iterator itr = instance->fileCache.find(path); std::map<QString, FileInfo>::const_iterator itr = instance->fileCache.find(path);
if (itr == instance->fileCache.end()) { if (itr == instance->fileCache.end()) {
QMimeDatabase db; QMimeDatabase db;
@ -275,17 +281,17 @@ QString Shared::Global::getName(EncryptionProtocol ep) {
} }
void Shared::Global::setSupported(const QString& pluginName, bool support) { void Shared::Global::setSupported(const QString& pluginName, bool support) {
std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName); std::map<QString, bool>::iterator itr = instance->optionalFeatures.find(pluginName);
if (itr != instance->pluginSupport.end()) { if (itr != instance->optionalFeatures.end()) {
itr->second = support; itr->second = support;
} }
} }
bool Shared::Global::supported(const QString& pluginName) { bool Shared::Global::supported(const QString& pluginName) {
std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName); std::map<QString, bool>::iterator itr = instance->optionalFeatures.find(pluginName);
if (itr != instance->pluginSupport.end()) { if (itr != instance->optionalFeatures.end())
return itr->second; return itr->second;
}
return false; return false;
} }
@ -325,11 +331,10 @@ void Shared::Global::highlightInFileManager(const QString& path)
QString output = proc.readLine().simplified(); QString output = proc.readLine().simplified();
QString folder; QString folder;
if (info.isDir()) { if (info.isDir())
folder = info.canonicalFilePath(); folder = info.canonicalFilePath();
} else { else
folder = info.canonicalPath(); folder = info.canonicalPath();
}
if (output.contains(dolphinReg)) { if (output.contains(dolphinReg)) {
//there is a bug on current (21.04.0) dolphin, it works correct only if you already have dolphin launched //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) { void Shared::Global::setStyle(const QString& style) {
if (style.toLower() == "system") { if (style.toLower() == "system")
QApplication::setStyle(getInstance()->defaultSystemStyle); QApplication::setStyle(getInstance()->defaultSystemStyle);
} else { else
QApplication::setStyle(style); QApplication::setStyle(style);
}
} }
#define FROM_INT_INPL(Enum) \ #define FROM_INT_INPL(Enum) \
template<> \ template<> \
Enum Shared::Global::fromInt(int src) \ Enum Shared::Global::fromInt(int src) \
{ \ { \
if (src < static_cast<int>(Enum##Lowest) || src > static_cast<int>(Enum##Highest)) { \ if (src < static_cast<int>(Enum##Lowest) || src > static_cast<int>(Enum##Highest)) \
throw EnumOutOfRange(#Enum); \ throw EnumOutOfRange(#Enum); \
} \ \
return static_cast<Enum>(src); \ return static_cast<Enum>(src); \
} \ } \
template<> \ template<> \

View File

@ -135,7 +135,7 @@ namespace Shared {
private: private:
static Global* instance; static Global* instance;
std::map<QString, bool> pluginSupport; std::map<QString, bool> optionalFeatures;
std::map<QString, FileInfo> fileCache; std::map<QString, FileInfo> fileCache;
#ifdef WITH_KIO #ifdef WITH_KIO

View File

@ -26,6 +26,7 @@ Account::Account():
m_ui->setupUi(this); m_ui->setupUi(this);
connect(m_ui->passwordType, qOverload<int>(&QComboBox::currentIndexChanged), this, &Account::onComboboxChange); connect(m_ui->passwordType, qOverload<int>(&QComboBox::currentIndexChanged), this, &Account::onComboboxChange);
QStandardItemModel *model = static_cast<QStandardItemModel*>(m_ui->passwordType->model());
for (int i = static_cast<int>(Shared::AccountPasswordLowest); i < static_cast<int>(Shared::AccountPasswordHighest) + 1; ++i) { for (int i = static_cast<int>(Shared::AccountPasswordLowest); i < static_cast<int>(Shared::AccountPasswordHighest) + 1; ++i) {
Shared::AccountPassword ap = static_cast<Shared::AccountPassword>(i); Shared::AccountPassword ap = static_cast<Shared::AccountPassword>(i);
@ -34,18 +35,19 @@ Account::Account():
m_ui->passwordType->setCurrentIndex(static_cast<int>(Shared::AccountPassword::plain)); m_ui->passwordType->setCurrentIndex(static_cast<int>(Shared::AccountPassword::plain));
if (!Shared::Global::supported("KWallet")) { if (!Shared::Global::supported("KWallet")) {
QStandardItemModel *model = static_cast<QStandardItemModel*>(m_ui->passwordType->model());
QStandardItem *item = model->item(static_cast<int>(Shared::AccountPassword::kwallet)); QStandardItem *item = model->item(static_cast<int>(Shared::AccountPassword::kwallet));
item->setFlags(item->flags() & ~Qt::ItemIsEnabled); item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
} }
if (!Shared::Global::supported("simpleCryptJammedPassword")) {
QStandardItem *item = model->item(static_cast<int>(Shared::AccountPassword::jammed));
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
}
} }
Account::~Account() Account::~Account() {}
{
}
QMap<QString, QVariant> Account::value() const QMap<QString, QVariant> Account::value() const {
{
QMap<QString, QVariant> map; QMap<QString, QVariant> map;
map["login"] = m_ui->login->text(); map["login"] = m_ui->login->text();
map["password"] = m_ui->password->text(); map["password"] = m_ui->password->text();
@ -58,13 +60,11 @@ QMap<QString, QVariant> Account::value() const
return map; return map;
} }
void Account::lockId() void Account::lockId() {
{
m_ui->name->setReadOnly(true);; m_ui->name->setReadOnly(true);;
} }
void Account::setData(const QMap<QString, QVariant>& data) void Account::setData(const QMap<QString, QVariant>& data) {
{
m_ui->login->setText(data.value("login").toString()); m_ui->login->setText(data.value("login").toString());
m_ui->password->setText(data.value("password").toString()); m_ui->password->setText(data.value("password").toString());
m_ui->server->setText(data.value("server").toString()); m_ui->server->setText(data.value("server").toString());
@ -73,8 +73,7 @@ void Account::setData(const QMap<QString, QVariant>& data)
m_ui->passwordType->setCurrentIndex(data.value("passwordType").toInt()); 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<Shared::AccountPassword>(index)); QString description = Shared::Global::getDescription(Shared::Global::fromInt<Shared::AccountPassword>(index));
m_ui->comment->setText(description); m_ui->comment->setText(description);
} }