/* * Copyright (C) 2020 Aetf * * 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 . */ #ifndef KEEPASSXC_FDOSECRETSPROXY_H #define KEEPASSXC_FDOSECRETSPROXY_H #include "fdosecrets/dbus/DBusTypes.h" #include #include #include #include #include #include #include #include #include /** * Mimic the interface of QDBusPendingReply so the same code can be used in test */ template class PropertyReply { QDBusPendingReply m_reply; public: /*implicit*/ PropertyReply(const QDBusMessage& reply) : m_reply(reply) { } bool isFinished() const { return m_reply.isFinished(); } bool isValid() const { return m_reply.isValid(); } bool isError() const { return m_reply.isError(); } QDBusError error() const { return m_reply.error(); } T value() const { return qdbus_cast(m_reply.value().variant()); } template T argumentAt() const { return value(); } }; #define IMPL_GET_PROPERTY(name) \ QDBusMessage msg = QDBusMessage::createMethodCall( \ service(), path(), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("Get")); \ msg << interface() << QStringLiteral(#name); \ return \ { \ connection().call(msg, QDBus::BlockWithGui) \ } #define IMPL_SET_PROPERTY(name, value) \ QDBusMessage msg = QDBusMessage::createMethodCall( \ service(), path(), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("Set")); \ msg << interface() << QStringLiteral(#name) << QVariant::fromValue(QDBusVariant(QVariant::fromValue(value))); \ return \ { \ connection().call(msg, QDBus::BlockWithGui) \ } /* * Proxy class for interface org.freedesktop.Secret.Service */ class ServiceProxy : public QDBusAbstractInterface { Q_OBJECT public: static inline const char* staticInterfaceName() { return "org.freedesktop.Secret.Service"; } public: ServiceProxy(const QString& service, const QString& path, const QDBusConnection& connection, QObject* parent = nullptr); ~ServiceProxy() override; inline PropertyReply> collections() const { IMPL_GET_PROPERTY(Collections); } public Q_SLOTS: // METHODS inline QDBusPendingReply CreateCollection(const QVariantMap& properties, const QString& alias) { QList argumentList; argumentList << QVariant::fromValue(properties) << QVariant::fromValue(alias); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("CreateCollection"), argumentList)}; } inline QDBusPendingReply GetSecrets(const QList& items, const QDBusObjectPath& session) { QList argumentList; argumentList << QVariant::fromValue(items) << QVariant::fromValue(session); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("GetSecrets"), argumentList)}; } inline QDBusPendingReply, QDBusObjectPath> Lock(const QList& paths) { QList argumentList; argumentList << QVariant::fromValue(paths); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Lock"), argumentList)}; } inline QDBusPendingReply OpenSession(const QString& algorithm, const QDBusVariant& input) { QList argumentList; argumentList << QVariant::fromValue(algorithm) << QVariant::fromValue(input); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("OpenSession"), argumentList)}; } inline QDBusPendingReply ReadAlias(const QString& name) { QList argumentList; argumentList << QVariant::fromValue(name); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("ReadAlias"), argumentList)}; } inline QDBusPendingReply, QList> SearchItems(FdoSecrets::wire::StringStringMap attributes) { QList argumentList; argumentList << QVariant::fromValue(attributes); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SearchItems"), argumentList)}; } inline QDBusPendingReply<> SetAlias(const QString& name, const QDBusObjectPath& collection) { QList argumentList; argumentList << QVariant::fromValue(name) << QVariant::fromValue(collection); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SetAlias"), argumentList)}; } inline QDBusPendingReply, QDBusObjectPath> Unlock(const QList& paths) { QList argumentList; argumentList << QVariant::fromValue(paths); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Unlock"), argumentList)}; } Q_SIGNALS: // SIGNALS void CollectionChanged(const QDBusObjectPath& collection); void CollectionCreated(const QDBusObjectPath& collection); void CollectionDeleted(const QDBusObjectPath& collection); }; /* * Proxy class for interface org.freedesktop.Secret.Collection */ class CollectionProxy : public QDBusAbstractInterface { Q_OBJECT public: static inline const char* staticInterfaceName() { return "org.freedesktop.Secret.Collection"; } public: CollectionProxy(const QString& service, const QString& path, const QDBusConnection& connection, QObject* parent = nullptr); ~CollectionProxy() override; inline PropertyReply created() const { IMPL_GET_PROPERTY(Created); } inline PropertyReply> items() const { IMPL_GET_PROPERTY(Items); } inline PropertyReply label() const { IMPL_GET_PROPERTY(Label); } inline QDBusPendingReply<> setLabel(const QString& value) { IMPL_SET_PROPERTY(Label, value); } inline PropertyReply locked() const { IMPL_GET_PROPERTY(Locked); } inline PropertyReply modified() const { IMPL_GET_PROPERTY(Modified); } public Q_SLOTS: // METHODS inline QDBusPendingReply CreateItem(const QVariantMap& properties, FdoSecrets::wire::Secret secret, bool replace) { QList argumentList; argumentList << QVariant::fromValue(properties) << QVariant::fromValue(secret) << QVariant::fromValue(replace); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("CreateItem"), argumentList)}; } inline QDBusPendingReply Delete() { QList argumentList; return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Delete"), argumentList)}; } inline QDBusPendingReply> SearchItems(FdoSecrets::wire::StringStringMap attributes) { QList argumentList; argumentList << QVariant::fromValue(attributes); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SearchItems"), argumentList)}; } Q_SIGNALS: // SIGNALS void ItemChanged(const QDBusObjectPath& item); void ItemCreated(const QDBusObjectPath& item); void ItemDeleted(const QDBusObjectPath& item); }; /* * Proxy class for interface org.freedesktop.Secret.Item */ class ItemProxy : public QDBusAbstractInterface { Q_OBJECT public: static inline const char* staticInterfaceName() { return "org.freedesktop.Secret.Item"; } public: ItemProxy(const QString& service, const QString& path, const QDBusConnection& connection, QObject* parent = nullptr); ~ItemProxy() override; inline PropertyReply attributes() const { IMPL_GET_PROPERTY(Attributes); } inline QDBusPendingReply<> setAttributes(FdoSecrets::wire::StringStringMap value) { IMPL_SET_PROPERTY(Attributes, value); } inline PropertyReply created() const { IMPL_GET_PROPERTY(Created); } inline PropertyReply label() const { IMPL_GET_PROPERTY(Label); } inline QDBusPendingReply<> setLabel(const QString& value) { IMPL_SET_PROPERTY(Label, value); } inline PropertyReply locked() const { IMPL_GET_PROPERTY(Locked); } inline PropertyReply modified() const { IMPL_GET_PROPERTY(Modified); } public Q_SLOTS: // METHODS inline QDBusPendingReply Delete() { QList argumentList; return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Delete"), argumentList)}; } inline QDBusPendingReply GetSecret(const QDBusObjectPath& session) { QList argumentList; argumentList << QVariant::fromValue(session); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("GetSecret"), argumentList)}; } inline QDBusPendingReply<> SetSecret(FdoSecrets::wire::Secret secret) { QList argumentList; argumentList << QVariant::fromValue(secret); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SetSecret"), argumentList)}; } Q_SIGNALS: // SIGNALS }; /* * Proxy class for interface org.freedesktop.Secret.Session */ class SessionProxy : public QDBusAbstractInterface { Q_OBJECT public: static inline const char* staticInterfaceName() { return "org.freedesktop.Secret.Session"; } public: SessionProxy(const QString& service, const QString& path, const QDBusConnection& connection, QObject* parent = nullptr); ~SessionProxy() override; public Q_SLOTS: // METHODS inline QDBusPendingReply<> Close() { QList argumentList; return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Close"), argumentList)}; } Q_SIGNALS: // SIGNALS }; /* * Proxy class for interface org.freedesktop.Secret.Prompt */ class PromptProxy : public QDBusAbstractInterface { Q_OBJECT public: static inline const char* staticInterfaceName() { return "org.freedesktop.Secret.Prompt"; } public: PromptProxy(const QString& service, const QString& path, const QDBusConnection& connection, QObject* parent = nullptr); ~PromptProxy() override; public Q_SLOTS: // METHODS inline QDBusPendingReply<> Dismiss() { QList argumentList; return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Dismiss"), argumentList)}; } inline QDBusPendingReply<> Prompt(const QString& windowId) { QList argumentList; argumentList << QVariant::fromValue(windowId); return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Prompt"), argumentList)}; } Q_SIGNALS: // SIGNALS void Completed(bool dismissed, const QDBusVariant& result); }; #undef IMPL_GET_PROPERTY #undef IMPL_SET_PROPERTY #endif // KEEPASSXC_FDOSECRETSPROXY_H