1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

2005-01-26 Moritz Schulte <moritz@g10code.com>

* command-ssh.c: New file.
	* Makefile.am (gpg_agent_SOURCES): New source file: command-ssh.c.

	* findkey.c (modify_description): New function.
	(agent_key_from_file): Support comment field in key s-expressions.

	* gpg-agent.c (enum cmd_and_opt_values): New item: oSSHSupport.
	(opts) New entry for oSSHSupport.
	New variable: socket_name_ssh.
	(cleanup_do): New function based on cleanup().
	(cleanup): Use cleanup_do() for socket_name and socket_name_ssh.
	(main): New switch case for oSSHSupport.
	(main): Move socket name creation code to ...
	(create_socket_name): ... this new function.
	(main): Use create_socket_name() for creating socket names for
	socket_name and for socket_name_ssh in case ssh support is
	enabled.
	Move socket creation code to ...
	(create_server_socket): ... this new function.
	(main): Use create_server_socket() for creating sockets.
	In case standard_socket is set, do not only store a socket name in
	socket_name, but also in socket_name_ssh.
	Generate additional environment info strings for ssh support.
	Pass additional ssh socket argument to handle_connections.
	(start_connection_thread_ssh): New function.
	(handle_connections): Use select to multiplex between gpg-agent
	and ssh-agent protocol.

	* agent.h (struct opt): New member: ssh_support.
	Declare function: start_command_handler_ssh.
This commit is contained in:
Moritz Schulte 2005-01-26 22:20:21 +00:00
parent 6cb495ca5c
commit a5d3f8a6e7
5 changed files with 468 additions and 126 deletions

View file

@ -1,5 +1,5 @@
/* findkey.c - locate the secret key
* Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
* Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -140,6 +140,108 @@ try_unprotect_cb (struct pin_entry_info_s *pi)
}
/* Modify a Key description, replacing certain special format
characters. List of currently supported replacements:
%% -> %
%c -> <COMMENT>. */
static int
modify_description (const char *description,
const char *comment, size_t comment_length,
char **description_modified)
{
size_t description_length;
size_t description_new_length;
gpg_error_t err;
char *description_new;
unsigned int i, j;
unsigned int special;
description_length = strlen (description);
description_new_length = description_length;
description_new = NULL;
/* Calculate length. */
special = 0;
for (i = 0; i < description_length; i++)
{
if (description[i] == '%')
special = 1;
else
{
if (special)
{
description_new_length -= 2;
switch (description[i])
{
case 'c':
/* Comment. */
description_new_length += comment_length;
break;
case '%':
description_new_length += 1;
break;
}
special = 0;
}
}
}
/* Allocate. */
description_new = xtrymalloc (description_new_length + 1);
if (! description_new)
{
err = gpg_error_from_errno (errno);
goto out;
}
/* Fill. */
for (i = j = 0; i < description_length; i++)
{
if (description[i] == '%')
special = 1;
else
{
if (special)
{
switch (description[i])
{
case 'c':
/* Comment. */
if (comment)
{
strncpy (description_new + j, comment, comment_length);
j += comment_length;
}
break;
case '%':
description_new[j] = '%';
j++;
break;
}
special = 0;
}
else
{
description_new[j] = description[i];
j++;
}
}
}
description_new[j] = 0;
*description_modified = description_new;
err = 0;
out:
return err;
}
/* Unprotect the canconical encoded S-expression key in KEYBUF. GRIP
should be the hex encoded keygrip of that key to be used with the
caching mechanism. DESC_TEXT may be set to override the default
@ -292,10 +394,42 @@ agent_key_from_file (CTRL ctrl, const char *desc_text,
case PRIVATE_KEY_CLEAR:
break; /* no unprotection needed */
case PRIVATE_KEY_PROTECTED:
rc = unprotect (ctrl, desc_text, &buf, grip, ignore_cache);
if (rc)
log_error ("failed to unprotect the secret key: %s\n",
gpg_strerror (rc));
{
gcry_sexp_t comment_sexp;
size_t comment_length;
char *desc_text_final;
const char *comment;
comment_sexp = gcry_sexp_find_token (s_skey, "comment", 0);
if (comment_sexp)
comment = gcry_sexp_nth_data (comment_sexp, 1, &comment_length);
else
{
comment = NULL;
comment_length = 0;
}
if (desc_text)
{
rc = modify_description (desc_text,
comment, comment_length, &desc_text_final);
if (rc)
log_error ("failed to modify description: %s\n", gpg_strerror (rc));
}
else
desc_text_final = NULL;
if (! rc)
{
rc = unprotect (ctrl, desc_text_final, &buf, grip, ignore_cache);
if (rc)
log_error ("failed to unprotect the secret key: %s\n",
gpg_strerror (rc));
}
gcry_sexp_release (comment_sexp);
xfree (desc_text_final);
}
break;
case PRIVATE_KEY_SHADOWED:
if (shadow_info)