mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-03-11 08:54:48 +00:00
This plugin implements the Secret Storage specification version 0.2. While running KeePassXC, it acts as a Secret Service server, registered on DBus, so clients like seahorse, python-secretstorage, or other implementations can connect and access the exposed database in KeePassXC. Squashed commits: - Initial code - Add SessionAdaptor and fix build - The skeletons for all dbus objects are in place - Implement collection creation and deletion - Emit collectionChanged signal - Implement app-wise settings page - Implement error message on GUI - Implement settings - Fix uuid to dbus path - Implement app level settings - Add freedesktop logo - Implement database settings page - Change database settings to a treeview - Move all settings read/write to one place - Rename SecretServiceOptionsPage to SettingsWidgetFdoSecrets - Fix selected group can not be saved if the user hasn't click on the item - Show selected group per database in app settings - Disable editing of various readonly widgets - Remove unused warning about non exposed database - Fix method signature on dbus adaptors - Fix type derived from DBusObject not recognized as QDBusContext - Resolve a few TODOs around error handling - Remove const when passing DBus exposed objects - Move dismiss to PromptBase - Implement per collection locking/unlocking - Fix const correctness on Item::setSecret - Implement SecretService::getSecrets - Rework the signal connections around collections. - Remove generateId from DBusObject - Per spec, use encoded label as DBus object path for collections - Fix some corner cases around collection name changes - Implement alias - Fix wrong alias dbus path - Implement encryption per spec - Cleanup SessionCipher - Implement searchItems for SecretService - Use Tools::uuidToHex - Implement Item attributes and delete - Implement createItem - Always check if the database is unlocked before perform any operation - Add missing ReadAlias/SetAlias on service - Reorganize and fix OpenSession always returning empty output - Overhaul error handling - Make sure default alias is always present - Remove collection aliases early in doDelete - Handles all content types, fix setProperties not working - Fix sometimes there is an extraneous leading zero when converting from MPI - Fix session encryption negotiation - Do not expose recycle bin - Protect against the methods not called from DBus - Also emit collectionChanged signal when lock state changes - Show notification when entry secret is requested - Add a README file - Actually close session when client disconnects - Gracefully return alternative label when collection is locked - Reorganize, rename secretservice to fdosecrets - Fix issues reported by clazy - Unify UI strings and fix icon - Implement a setting to skip confirmation when deleting entries from DBus - Remove some unused debugging log - Simply ignore errors when DBus context is not available. QtDBus won't set QDBusContext when deliver property get/set, and there is no way to get a QDBusMessage in property getter/setter. - Simplify GcryptMPI using std::unique_ptr and add unit test - Format code in fdosecrets - Move DBusReturnImpl to details namespace - Fix crash when locking a database: don't modify exposedGroup setting in customData when database is deleted - Make sure Collection::searchItems works, whether it's locked or not - Fix FdoSecrets::Collection becomes empty after a database reload - Fix crash when looping while modifying the list
238 lines
7.4 KiB
C++
238 lines
7.4 KiB
C++
/*
|
|
* Copyright (C) 2019 Aetf <aetf@unlimitedcodeworks.xyz>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
* version 3 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "Prompt.h"
|
|
|
|
#include "fdosecrets/FdoSecretsSettings.h"
|
|
#include "fdosecrets/objects/Collection.h"
|
|
#include "fdosecrets/objects/Item.h"
|
|
#include "fdosecrets/objects/Service.h"
|
|
|
|
#include "core/Tools.h"
|
|
#include "gui/DatabaseWidget.h"
|
|
#include "gui/MessageBox.h"
|
|
|
|
#include <QThread>
|
|
#include <QWindow>
|
|
|
|
namespace FdoSecrets
|
|
{
|
|
|
|
PromptBase::PromptBase(Service* parent)
|
|
: DBusObject(parent)
|
|
{
|
|
registerWithPath(
|
|
QStringLiteral("%1/prompt/%2").arg(p()->objectPath().path(), Tools::uuidToHex(QUuid::createUuid())),
|
|
new PromptAdaptor(this));
|
|
|
|
connect(this, &PromptBase::completed, this, &PromptBase::deleteLater);
|
|
}
|
|
|
|
QWindow* PromptBase::findWindow(const QString& windowId)
|
|
{
|
|
// find parent window, or nullptr if not found
|
|
bool ok = false;
|
|
WId wid = windowId.toULongLong(&ok, 0);
|
|
QWindow* parent = nullptr;
|
|
if (ok) {
|
|
parent = QWindow::fromWinId(wid);
|
|
}
|
|
if (parent) {
|
|
// parent is not the child of any object, so make sure it gets deleted at some point
|
|
QObject::connect(this, &QObject::destroyed, parent, &QObject::deleteLater);
|
|
}
|
|
return parent;
|
|
}
|
|
|
|
Service* PromptBase::service() const
|
|
{
|
|
return qobject_cast<Service*>(parent());
|
|
}
|
|
|
|
DBusReturn<void> PromptBase::dismiss()
|
|
{
|
|
emit completed(true, {});
|
|
return {};
|
|
}
|
|
|
|
DeleteCollectionPrompt::DeleteCollectionPrompt(Service* parent, Collection* coll)
|
|
: PromptBase(parent)
|
|
, m_collection(coll)
|
|
{
|
|
}
|
|
|
|
DBusReturn<void> DeleteCollectionPrompt::prompt(const QString& windowId)
|
|
{
|
|
if (thread() != QThread::currentThread()) {
|
|
DBusReturn<void> ret;
|
|
QMetaObject::invokeMethod(this,
|
|
"prompt",
|
|
Qt::BlockingQueuedConnection,
|
|
Q_ARG(QString, windowId),
|
|
Q_RETURN_ARG(DBusReturn<void>, ret));
|
|
return ret;
|
|
}
|
|
|
|
if (!m_collection) {
|
|
return DBusReturn<>::Error(QStringLiteral(DBUS_ERROR_SECRET_NO_SUCH_OBJECT));
|
|
}
|
|
|
|
MessageBox::OverrideParent override(findWindow(windowId));
|
|
// only need to delete in backend, collection will react itself.
|
|
service()->doCloseDatabase(m_collection->backend());
|
|
|
|
emit completed(false, {});
|
|
|
|
return {};
|
|
}
|
|
|
|
CreateCollectionPrompt::CreateCollectionPrompt(Service* parent)
|
|
: PromptBase(parent)
|
|
{
|
|
}
|
|
|
|
DBusReturn<void> CreateCollectionPrompt::prompt(const QString& windowId)
|
|
{
|
|
if (thread() != QThread::currentThread()) {
|
|
DBusReturn<void> ret;
|
|
QMetaObject::invokeMethod(this,
|
|
"prompt",
|
|
Qt::BlockingQueuedConnection,
|
|
Q_ARG(QString, windowId),
|
|
Q_RETURN_ARG(DBusReturn<void>, ret));
|
|
return ret;
|
|
}
|
|
|
|
MessageBox::OverrideParent override(findWindow(windowId));
|
|
|
|
auto coll = service()->doNewDatabase();
|
|
if (!coll) {
|
|
return dismiss();
|
|
}
|
|
|
|
emit collectionCreated(coll);
|
|
emit completed(false, coll->objectPath().path());
|
|
|
|
return {};
|
|
}
|
|
|
|
LockCollectionsPrompt::LockCollectionsPrompt(Service* parent, const QList<Collection*>& colls)
|
|
: PromptBase(parent)
|
|
{
|
|
m_collections.reserve(colls.size());
|
|
for (const auto& c : asConst(colls)) {
|
|
m_collections << c;
|
|
}
|
|
}
|
|
|
|
DBusReturn<void> LockCollectionsPrompt::prompt(const QString& windowId)
|
|
{
|
|
if (thread() != QThread::currentThread()) {
|
|
DBusReturn<void> ret;
|
|
QMetaObject::invokeMethod(this,
|
|
"prompt",
|
|
Qt::BlockingQueuedConnection,
|
|
Q_ARG(QString, windowId),
|
|
Q_RETURN_ARG(DBusReturn<void>, ret));
|
|
return ret;
|
|
}
|
|
|
|
MessageBox::OverrideParent override(findWindow(windowId));
|
|
|
|
QList<QDBusObjectPath> locked;
|
|
for (const auto& c : asConst(m_collections)) {
|
|
if (c) {
|
|
c->doLock();
|
|
locked << c->objectPath();
|
|
}
|
|
}
|
|
|
|
emit completed(false, QVariant::fromValue(locked));
|
|
|
|
return {};
|
|
}
|
|
|
|
UnlockCollectionsPrompt::UnlockCollectionsPrompt(Service* parent, const QList<Collection*>& colls)
|
|
: PromptBase(parent)
|
|
{
|
|
m_collections.reserve(colls.size());
|
|
for (const auto& c : asConst(colls)) {
|
|
m_collections << c;
|
|
}
|
|
}
|
|
|
|
DBusReturn<void> UnlockCollectionsPrompt::prompt(const QString& windowId)
|
|
{
|
|
if (thread() != QThread::currentThread()) {
|
|
DBusReturn<void> ret;
|
|
QMetaObject::invokeMethod(this,
|
|
"prompt",
|
|
Qt::BlockingQueuedConnection,
|
|
Q_ARG(QString, windowId),
|
|
Q_RETURN_ARG(DBusReturn<void>, ret));
|
|
return ret;
|
|
}
|
|
|
|
MessageBox::OverrideParent override(findWindow(windowId));
|
|
|
|
QList<QDBusObjectPath> unlocked;
|
|
for (const auto& c : asConst(m_collections)) {
|
|
if (c) {
|
|
c->doUnlock();
|
|
unlocked << c->objectPath();
|
|
}
|
|
}
|
|
|
|
emit completed(false, QVariant::fromValue(unlocked));
|
|
|
|
return {};
|
|
}
|
|
|
|
DeleteItemPrompt::DeleteItemPrompt(Service* parent, Item* item)
|
|
: PromptBase(parent)
|
|
, m_item(item)
|
|
{
|
|
}
|
|
|
|
DBusReturn<void> DeleteItemPrompt::prompt(const QString& windowId)
|
|
{
|
|
if (thread() != QThread::currentThread()) {
|
|
DBusReturn<void> ret;
|
|
QMetaObject::invokeMethod(this,
|
|
"prompt",
|
|
Qt::BlockingQueuedConnection,
|
|
Q_ARG(QString, windowId),
|
|
Q_RETURN_ARG(DBusReturn<void>, ret));
|
|
return ret;
|
|
}
|
|
|
|
MessageBox::OverrideParent override(findWindow(windowId));
|
|
|
|
// delete item's backend. Item will be notified after the backend is deleted.
|
|
if (m_item) {
|
|
if (FdoSecrets::settings()->noConfirmDeleteItem()) {
|
|
MessageBox::setNextAnswer(MessageBox::Move);
|
|
}
|
|
m_item->collection()->doDeleteEntries({m_item->backend()});
|
|
}
|
|
|
|
emit completed(false, {});
|
|
|
|
return {};
|
|
}
|
|
|
|
} // namespace FdoSecrets
|