[gnome-keyring/wip/dueno/ssh-agent] ssh: various fixes



commit 1445781e2287d22c1461f0578b4b306a7190a3b4
Author: Daiki Ueno <dueno src gnome org>
Date:   Mon Dec 11 15:22:57 2017 +0100

    ssh: various fixes

 configure.ac                             |    6 +++---
 daemon/ssh-agent/gkd-ssh-agent-client.c  |    2 +-
 daemon/ssh-agent/gkd-ssh-agent-ops.c     |    5 ++++-
 daemon/ssh-agent/gkd-ssh-agent-preload.c |   18 +++++++-----------
 daemon/ssh-agent/gkd-ssh-interaction.c   |   26 ++++++++++++++++++++++++++
 daemon/ssh-agent/gkd-ssh-openssh.c       |    2 +-
 6 files changed, 42 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9533a06..c713500 100644
--- a/configure.ac
+++ b/configure.ac
@@ -335,12 +335,12 @@ AC_ARG_ENABLE([ssh-agent],
 
 if test "$enable_ssh_agent" != "no"; then
        AC_PATH_PROG([SSH_AGENT], [ssh-agent], [no])
-       AC_PATH_PROG([SSH_ADD], [ssh-agent], [no])
+       AC_PATH_PROG([SSH_ADD], [ssh-add], [no])
        if test "$SSH_AGENT" = "no" -o "$SSH_ADD" = "no"; then
                AC_MSG_ERROR([the ssh-agent and ssh-add commands were not found])
        fi
-       AC_DEFINE_UNQUOTED(SSH_AGENT, "$SSH_AGENT", [The path to ssh-agent]) 
-       AC_DEFINE_UNQUOTED(SSH_ADD, "$SSH_ADD", [The path to ssh-add]) 
+       AC_DEFINE_UNQUOTED(SSH_AGENT, "$SSH_AGENT", [The path to ssh-agent])
+       AC_DEFINE_UNQUOTED(SSH_ADD, "$SSH_ADD", [The path to ssh-add])
        AC_DEFINE(WITH_SSH, 1, [Whether to build SSH agent or not])
        ssh_status="yes"
 else
diff --git a/daemon/ssh-agent/gkd-ssh-agent-client.c b/daemon/ssh-agent/gkd-ssh-agent-client.c
index 98f2773..2cf44c4 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-client.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-client.c
@@ -167,7 +167,7 @@ gkd_ssh_agent_client_connect (void)
                source = g_timeout_add_seconds (5, agent_ready_timeout, &timedout);
                while (started && !ssh_agent_ready && !timedout) {
 g_message ("waiting for agent: %u", (guint)timedout);
-                       g_main_context_iteration (NULL, TRUE);
+                       g_main_context_iteration (NULL, FALSE);
                }
                g_source_remove (source);
 g_message ("waited for agent");
diff --git a/daemon/ssh-agent/gkd-ssh-agent-ops.c b/daemon/ssh-agent/gkd-ssh-agent-ops.c
index 5b68578..00d690e 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-ops.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-ops.c
@@ -154,6 +154,9 @@ op_request_identities (GkdSshAgentCall *call)
        egg_buffer_set_uint32 (call->resp, 5, added + g_hash_table_size (answer));
        g_hash_table_unref (answer);
 
+       /* Set the correct total size of the payload */
+       egg_buffer_set_uint32 (call->resp, 0, call->resp->len - 4);
+
        return TRUE;
 }
 
@@ -207,7 +210,7 @@ op_sign_request (GkdSshAgentCall *call)
        GBytes *key;
 
        /* If parsing the request fails, just pass through */
