From 71290e208d2decab6042ce40b372e9aabfba7cef Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 8 Aug 2021 18:57:38 +0200 Subject: [PATCH] Enable insecure fallback for secret storage --- src/Cache.cpp | 9 ++++++++- src/UserSettingsPage.cpp | 3 --- src/UserSettingsPage.h | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 7996c017..eb9fb028 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -722,8 +722,8 @@ Cache::storeSecret(const std::string name, const std::string secret) auto job = new QKeychain::WritePasswordJob(QCoreApplication::applicationName()); job->setAutoDelete(true); job->setInsecureFallback(true); + job->setSettings(UserSettings::instance()->qsettings()); - // job->setSettings(new QSettings(job)); job->setKey( "matrix." + QString(QCryptographicHash::hash(settings->profile().toUtf8(), QCryptographicHash::Sha256) @@ -731,6 +731,7 @@ Cache::storeSecret(const std::string name, const std::string secret) "." + QString::fromStdString(name)); job->setTextData(QString::fromStdString(secret)); + QObject::connect( job, &QKeychain::WritePasswordJob::finished, @@ -758,11 +759,14 @@ Cache::deleteSecret(const std::string name) QKeychain::DeletePasswordJob job(QCoreApplication::applicationName()); job.setAutoDelete(false); job.setInsecureFallback(true); + job.setSettings(UserSettings::instance()->qsettings()); + job.setKey( "matrix." + QString(QCryptographicHash::hash(settings->profile().toUtf8(), QCryptographicHash::Sha256) .toBase64()) + "." + QString::fromStdString(name)); + // FIXME(Nico): Nested event loops are dangerous. Some other slots may resume in the mean // time! QEventLoop loop; @@ -780,11 +784,14 @@ Cache::secret(const std::string name) QKeychain::ReadPasswordJob job(QCoreApplication::applicationName()); job.setAutoDelete(false); job.setInsecureFallback(true); + job.setSettings(UserSettings::instance()->qsettings()); + job.setKey( "matrix." + QString(QCryptographicHash::hash(settings->profile().toUtf8(), QCryptographicHash::Sha256) .toBase64()) + "." + QString::fromStdString(name)); + // FIXME(Nico): Nested event loops are dangerous. Some other slots may resume in the mean // time! QEventLoop loop; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index ab6ac492..f67c5e2d 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -63,7 +62,6 @@ UserSettings::initialize(std::optional profile) void UserSettings::load(std::optional profile) { - QSettings settings; tray_ = settings.value("user/window/tray", false).toBool(); startInTray_ = settings.value("user/window/start_in_tray", false).toBool(); @@ -601,7 +599,6 @@ UserSettings::applyTheme() void UserSettings::save() { - QSettings settings; settings.beginGroup("user"); settings.beginGroup("window"); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 096aab81..84940e47 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -107,6 +108,8 @@ public: static QSharedPointer instance(); static void initialize(std::optional profile); + QSettings *qsettings() { return &settings; } + enum class Presence { AutomaticPresence, @@ -316,6 +319,8 @@ private: QString homeserver_; QStringList hiddenTags_; + QSettings settings; + static QSharedPointer instance_; };