1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
/* gkd-ssh-agent-standalone.c - Test standalone SSH agent
4
Copyright (C) 2007 Stefan Walter
6
Gnome keyring is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of the
9
License, or (at your option) any later version.
11
Gnome keyring is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
Author: Stef Walter <stef@memberwebs.com>
25
#include "gkd-ssh-agent.h"
26
#include "gkd-ssh-agent-private.h"
28
#include "egg/egg-secure-memory.h"
30
#include "gp11/gp11.h"
33
#include <glib-object.h>
39
G_LOCK_DEFINE_STATIC (memory_mutex);
41
void egg_memory_lock (void)
42
{ G_LOCK (memory_mutex); }
44
void egg_memory_unlock (void)
45
{ G_UNLOCK (memory_mutex); }
47
void* egg_memory_fallback (void *p, size_t sz)
48
{ return g_realloc (p, sz); }
51
accept_client (GIOChannel *channel, GIOCondition cond, gpointer unused)
53
gkd_ssh_agent_accept ();
58
authenticate_slot (GP11Module *module, GP11Slot *slot, gchar *label, gchar **password, gpointer unused)
60
gchar *prompt = g_strdup_printf ("Enter token password (%s): ", label);
61
char *result = getpass (prompt);
63
*password = g_strdup (result);
64
memset (result, 0, strlen (result));
69
authenticate_object (GP11Module *module, GP11Object *object, gchar *label, gchar **password)
71
gchar *prompt = g_strdup_printf ("Enter object password (%s): ", label);
72
char *result = getpass (prompt);
74
*password = g_strdup (result);
75
memset (result, 0, strlen (result));
80
main(int argc, char *argv[])
91
if (!g_thread_supported ())
95
g_message ("specify pkcs11 module on the command line");
99
module = gp11_module_initialize (argv[1], argc > 2 ? argv[2] : NULL, &error);
101
g_message ("couldn't load pkcs11 module: %s", error->message);
102
g_clear_error (&error);
107
g_signal_connect (module, "authenticate-slot", G_CALLBACK (authenticate_slot), NULL);
108
g_signal_connect (module, "authenticate-object", G_CALLBACK (authenticate_object), NULL);
109
gp11_module_set_auto_authenticate (module, GP11_AUTHENTICATE_OBJECTS);
111
ret = gkd_ssh_agent_initialize_with_module (module);
112
g_object_unref (module);
117
sock = gkd_ssh_agent_startup ("/tmp");
121
channel = g_io_channel_unix_new (sock);
122
g_io_add_watch (channel, G_IO_IN | G_IO_HUP, accept_client, NULL);
123
g_io_channel_unref (channel);
125
g_print ("SSH_AUTH_SOCK=%s\n", g_getenv ("SSH_AUTH_SOCK"));
127
/* Run a main loop */
128
loop = g_main_loop_new (NULL, FALSE);
129
g_main_loop_run (loop);
130
g_main_loop_unref (loop);
132
gkd_ssh_agent_shutdown ();
133
gkd_ssh_agent_uninitialize ();