7#ifndef _KWALLETFREEDESKTOPSERVICE_H_
8#define _KWALLETFREEDESKTOPSERVICE_H_
11#include <QDBusArgument>
12#include <QDBusServiceWatcher>
18#include "kwalletdbuscontext.h"
20#define FDO_APPID QString()
21#define FDO_SECRETS_SERVICE_OBJECT "/org/freedesktop/secrets"
22#define FDO_ALIAS_PATH "/org/freedesktop/secrets/aliases/"
24static inline constexpr size_t FDO_SECRETS_CIPHER_KEY_SIZE = 16;
25static inline constexpr int FDO_DH_PUBLIC_KEY_SIZE = 128;
29class FreedesktopSecret
32 FreedesktopSecret() =
default;
34 FreedesktopSecret(QDBusObjectPath iSession,
const QCA::SecureArray &iValue, QString iMimeType)
35 : session(std::
move(iSession))
37 , mimeType(std::
move(iMimeType))
41 friend QDBusArgument &operator<<(QDBusArgument &arg,
const FreedesktopSecret &secret);
42 friend const QDBusArgument &operator>>(
const QDBusArgument &arg, FreedesktopSecret &secret);
44 QDBusObjectPath session;
45 QCA::SecureArray parameters;
46 QCA::SecureArray value;
55 static EntryLocation fromUniqueLabel(
const struct FdoUniqueLabel &uniqLabel);
56 struct FdoUniqueLabel toUniqueLabel() const;
58 bool operator==(
const EntryLocation &rhs)
const
60 return folder == rhs.folder && key == rhs.key;
63 bool operator!=(
const EntryLocation &rhs)
const
65 return !(*
this == rhs);
72struct FdoUniqueLabel {
73 static FdoUniqueLabel fromEntryLocation(
const EntryLocation &entryLocation);
74 static FdoUniqueLabel fromName(
const QString &name);
75 static QString makeName(
const QString &label,
int copyId);
77 bool operator==(
const FdoUniqueLabel &rhs)
const
79 return copyId == rhs.copyId && label == rhs.label;
82 bool operator!=(
const FdoUniqueLabel &rhs)
const
84 return !(*
this == rhs);
87 QString toName()
const;
88 EntryLocation toEntryLocation()
const;
97Q_DECLARE_METATYPE(FreedesktopSecret)
98Q_DECLARE_METATYPE(FreedesktopSecretMap)
99Q_DECLARE_METATYPE(PropertiesMap)
100Q_DECLARE_METATYPE(StrStrMap)
103class KWalletFreedesktopSession;
104class KWalletFreedesktopSessionAlgorithm;
105class KWalletFreedesktopCollection;
106class KWalletFreedesktopPrompt;
107class KWalletFreedesktopItem;
109class KWalletFreedesktopService :
public QObject,
protected FDO_DBUS_CONTEXT
113 Q_PROPERTY(QList<QDBusObjectPath> Collections READ collections)
114 QList<QDBusObjectPath> collections()
const;
119 explicit KWalletFreedesktopService(KWalletD *
parent);
120 ~KWalletFreedesktopService();
122 KWalletFreedesktopService(
const KWalletFreedesktopService &) =
delete;
123 KWalletFreedesktopService &operator=(
const KWalletFreedesktopService &) =
delete;
125 KWalletFreedesktopService(KWalletFreedesktopService &&) =
delete;
126 KWalletFreedesktopService &operator=(KWalletFreedesktopService &&) =
delete;
128 static QString wrapToCollectionPath(
const QString &itemPath);
130 static QDBusObjectPath nextPromptPath();
131 KWalletD *backend()
const;
132 QDBusObjectPath fdoObjectPath()
const;
134 bool desecret(
const QDBusMessage &message, FreedesktopSecret &secret);
135 bool ensecret(
const QDBusMessage &message, FreedesktopSecret &secret);
136 KWalletFreedesktopItem *getItemByObjectPath(
const QDBusObjectPath &path)
const;
137 KWalletFreedesktopCollection *getCollectionByWalletName(
const QString &walletName)
const;
138 KWalletFreedesktopPrompt *getPromptByObjectPath(
const QDBusObjectPath &path)
const;
140 FdoUniqueLabel makeUniqueCollectionLabel(
const QString &label);
141 QString makeUniqueWalletName(
const QString &labelPrefix);
142 QDBusObjectPath makeUniqueObjectPath(
const QString &walletName)
const;
144 QString resolveIfAlias(QString alias);
145 QStringList readAliasesFor(
const QString &walletName);
146 void createCollectionAlias(
const QString &alias, KWalletFreedesktopCollection *collection);
147 void createCollectionAlias(
const QString &alias,
const QString &walletName);
148 void updateCollectionAlias(
const QString &alias,
const QString &walletName);
149 void removeAlias(
const QString &alias);
151 void deletePrompt(
const QString &objectPath);
152 void deleteSession(
const QString &objectPath);
153 QDBusObjectPath promptUnlockCollection(
const QString &walletName,
int handle);
156 void onCollectionCreated(
const QDBusObjectPath &path);
157 void onCollectionChanged(
const QDBusObjectPath &path);
158 void onCollectionDeleted(
const QDBusObjectPath &path);
159 void onPropertiesChanged(
const QVariantMap &properties);
162 void lockCollection(
const QString &name);
163 void entryUpdated(
const QString &walletName,
const QString &folder,
const QString &entryName);
164 void entryDeleted(
const QString &walletName,
const QString &folder,
const QString &entryName);
165 void entryRenamed(
const QString &walletName,
const QString &folder,
const QString &oldName,
const QString &newName);
166 void walletDeleted(
const QString &walletName);
167 void walletCreated(
const QString &walletCreated);
174 std::unique_ptr<KWalletFreedesktopSessionAlgorithm> createSessionAlgorithmPlain()
const;
175 std::unique_ptr<KWalletFreedesktopSessionAlgorithm> createSessionAlgorithmDhAes(
const QByteArray &clientKey)
const;
176 QString createSession(std::unique_ptr<KWalletFreedesktopSessionAlgorithm> algorithm);
177 QString defaultWalletName(KConfigGroup &cfg);
180 std::map<QString, std::unique_ptr<KWalletFreedesktopSession>> m_sessions;
181 std::map<QString, std::unique_ptr<KWalletFreedesktopCollection>> m_collections;
182 std::map<QString, std::unique_ptr<KWalletFreedesktopPrompt>> m_prompts;
184 uint64_t m_session_counter = 0;
190 QCA::Initializer m_init;
197 QDBusObjectPath CreateCollection(
const QVariantMap &properties,
const QString &alias, QDBusObjectPath &prompt);
198 FreedesktopSecretMap GetSecrets(
const QList<QDBusObjectPath> &items,
const QDBusObjectPath &session);
199 QList<QDBusObjectPath> Lock(
const QList<QDBusObjectPath> &objects, QDBusObjectPath &Prompt);
200 QDBusVariant OpenSession(
const QString &algorithm,
const QDBusVariant &input, QDBusObjectPath &result);
201 QDBusObjectPath ReadAlias(
const QString &name);
202 QList<QDBusObjectPath> SearchItems(
const StrStrMap &attributes, QList<QDBusObjectPath> &locked);
203 void SetAlias(
const QString &name,
const QDBusObjectPath &collection);
204 QList<QDBusObjectPath> Unlock(
const QList<QDBusObjectPath> &objects, QDBusObjectPath &prompt);
208 void CollectionChanged(
const QDBusObjectPath &collection);
209 void CollectionCreated(
const QDBusObjectPath &collection);
210 void CollectionDeleted(
const QDBusObjectPath &collection);
224void explicit_zero_mem(
void *data,
size_t size);
KIOCORE_EXPORT CopyJob * move(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QObject * parent() const const