The current implementation of KSecretsService accepts property names of
Collection and Item without interface name. The Secret Service API standard
says "Specify the property names in full interface.Property form" [1]
The form required by the standard:
"org.freedesktop.Secret.Item.Label"
The accepted form in KSecretsService:
"Label"
(gnome-keyring accepts the properties only in full interface form)
The patch changes the accepted name form from single name form to full
interface name form. The patch simply adds an interface prefix to each
occurrence of a property name. (I used a helper macros because of DRY.)
The patch applies to the files:
ksecretsserviced/frontend/secret/collection.cpp
ksecretsserviced/frontend/secret/service.cpp
ksecretsserviced/frontend/tests/servicetest.cpp
Regards,
Jakub
[1] : http://standards.freedesktop.org/secret-service/re02.html>From b21c8ce9897d009b56432eefd782e5a1058d50c6 Mon Sep 17 00:00:00 2001
From: Jakub Filak <[email protected]>
Date: Sun, 5 Aug 2012 11:40:57 +0200
Subject: [PATCH] Collection and Item property names in full
interface.Property form.
Signed-off-by: Jakub Filak <[email protected]>
---
ksecretsserviced/frontend/secret/collection.cpp | 18 +++++++++++-------
ksecretsserviced/frontend/secret/service.cpp | 12 ++++++++----
ksecretsserviced/frontend/tests/servicetest.cpp | 20 +++++++++++---------
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/ksecretsserviced/frontend/secret/collection.cpp b/ksecretsserviced/frontend/secret/collection.cpp
index 772c75b..ac47213 100644
--- a/ksecretsserviced/frontend/secret/collection.cpp
+++ b/ksecretsserviced/frontend/secret/collection.cpp
@@ -185,17 +185,21 @@ QDBusObjectPath Collection::createItem(const QMap<QString, QVariant> &properties
return QDBusObjectPath("/");
}
- if(properties.contains("Locked")) {
- locked = properties["Locked"].toBool();
+#define ITEM_PROPERTY(name) "org.freedesktop.Secret.Item."name
+
+ if(properties.contains(ITEM_PROPERTY("Locked"))) {
+ locked = properties[ITEM_PROPERTY("Locked")].toBool();
}
- if(properties.contains("Attributes")) {
- attributes = qdbus_cast<StringStringMap>(properties["Attributes"].value<QDBusArgument>());
+ if(properties.contains(ITEM_PROPERTY("Attributes"))) {
+ attributes = qdbus_cast<StringStringMap>(properties[ITEM_PROPERTY("Attributes")].value<QDBusArgument>());
}
- if(properties.contains("Label")) {
- label = properties["Label"].toString();
- attributes["Label"] = label;
+ if(properties.contains(ITEM_PROPERTY("Label"))) {
+ label = properties[ITEM_PROPERTY("Label")].toString();
+ attributes[ITEM_PROPERTY("Label")] = label;
}
+#undef ITEM_PROPERTY
+
// TODO: check the parameters before creating the prompt
QCA::SecureArray secretValue;
if(!session->decrypt(secret.m_value, secret.m_parameters, secretValue)) {
diff --git a/ksecretsserviced/frontend/secret/service.cpp b/ksecretsserviced/frontend/secret/service.cpp
index be13db5..d496227 100644
--- a/ksecretsserviced/frontend/secret/service.cpp
+++ b/ksecretsserviced/frontend/secret/service.cpp
@@ -101,11 +101,13 @@ QDBusObjectPath Service::createCollection(const QMap<QString, QVariant> &propert
const QString& alias,
QDBusObjectPath &prompt)
{
+#define COLLECTION_PROPERTY(name) "org.freedesktop.Secret.Collection."name
+
QString label;
if ( alias.isEmpty() ) {
// TODO: find a way to get properties lookup case insensitive
- if(properties.contains("Label")) {
- label = properties["Label"].toString();
+ if(properties.contains(COLLECTION_PROPERTY("Label"))) {
+ label = properties[COLLECTION_PROPERTY("Label")].toString();
}
else {
// FIXME: shouldn't we throw an error if the collection has no name specified ?
@@ -119,10 +121,12 @@ QDBusObjectPath Service::createCollection(const QMap<QString, QVariant> &propert
}
CollectionCreateInfo createCollectionInfo(label, getCallingPeer());
- if(properties.contains("Locked")) {
- createCollectionInfo.m_locked = properties["Locked"].toBool();
+ if(properties.contains(COLLECTION_PROPERTY("Locked"))) {
+ createCollectionInfo.m_locked = properties[COLLECTION_PROPERTY("Locked")].toBool();
}
+#undef COLLECTION_PROPERTY
+
CreateCollectionMasterJob *job = m_master->createCreateCollectionMasterJob(createCollectionInfo);
if(job->isImmediate()) {
job->exec();
diff --git a/ksecretsserviced/frontend/tests/servicetest.cpp b/ksecretsserviced/frontend/tests/servicetest.cpp
index 6ee0edd..57766a3 100644
--- a/ksecretsserviced/frontend/tests/servicetest.cpp
+++ b/ksecretsserviced/frontend/tests/servicetest.cpp
@@ -47,6 +47,8 @@
* and not over the dbus and calling an eventually running daemon
*/
#define DBUS_SERVICE "org.freedesktop.secrets.frontend.test"
+#define COLLECTION_PROPERTY(name) "org.freedesktop.Secret.Collection."name
+#define ITEM_PROPERTY(name) "org.freedesktop.Secret.Item."name
void ServiceTest::initTestCase()
{
@@ -176,8 +178,8 @@ void ServiceTest::nonBlockingCollection()
QDBusObjectPath collectionPath;
StringVariantMap createProperties;
QList<QVariant> createInput;
- createProperties["Label"] = "test";
- createProperties["Locked"] = false; // create collection unlocked
+ createProperties[COLLECTION_PROPERTY("Label")] = "test";
+ createProperties[COLLECTION_PROPERTY("Locked")] = false; // create collection unlocked
createInput << QVariant::fromValue(createProperties);
createInput << QString("test alias");
QDBusMessage createReply = ifaceService.callWithArgumentList(QDBus::Block, "CreateCollection",
@@ -290,8 +292,8 @@ void ServiceTest::nonBlockingItem()
QDBusObjectPath collectionPath;
QMap<QString, QVariant> collProperties;
QList<QVariant> collInput;
- collProperties["Label"] = "test3";
- collProperties["Locked"] = false;
+ collProperties[COLLECTION_PROPERTY("Label")] = "test3";
+ collProperties[COLLECTION_PROPERTY("Locked")] = false;
collInput << QVariant::fromValue(collProperties);
collInput << "test alias";
QDBusMessage collReply = ifaceService.callWithArgumentList(QDBus::Block, "CreateCollection",
@@ -317,9 +319,9 @@ void ServiceTest::nonBlockingItem()
itemAttributes["attribute1"] = "value1";
itemAttributes["attribute2"] = "value2";
QMap<QString, QVariant> itemProperties;
- itemProperties["Attributes"] = QVariant::fromValue(itemAttributes);
- itemProperties["Label"] = "item1";
- itemProperties["Locked"] = false;
+ itemProperties[ITEM_PROPERTY("Attributes")] = QVariant::fromValue(itemAttributes);
+ itemProperties[ITEM_PROPERTY("Label")] = "item1";
+ itemProperties[ITEM_PROPERTY("Locked")] = false;
QList<QVariant> itemInput;
SecretStruct secret;
secret.m_session = sessionPath;
@@ -496,8 +498,8 @@ void ServiceTest::blockingCollection()
QDBusObjectPath promptPath;
QMap<QString, QVariant> createProperties;
QList<QVariant> createInput;
- createProperties["Label"] = "test";
- createProperties["Locked"] = false; // create collection unlocked
+ createProperties[COLLECTION_PROPERTY("Label")] = "test";
+ createProperties[COLLECTION_PROPERTY("Locked")] = false; // create collection unlocked
createInput << QVariant::fromValue(createProperties);
createInput << QString("test alias");
QDBusMessage createReply = ifaceService.callWithArgumentList(QDBus::Block, "CreateCollection",
--
1.7.11.2