-       if (egg_buffer_get_byte_array (call->resp, offset, &offset, &blob, &length)) {
+       if (egg_buffer_get_byte_array (call->req, offset, &offset, &blob, &length)) {
                key = g_bytes_new (blob, length);
                preload_key_if_necessary (call->ssh_agent, key);
                g_bytes_unref (key);
diff --git a/daemon/ssh-agent/gkd-ssh-agent-preload.c b/daemon/ssh-agent/gkd-ssh-agent-preload.c
index 5595e43..395d5fb 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-preload.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-preload.c
@@ -123,8 +123,10 @@ file_load_inlock (EggFileTracker *tracker,
                public_key = gkd_ssh_openssh_parse_public_key (public_bytes, &comment);
                if (public_key) {
                        preload = g_new0 (Preload, 1);
-                       preload->filename = g_strdup (path);
+                       preload->filename = private_path;
+                       private_path = NULL;
                        preload->public_key = public_key;
+                       preload->private_file = private_bytes;
                        preload->comment = comment;
                        g_hash_table_replace (preloads_by_filename, preload->filename, preload);
                        g_hash_table_replace (preloads_by_key, preload->public_key, preload);
@@ -229,10 +231,8 @@ gkd_ssh_agent_preload_clear (GBytes *key)
        preload_lock_and_update ();
 
        preload = g_hash_table_lookup (preloads_by_key, key);
-       if (preload) {
-               g_bytes_unref (preload->private_file);
-               preload->private_file = NULL;
-       }
+       if (preload)
+               g_clear_pointer (&preload->private_file, (GDestroyNotify) g_bytes_unref);
 
        preload_unlock ();
 }
@@ -246,12 +246,8 @@ gkd_ssh_agent_preload_clear_all (void)
        preload_lock_and_update ();
 
        g_hash_table_iter_init (&iter, preloads_by_key);
-       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&preload)) {
-               if (preload->private_file) {
-                       g_bytes_unref (preload->private_file);
-                       preload->private_file = NULL;
-               }
-       }
+       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&preload))
+               g_clear_pointer (&preload->private_file, (GDestroyNotify) g_bytes_unref);
 
        preload_unlock ();
 }
diff --git a/daemon/ssh-agent/gkd-ssh-interaction.c b/daemon/ssh-agent/gkd-ssh-interaction.c
index f9d7470..aa3c99a 100644
--- a/daemon/ssh-agent/gkd-ssh-interaction.c
+++ b/daemon/ssh-agent/gkd-ssh-interaction.c
@@ -65,6 +65,30 @@ gkd_ssh_interaction_finalize (GObject *obj)
 }
 
 static void
+on_prompt_password (GObject *source_object,
+                   GAsyncResult *result,
+                   gpointer user_data)
+{
+       GTask *task = G_TASK (user_data);
+       GTlsPassword *password = g_task_get_task_data (task);
+       GcrPrompt *self = GCR_PROMPT (source_object);
+       GError *error = NULL;
+       const gchar *value;
+
+       value = gcr_prompt_password_finish (self, result, &error);
+       if (!value) {
+               g_task_return_error (task, error);
+               g_object_unref (task);
+               return;
+       }
+       g_tls_password_set_value (password, (const guchar *)value, strlen (value));
+       g_object_unref (self);
+
+       g_task_return_boolean (task, TRUE);
+       g_object_unref (task);
+}
+
+static void
 on_prompt_open (GObject *source_object,
                 GAsyncResult *result,
                 gpointer user_data)
@@ -101,6 +125,8 @@ on_prompt_open (GObject *source_object,
        if (g_tls_password_get_flags (password) & G_TLS_PASSWORD_RETRY)
                gcr_prompt_set_warning (prompt, _("The unlock password was incorrect"));
 
+       gcr_prompt_password_async (prompt, g_task_get_cancellable (task), on_prompt_password, g_object_ref 
(task));
+
        g_object_unref (task);
 }
 
diff --git a/daemon/ssh-agent/gkd-ssh-openssh.c b/daemon/ssh-agent/gkd-ssh-openssh.c
index 5453f8c..e197d4f 100644
--- a/daemon/ssh-agent/gkd-ssh-openssh.c
+++ b/daemon/ssh-agent/gkd-ssh-openssh.c
@@ -68,7 +68,7 @@ gkd_ssh_openssh_parse_public_key (GBytes *input,
        /* Decode the base64 key */
        save = state = 0;
        decoded = g_malloc (n_data * 3 / 4);
-       n_decoded = g_base64_decode_step ((gchar*)data, n_data, decoded, &state, &save);
+       n_decoded = g_base64_decode_step ((gchar*)data, at - data, decoded, &state, &save);
 
        if (!n_decoded) {
                g_free (decoded);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]