summaryrefslogtreecommitdiff
path: root/pkcs11/secret-store
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-10-12 17:39:53 +0200
committerStef Walter <stefw@gnome.org>2012-10-12 19:45:06 +0200
commitb7648ca3864cf8d952468bae299806b0fcda5442 (patch)
tree27a01464cfd42dec5cc45327558269e3031976f2 /pkcs11/secret-store
parent34467afa89c1eabf16bf65b89f35b62cc61bf9d9 (diff)
downloadgnome-keyring-b7648ca3864cf8d952468bae299806b0fcda5442.tar.gz
secret-store: Set the schema name correctly on loaded items
* When we loaded items from the keyring we didn't set the schema correctly. * This causes any searches for the item that include a schema in the search parameters to fail. * Also caused problems storing items, when it was expected that the item would replace any already stored. This uses a search internally. * Fix and add a test for this case, both for encrypted and plaintext keyring files. https://bugzilla.gnome.org/show_bug.cgi?id=681727
Diffstat (limited to 'pkcs11/secret-store')
-rw-r--r--pkcs11/secret-store/gkm-secret-binary.c9
-rw-r--r--pkcs11/secret-store/gkm-secret-textual.c15
-rw-r--r--pkcs11/secret-store/tests/files/encrypted-with-schema.keyringbin0 -> 404 bytes
-rw-r--r--pkcs11/secret-store/tests/files/plain-with-schema.keyring23
-rw-r--r--pkcs11/secret-store/tests/test-secret-binary.c21
-rw-r--r--pkcs11/secret-store/tests/test-secret-textual.c23
6 files changed, 85 insertions, 6 deletions
diff --git a/pkcs11/secret-store/gkm-secret-binary.c b/pkcs11/secret-store/gkm-secret-binary.c
index b8dbef79..92ba8ca5 100644
--- a/pkcs11/secret-store/gkm-secret-binary.c
+++ b/pkcs11/secret-store/gkm-secret-binary.c
@@ -738,15 +738,18 @@ static void
setup_item_from_info (GkmSecretItem *item, GkmSecretData *data, ItemInfo *info)
{
GkmSecretObject *obj = GKM_SECRET_OBJECT (item);
+ const gchar *schema_name;
GkmSecret *secret;
- const gchar *type;
gkm_secret_object_set_label (obj, info->display_name);
gkm_secret_object_set_created (obj, info->ctime);
gkm_secret_object_set_modified (obj, info->mtime);
- type = gkm_secret_compat_format_item_type (info->type);
- gkm_secret_item_set_schema (item, type);
+ schema_name = g_hash_table_lookup (info->attributes, GKM_SECRET_FIELD_SCHEMA);
+ if (schema_name == NULL)
+ schema_name = gkm_secret_compat_format_item_type (info->type);
+ gkm_secret_item_set_schema (item, schema_name);
+
gkm_secret_item_set_fields (item, info->attributes);
/* Collection is locked */
diff --git a/pkcs11/secret-store/gkm-secret-textual.c b/pkcs11/secret-store/gkm-secret-textual.c
index af7bc372..358c3cc3 100644
--- a/pkcs11/secret-store/gkm-secret-textual.c
+++ b/pkcs11/secret-store/gkm-secret-textual.c
@@ -122,7 +122,10 @@ generate_attributes (GKeyFile *file, GkmSecretItem *item)
}
static void
-parse_attributes (GKeyFile *file, GkmSecretItem *item, const gchar **groups)
+parse_attributes (GKeyFile *file,
+ GkmSecretItem *item,
+ const gchar **groups,
+ gint compat_type)
{
GHashTable *attributes;
const gchar *identifier;
@@ -130,6 +133,7 @@ parse_attributes (GKeyFile *file, GkmSecretItem *item, const gchar **groups)
gchar *prefix;
gchar *name, *type;
guint64 number;
+ const gchar *schema_name;
/* Now do the attributes */
@@ -163,6 +167,12 @@ parse_attributes (GKeyFile *file, GkmSecretItem *item, const gchar **groups)
}
gkm_secret_item_set_fields (item, attributes);
+
+ schema_name = g_hash_table_lookup (attributes, GKM_SECRET_FIELD_SCHEMA);
+ if (schema_name == NULL)
+ schema_name = gkm_secret_compat_format_item_type (compat_type);
+ gkm_secret_item_set_schema (item, schema_name);
+
g_hash_table_unref (attributes);
g_free (prefix);
}
@@ -331,7 +341,6 @@ parse_item (GKeyFile *file, GkmSecretItem *item, GkmSecretData *sdata,
g_clear_error (&err);
type = 0;
}
- gkm_secret_item_set_schema (item, gkm_secret_compat_format_item_type (type));
val = g_key_file_get_string (file, identifier, "display-name", NULL);
gkm_secret_object_set_label (obj, val);
@@ -374,7 +383,7 @@ parse_item (GKeyFile *file, GkmSecretItem *item, GkmSecretData *sdata,
gkm_secret_object_set_created (obj, num);
/* Now the other stuff */
- parse_attributes (file, item, groups);
+ parse_attributes (file, item, groups, type);
parse_acl (file, item, groups);
}
diff --git a/pkcs11/secret-store/tests/files/encrypted-with-schema.keyring b/pkcs11/secret-store/tests/files/encrypted-with-schema.keyring
new file mode 100644
index 00000000..63d1a730
--- /dev/null
+++ b/pkcs11/secret-store/tests/files/encrypted-with-schema.keyring
Binary files differ
diff --git a/pkcs11/secret-store/tests/files/plain-with-schema.keyring b/pkcs11/secret-store/tests/files/plain-with-schema.keyring
new file mode 100644
index 00000000..b2d51cda
--- /dev/null
+++ b/pkcs11/secret-store/tests/files/plain-with-schema.keyring
@@ -0,0 +1,23 @@
+[keyring]
+display-name=test
+ctime=0
+mtime=0
+lock-on-idle=false
+lock-after=false
+
+[1]
+item-type=0
+display-name=Secret Test Credentials
+secret=pa$$w0rd
+mtime=1350055423
+ctime=0
+
+[1:attribute0]
+name=rishi-identity
+type=string
+value=rishi-identity
+
+[1:attribute1]
+name=xdg:schema
+type=string
+value=se.lostca.is.rishi.secret
diff --git a/pkcs11/secret-store/tests/test-secret-binary.c b/pkcs11/secret-store/tests/test-secret-binary.c
index f581e3f2..a18803cd 100644
--- a/pkcs11/secret-store/tests/test-secret-binary.c
+++ b/pkcs11/secret-store/tests/test-secret-binary.c
@@ -225,6 +225,26 @@ test_read_created_on_rhel (Test *test, gconstpointer unused)
g_assert_cmpint (res, ==, GKM_DATA_SUCCESS);
}
+static void
+test_read_with_schema (Test *test,
+ gconstpointer unused)
+{
+ GkmDataResult res;
+ GkmSecret *master;
+ GkmSecretItem *item;
+
+ master = gkm_secret_new_from_password ("test");
+ gkm_secret_data_set_master (test->sdata, master);
+ g_object_unref (master);
+ res = check_read_keyring_file (test, SRCDIR "/files/encrypted-with-schema.keyring");
+ g_assert_cmpint (res, ==, GKM_DATA_SUCCESS);
+
+ item = gkm_secret_collection_get_item (test->collection, "1");
+ g_assert (item != NULL);
+
+ g_assert_cmpstr (gkm_secret_item_get_schema (item), ==, "se.lostca.is.rishi.secret");
+}
+
int
main (int argc, char **argv)
{
@@ -239,6 +259,7 @@ main (int argc, char **argv)
g_test_add ("/secret-store/binary/remove_unavailable", Test, NULL, setup, test_remove_unavailable, teardown);
g_test_add ("/secret-store/binary/created_on_rhel", Test, NULL, setup, test_read_created_on_rhel, teardown);
g_test_add ("/secret-store/binary/created_on_solaris_opencsw", Test, NULL, setup, test_read_created_on_solaris_opencsw, teardown);
+ g_test_add ("/secret-store/binary/read_with_schema", Test, NULL, setup, test_read_with_schema, teardown);
return g_test_run ();
}
diff --git a/pkcs11/secret-store/tests/test-secret-textual.c b/pkcs11/secret-store/tests/test-secret-textual.c
index 4c8a5aed..87bc4082 100644
--- a/pkcs11/secret-store/tests/test-secret-textual.c
+++ b/pkcs11/secret-store/tests/test-secret-textual.c
@@ -189,6 +189,28 @@ test_remove_unavailable (Test *test, gconstpointer unused)
g_free (data);
}
+static void
+test_read_with_schema (Test *test,
+ gconstpointer unused)
+{
+ GkmDataResult res;
+ GkmSecretItem *item;
+ gchar *data;
+ gsize n_data;
+
+ if (!g_file_get_contents (SRCDIR "/files/plain-with-schema.keyring", &data, &n_data, NULL))
+ g_assert_not_reached ();
+ res = gkm_secret_textual_read (test->collection, test->sdata, data, n_data);
+ g_assert (res == GKM_DATA_SUCCESS);
+
+ item = gkm_secret_collection_get_item (test->collection, "1");
+ g_assert (item != NULL);
+
+ g_assert_cmpstr (gkm_secret_item_get_schema (item), ==, "se.lostca.is.rishi.secret");
+
+ g_free (data);
+}
+
int
main (int argc, char **argv)
{
@@ -200,6 +222,7 @@ main (int argc, char **argv)
g_test_add ("/secret-store/search/read_bad_number", Test, NULL, setup, test_read_bad_number, teardown);
g_test_add ("/secret-store/search/write", Test, NULL, setup, test_write, teardown);
g_test_add ("/secret-store/search/remove_unavailable", Test, NULL, setup, test_remove_unavailable, teardown);
+ g_test_add ("/secret-store/search/read-with-schema", Test, NULL, setup, test_read_with_schema, teardown);
return g_test_run ();
}