summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@redhat.com>2014-10-26 13:42:40 +0100
committerDaiki Ueno <dueno@src.gnome.org>2018-02-12 15:11:38 +0100
commit3fc02adcb6d6fa54c1cc8c1498b48a5d24a95bbf (patch)
tree0d81e66d85aace81fb28fe939b7fc5c76d18da83
parentdd091615250fb3e24f88f7b7e76bbedb49c9120f (diff)
downloadgnome-keyring-3fc02adcb6d6fa54c1cc8c1498b48a5d24a95bbf.tar.gz
WIP ssh more
-rw-r--r--configure.ac6
-rw-r--r--daemon/ssh-agent/gkd-ssh-agent-ops.c23
-rw-r--r--daemon/ssh-agent/gkd-ssh-agent-preload.h2
-rw-r--r--daemon/ssh-agent/gkd-ssh-interaction.c103
4 files changed, 129 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 9a6a503b..2cb108e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -349,10 +349,12 @@ AC_ARG_ENABLE([ssh-agent],
if test "$enable_ssh_agent" != "no"; then
AC_PATH_PROG([SSH_AGENT], [ssh-agent], [no])
- if test "$SSH_AGENT" = "no"; then
- AC_MSG_ERROR([the ssh-agent command was not found])
+ AC_PATH_PROG([SSH_ADD], [ssh-agent], [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(WITH_SSH, 1, [Whether to build SSH agent or not])
ssh_status="yes"
else
diff --git a/daemon/ssh-agent/gkd-ssh-agent-ops.c b/daemon/ssh-agent/gkd-ssh-agent-ops.c
index beb2c122..5278fe1a 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-ops.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-ops.c
@@ -30,6 +30,8 @@
#include "egg/egg-error.h"
#include "egg/egg-secure-memory.h"
+#include <gcr/gcr-base.h>
+
#include <glib.h>
#include <ctype.h>
@@ -156,6 +158,20 @@ op_request_identities (GkdSshAgentCall *call)
}
static void
+on_ssh_add_prompting (GcrSystemInteraction *interaction,
+ GcrPrompt *prompt,
+ gint prompt_type,
+ gpointer user_data)
+{
+ if (prompt_type == 1) {
+ choice = NULL;
+ if (gkd_login_available ())
+ choice = _("Automatically unlock this key, whenever I'm logged in");
+ gcr_prompt_set_choice_label (prompt, choice);
+ }
+}
+
+static void
preload_key_if_necessary (gint ssh_agent,
GBytes *key)
{
@@ -175,8 +191,9 @@ preload_key_if_necessary (gint ssh_agent,
if (!filename)
return;
- prompt = gcr_system_prompt_new ();
- askpass = gcr_ssh_askpass_new (G_TLS_INTERACTION (prompt));
+ interaction = gcr_system_interaction_new (_("Secure Shell Key"));
+ g_signal_connect (intercation, "prompting", G_CALLBACK (on_ssh_add_prompting), NULL);
+ askpass = gcr_ssh_askpass_new (interaction);
g_object_unref (interaction);
if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_DEFAULT,
@@ -185,7 +202,7 @@ preload_key_if_necessary (gint ssh_agent,
g_warning ("cannot run %s: %s", argv[0], error->message);
} else if (!g_spawn_check_exit_status (status, &error)) {
- g_message ("the %s command failed: %s", error->message);
+ g_message ("the %s command failed: %s", argv[0], error->message);
} else {
gkd_ssh_agent_preload_clear (key);
diff --git a/daemon/ssh-agent/gkd-ssh-agent-preload.h b/daemon/ssh-agent/gkd-ssh-agent-preload.h
index 503b25ef..00d1ce21 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-preload.h
+++ b/daemon/ssh-agent/gkd-ssh-agent-preload.h
@@ -30,6 +30,8 @@ GList * gkd_ssh_agent_preload_keys (void);
gchar * gkd_ssh_agent_preload_comment (GBytes *key);
+gchar * gkd_ssh_agent_preload_path (GBytes *key);
+
GBytes * gkd_ssh_agent_preload_private (GBytes *key);
void gkd_ssh_agent_preload_clear (GBytes *key);
diff --git a/daemon/ssh-agent/gkd-ssh-interaction.c b/daemon/ssh-agent/gkd-ssh-interaction.c
new file mode 100644
index 00000000..c52333c4
--- /dev/null
+++ b/daemon/ssh-agent/gkd-ssh-interaction.c
@@ -0,0 +1,103 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* gkd-ssh-interaction.c
+
+ Copyright (C) 2014 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ see <http://www.gnu.org/licenses/>.
+
+ Author: Stef Walter <stefw@gnome.org>
+*/
+
+#include "config.h"
+
+#include "gkd-ssh-interaction.h"
+
+#define MOCK_INTERACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOCK_TYPE_INTERACTION, MockInteraction))
+#define MOCK_IS_INTERACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOCK_TYPE_INTERACTION))
+#define MOCK_INTERACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOCK_TYPE_INTERACTION, MockInteractionClass))
+
+typedef struct _MockInteractionClass MockInteractionClass;
+
+struct _MockInteraction {
+ GTlsInteraction interaction;
+};
+
+struct _MockInteractionClass {
+ GTlsInteractionClass parent;
+};
+
+G_DEFINE_TYPE (MockInteraction, mock_interaction, G_TYPE_TLS_INTERACTION);
+
+static void
+mock_interaction_init (MockInteraction *self)
+{
+
+}
+
+static void
+mock_interaction_finalize (GObject *obj)
+{
+ MockInteraction *self = MOCK_INTERACTION (obj);
+
+ g_free (self->password);
+
+ G_OBJECT_CLASS (mock_interaction_parent_class)->dispose (obj);
+}
+
+static GTlsInteractionResult
+mock_interaction_ask_password_async (GTlsInteraction *interaction,
+ GTlsPassword *password,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_task_new ();
+
+ if (gkd_login_available() && self->keyid) {
+ xxxx = gkd_login_lookup (self->keyid);
+ g_tls_password_set_value (password, xxxx);
+
+ }
+
+ MockInteraction *self = MOCK_INTERACTION (interaction);
+
+ if (self->password) {
+ g_tls_password_set_value (password, (const guchar *)self->password, -1);
+ return G_TLS_INTERACTION_HANDLED;
+ } else {
+ return G_TLS_INTERACTION_UNHANDLED;
+ }
+}
+
+static void
+mock_interaction_class_init (MockInteractionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GTlsInteractionClass *interaction_class = G_TLS_INTERACTION_CLASS (klass);
+
+ object_class->finalize = mock_interaction_finalize;
+
+ interaction_class->ask_password = mock_interaction_ask_password;
+}
+
+GTlsInteraction *
+mock_interaction_new (const gchar *password)
+{
+ MockInteraction *result;
+
+ result = g_object_new (MOCK_TYPE_INTERACTION, NULL);
+ result->password = g_strdup (password);
+
+ return G_TLS_INTERACTION (result);
+}