[epiphany/wip/dueno/libsecret-simple] password-manager: Port to the secret_password* API
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/dueno/libsecret-simple] password-manager: Port to the secret_password* API
- Date: Sat, 29 Jun 2019 06:10:13 +0000 (UTC)
commit 13a781a0ede15d763cd5d76683a22c9f538fd261
Author: Daiki Ueno <dueno src gnome org>
Date: Sat Jun 29 08:03:00 2019 +0200
password-manager: Port to the secret_password* API
This switches from using the D-Bus based libsecret API to the simple
API that doesn't impose the particular backend implementation. That
would make it easier to migrate to the local storage in the future.
lib/sync/ephy-password-manager.c | 80 +++++++++++++++++++++-------------------
1 file changed, 43 insertions(+), 37 deletions(-)
---
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index 2d138d674..a4f8c5f19 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -351,9 +351,9 @@ ephy_password_manager_get_usernames_for_origin (EphyPasswordManager *self,
}
static void
-secret_service_store_cb (SecretService *service,
- GAsyncResult *result,
- ManageRecordAsyncData *data)
+secret_password_store_cb (GObject *source_object,
+ GAsyncResult *result,
+ ManageRecordAsyncData *data)
{
GError *error = NULL;
const char *origin;
@@ -362,7 +362,7 @@ secret_service_store_cb (SecretService *service,
origin = ephy_password_record_get_origin (data->record);
username = ephy_password_record_get_username (data->record);
- secret_service_store_finish (service, result, &error);
+ secret_password_store_finish (result, &error);
if (error) {
g_warning ("Failed to store password record for (%s, %s, %s, %s, %s): %s",
origin,
@@ -384,7 +384,6 @@ ephy_password_manager_store_record (EphyPasswordManager *self,
EphyPasswordRecord *record)
{
GHashTable *attributes;
- SecretValue *value;
const char *origin;
const char *target_origin;
const char *username;
@@ -424,14 +423,12 @@ ephy_password_manager_store_record (EphyPasswordManager *self,
username_field, password_field,
modified);
- value = secret_value_new (password, -1, "text/plain");
- secret_service_store (NULL, EPHY_FORM_PASSWORD_SCHEMA,
- attributes, NULL, label, value, NULL,
- (GAsyncReadyCallback)secret_service_store_cb,
- manage_record_async_data_new (self, record));
+ secret_password_storev (EPHY_FORM_PASSWORD_SCHEMA,
+ attributes, NULL, label, password, NULL,
+ (GAsyncReadyCallback)secret_password_store_cb,
+ manage_record_async_data_new (self, record));
g_free (label);
- secret_value_unref (value);
g_hash_table_unref (attributes);
}
@@ -511,15 +508,15 @@ ephy_password_manager_save (EphyPasswordManager *self,
}
static void
-secret_service_search_cb (SecretService *service,
- GAsyncResult *result,
- QueryAsyncData *data)
+secret_password_search_cb (GObject *source_object,
+ GAsyncResult *result,
+ QueryAsyncData *data)
{
GList *matches = NULL;
GList *records = NULL;
GError *error = NULL;
- matches = secret_service_search_finish (service, result, &error);
+ matches = secret_password_search_finish (result, &error);
if (error) {
g_warning ("Failed to search secrets in password schema: %s", error->message);
g_error_free (error);
@@ -527,9 +524,9 @@ secret_service_search_cb (SecretService *service,
}
for (GList *l = matches; l && l->data; l = l->next) {
- SecretItem *item = (SecretItem *)l->data;
- GHashTable *attributes = secret_item_get_attributes (item);
- SecretValue *value = secret_item_get_secret (item);
+ SecretRetrievable *retrievable = SECRET_RETRIEVABLE (l->data);
+ GHashTable *attributes = secret_retrievable_get_attributes (retrievable);
+ SecretValue *value;
const char *id = g_hash_table_lookup (attributes, ID_KEY);
const char *origin = g_hash_table_lookup (attributes, ORIGIN_KEY);
const char *target_origin = g_hash_table_lookup (attributes, TARGET_ORIGIN_KEY);
@@ -537,13 +534,23 @@ secret_service_search_cb (SecretService *service,
const char *username_field = g_hash_table_lookup (attributes, USERNAME_FIELD_KEY);
const char *password_field = g_hash_table_lookup (attributes, PASSWORD_FIELD_KEY);
const char *timestamp = g_hash_table_lookup (attributes, SERVER_TIME_MODIFIED_KEY);
- const char *password = secret_value_get (value, NULL);
+ gint64 created = secret_retrievable_get_created (retrievable);
+ gint64 modified = secret_retrievable_get_modified (retrievable);
+ const char *password;
gint64 server_time_modified;
EphyPasswordRecord *record;
LOG ("Found password record for (%s, %s, %s, %s, %s)",
origin, target_origin, username, username_field, password_field);
+ value = secret_retrievable_retrieve_secret_sync (retrievable, NULL, &error);
+ if (!value) {
+ g_warning ("Failed to retrieve password: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ password = secret_value_get_text (value);
+
if (!id || !origin || !target_origin || !timestamp) {
LOG ("Password record is corrupted, skipping it...");
goto next;
@@ -552,8 +559,8 @@ secret_service_search_cb (SecretService *service,
record = ephy_password_record_new (id, origin, target_origin,
username, password,
username_field, password_field,
- secret_item_get_created (item) * 1000,
- secret_item_get_modified (item) * 1000);
+ created * 1000,
+ modified * 1000);
server_time_modified = g_ascii_strtod (timestamp, NULL);
ephy_synchronizable_set_server_time_modified (EPHY_SYNCHRONIZABLE (record),
server_time_modified);
@@ -594,25 +601,24 @@ ephy_password_manager_query (EphyPasswordManager *self,
username_field, password_field, -1);
data = query_async_data_new (callback, user_data);
- secret_service_search (NULL,
- EPHY_FORM_PASSWORD_SCHEMA,
- attributes,
- SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
- NULL,
- (GAsyncReadyCallback)secret_service_search_cb,
- data);
+ secret_password_searchv (EPHY_FORM_PASSWORD_SCHEMA,
+ attributes,
+ SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
+ NULL,
+ (GAsyncReadyCallback)secret_password_search_cb,
+ data);
g_hash_table_unref (attributes);
}
static void
-secret_service_clear_cb (SecretService *service,
- GAsyncResult *result,
- gpointer user_data)
+secret_password_clear_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
GError *error = NULL;
- secret_service_clear_finish (service, result, &error);
+ secret_password_clear_finish (result, &error);
if (error) {
g_warning ("Failed to clear secrets from password schema: %s", error->message);
g_error_free (error);
@@ -651,9 +657,9 @@ ephy_password_manager_forget_record (EphyPasswordManager *self,
ephy_password_record_get_username_field (record),
ephy_password_record_get_password_field (record));
- secret_service_clear (NULL, EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL,
- (GAsyncReadyCallback)secret_service_clear_cb,
- replacement ? manage_record_async_data_new (self, replacement) : NULL);
+ secret_password_clearv (EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL,
+ (GAsyncReadyCallback)secret_password_clear_cb,
+ replacement ? manage_record_async_data_new (self, replacement) : NULL);
ephy_password_manager_cache_remove (self,
ephy_password_record_get_origin (record),
@@ -703,8 +709,8 @@ forget_all_cb (GList *records,
GHashTable *attributes;
attributes = secret_attributes_build (EPHY_FORM_PASSWORD_SCHEMA, NULL);
- secret_service_clear (NULL, EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL,
- (GAsyncReadyCallback)secret_service_clear_cb, NULL);
+ secret_password_clearv (EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL,
+ (GAsyncReadyCallback)secret_password_clear_cb, NULL);
for (GList *l = records; l && l->data; l = l->next)
g_signal_emit_by_name (self, "synchronizable-deleted", l->data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]