kutils: do not reparse the kpasswdstore config on get and set

with password stores being giant-locked (so that opening password stores
happens once even with multiple attempts to open before the first has
finished) it can be assumed that kpasswdstore has not been tempered with
even tho that may not hold true (it can be manually edited via text editor
but do not expect support for that)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-21 03:56:04 +02:00
parent 836da4c2ce
commit 1a3f533744
2 changed files with 7 additions and 10 deletions

View file

@ -18,7 +18,6 @@
#include "kpasswdstoreimpl.h"
#include "kstandarddirs.h"
#include "ksettings.h"
#include "kpassworddialog.h"
#include "knewpassworddialog.h"
#include "kmessagebox.h"
@ -59,7 +58,7 @@ KPasswdStoreImpl::KPasswdStoreImpl(const QString &id)
m_timeout(kpasswdstore_passtimeout * 60000),
m_cacheonly(false),
m_storeid(id),
m_passwdstore(KStandardDirs::locateLocal("data", "kpasswdstore"))
m_passwdstore(KStandardDirs::locateLocal("data", "kpasswdstore"), KSettings::SimpleConfig)
#if defined(HAVE_OPENSSL)
, m_opensslkeylen(0),
m_opensslivlen(0),
@ -142,11 +141,10 @@ QString KPasswdStoreImpl::getPasswd(const QByteArray &key, const qlonglong windo
}
bool ok = false;
KSettings ksettings(m_passwdstore, KSettings::SimpleConfig);
QString storekey = m_storeid;
storekey.append(QLatin1Char('/'));
storekey.append(QString::fromLatin1(key.constData(), key.size()));
const QString passwd = ksettings.string(storekey);
const QString passwd = m_passwdstore.string(storekey);
if (passwd.isEmpty()) {
return QString();
}
@ -169,11 +167,10 @@ bool KPasswdStoreImpl::storePasswd(const QByteArray &key, const QString &passwd,
}
bool ok = false;
KSettings ksettings(m_passwdstore, KSettings::SimpleConfig);
QString storekey = m_storeid;
storekey.append(QLatin1Char('/'));
storekey.append(QString::fromLatin1(key.constData(), key.size()));
ksettings.setString(storekey, encryptPasswd(passwd, &ok));
m_passwdstore.setString(storekey, encryptPasswd(passwd, &ok));
return ok;
}
@ -192,10 +189,9 @@ bool KPasswdStoreImpl::ensurePasswd(const qlonglong windowid, const bool showerr
// the only reason to encrypt and decrypt passwords is to obscure them
// for the naked eye, if one can overwrite, delete or otherwise alter
// the password store then there are more possibilities for havoc
KSettings ksettings(m_passwdstore, KSettings::SimpleConfig);
QString storekey = QString::fromLatin1("KPasswdStore/");
storekey.append(m_storeid);
const QString storepasswdhash = ksettings.string(storekey);
const QString storepasswdhash = m_passwdstore.string(storekey);
if (storepasswdhash.isEmpty()) {
KNewPasswordDialog knewpasswddialog(widgetForWindowID(windowid));
knewpasswddialog.setPrompt(i18n("Enter a password for <b>%1</b> password storage", m_storeid));
@ -243,7 +239,7 @@ bool KPasswdStoreImpl::ensurePasswd(const qlonglong windowid, const bool showerr
}
if (storepasswdhash.isEmpty()) {
ksettings.setString(storekey, passhash);
m_passwdstore.setString(storekey, passhash);
return true;
}
if (passhash != storepasswdhash) {

View file

@ -21,6 +21,7 @@
#include "config.h"
#include "kpasswdstore_export.h"
#include "ksettings.h"
#include <QString>
#include <QMap>
@ -55,7 +56,7 @@ private:
qint64 m_timeout;
bool m_cacheonly;
QString m_storeid;
QString m_passwdstore;
KSettings m_passwdstore;
QMap<QByteArray, QString> m_cachemap;
#if defined(HAVE_OPENSSL)