1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-10 23:49:50 +02:00

2004-09-27 Moritz Schulte <moritz@g10code.com>

**MERGED FROM MAIN BRANCH, RE-PATCHED**

	* command-ssh.c: New file.

	* findkey.c (modify_description): New function.
	(agent_key_from_file): New variables: comment, comment_sexp,
	comment_length, desc_text_modified; extract comment from S-Exp,
	pass modified version to unprotect().

	* agent.h: Declare: start_command_handler_ssh.
	(struct opt): New member: ssh_support.

	* gpg-agent.c: Include <sys/select.h>.
	New configuration option: ssh-support.
	(socket_name_ssh): New variabel.
	(handle_connections): Additional argument: listen_fd_ssh.  Accept
	connections on both sockets, call start_connection_thread_ssh for
	connections on listen_fd_ssh.
	(start_connection_thread_ssh): New function.
	(cleanup_do): New functions, basically old cleanup function.
	(cleanup): Call cleanup_do for socket_name and socket_name_ssh.
	(server_socket_create): New function ...
	(main): ... use it.
	(main): Generate environment entries for ssh.

	* query.c (start_pinentry): Accept CTRL being NULL.
This commit is contained in:
Moritz Schulte 2004-09-27 06:45:09 +00:00
parent a8dfea6457
commit 3504abfa29
7 changed files with 1799 additions and 1135 deletions

View File

@ -1,72 +1,16 @@
2004-08-09 Moritz Schulte <moritz@g10code.com>
2004-09-27 Moritz Schulte <moritz@g10code.com>
* findkey.c (modify_description): Accept description being NULL.
**MERGED FROM MAIN BRANCH, RE-PATCHED**
2004-08-07 Moritz Schulte <moritz@g10code.com>
* command-ssh.c (ssh_key_to_sexp_buffer): New argument: comment;
integrate into S-Exp.
(ssh_identity_register): New argument: comment; pass to
ssh_key_to_sexp_buffer().
(ssh_handler_add_identity): Pass comment to
ssh_identity_register().
(ssh_identity_register): Allocate description dynamically, insert
comment; new variable: description_length; removed variable: i.
(data_sign): Do not calculate key grip for integration in
description; removed variable: i.
* command-ssh.c: New file.
* findkey.c (modify_description): New function.
(agent_key_from_file): New variables: comment, comment_sexp,
comment_length, desc_text_modified; extract comment from S-Exp,
pass modified version to unprotect().
2004-07-30 Moritz Schulte <moritz@g10code.com>
* command-ssh.c: Updated Libgpg-stream (more support for secure
memory), adjusted code for new API.
2004-07-27 Moritz Schulte <moritz@g10code.com>
* findkey.c (key_io_lock): New variable.
* command-ssh.c: Use gcrypt memory allocators, use secure memory
where necessary.
2004-07-26 Moritz Schulte <moritz@g10code.com>
* command-ssh.c (data_sign): Do not forget to unsigned char when
constructing human-readable key grip.
* Makefile.am (gpg_agent_SOURCES): Removed: buffer.c, buffer.h;
updated Libgpg-stream.
2004-07-24 Moritz Schulte <moritz@g10code.com>
* gpg-stream-config.h: New file (was missing before).
2004-07-19 Moritz Schulte <moritz@g10code.com>
* command-ssh.c: Only log debugging message if asked to do so.
* command-ssh.c (gpg_stream_copy): Remove function.
Update Libgpg-stream.
* command-ssh.c: Fix handling of iqmp vs. u.
* command-ssh.c (ssh_identity_register): passphrase must not be freed.
* Makefile.am (gpg_agent_SOURCES): Adding: gpg-stream.c,
gpg-stream.h, buffer.c, buffer.h, command-ssh.c.
* pksign.c (agent_pksign_do): New function, based on code ripped
out from agent_pksign.
(agent_pksign): Use agent_pksign_do.
* query.c (start_pinentry): Accept CTRL being NULL.
* agent.h (start_command_handler_ssh): Declare function.
(agent_pksign_do): Declare function.
(opt): New member: ssh_support.
* agent.h: Declare: start_command_handler_ssh.
(struct opt): New member: ssh_support.
* gpg-agent.c: Include <sys/select.h>.
New configuration option: ssh-support.
@ -81,9 +25,52 @@
(main): ... use it.
(main): Generate environment entries for ssh.
* command-ssh.c: New file, implementing the ssh-agent protocol.
* gpg-stream.c, gpg-stream.h, buffer.c, buffer.h: Merged
Libgpg-stream.
* query.c (start_pinentry): Accept CTRL being NULL.
2004-09-25 Moritz Schulte <moritz@g10code.com>
* agent.h: Declare: agent_pksign_do.
(struct server_control_s): New member: raw_value.
* pksign.c (do_encode_md): New argument: raw_value; support
generation of raw (non-pkcs1) data objects; adjust callers.
(agent_pksign_do): New function, based on code ripped
out from agent_pksign.
(agent_pksign): Use agent_pksign_do.
* command.c (start_command_handler): Set ctrl.digest.raw_value.
2004-09-09 Werner Koch <wk@g10code.de>
* gpg-agent.c (check_for_running_agent): New.
(main): The default action is now to check for an already running
agent.
(parse_rereadable_options): Set logfile only on reread.
(main): Do not print the "is development version" note.
2004-08-20 Werner Koch <wk@g10code.de>
* gpg-agent.c: New option --max-cache-ttl. Suggested by Alexander
Belopolsky.
* cache.c (housekeeping): Use it here instead of the hardwired
default of 1 hour.
* query.c (start_pinentry): Use a timeout for the pinentry lock.
2004-08-18 Werner Koch <wk@g10code.de>
* protect-tool.c (get_passphrase): Make sure that the default
prompts passed to gpg-agent are utf-8 encoded. Add new prompt values.
(import_p12_file, import_p12_file, export_p12_file): Changed calls
to get_passphrase so that better prompts are displayed.
(get_new_passphrase): New.
2004-07-22 Werner Koch <wk@g10code.de>
* trustlist.c (read_list): Allow colons in the fingerprint.
(headerblurb): Rephrased.
* gpg-agent.c (handle_connections): Increase the stack size ot 256k.
2004-06-20 Moritz Schulte <moritz@g10code.com>

View File

@ -54,6 +54,7 @@ struct {
const char *scdaemon_program;
int no_grab; /* don't let the pinentry grab the keyboard */
unsigned long def_cache_ttl;
unsigned long max_cache_ttl;
int running_detached; /* we are running detached from the tty. */
@ -61,7 +62,7 @@ struct {
int allow_mark_trusted;
int keep_tty; /* don't switch the TTY (for pinentry) on request */
int keep_display; /* don't switch the DISPLAY (for pinentry) on request */
int ssh_support; /* enable SSH-Agent emulation. */
int ssh_support; /* Enable ssh-agent emulation. */
} opt;
@ -95,6 +96,7 @@ struct server_control_s {
int algo;
unsigned char value[MAX_DIGEST_LEN];
int valuelen;
int raw_value: 1;
} digest;
char keygrip[20];
int have_keygrip;

File diff suppressed because it is too large Load Diff

View File

@ -854,6 +854,7 @@ start_command_handler (int listen_fd, int fd)
ctrl.server_local->assuan_ctx = ctx;
ctrl.server_local->message_fd = -1;
ctrl.server_local->use_cache_for_signing = 1;
ctrl.digest.raw_value = 0;
if (DBG_ASSUAN)
assuan_set_log_stream (ctx, log_get_stream ());

View File

@ -78,15 +78,17 @@ enum cmd_and_opt_values
oLCctype,
oLCmessages,
oScdaemonProgram,
oDefCacheTTL,
oDisablePth,
oDefCacheTTL,
oMaxCacheTTL,
oIgnoreCacheForSigning,
oAllowMarkTrusted,
oKeepTTY,
oKeepDISPLAY,
aTest,
oSSHSupport };
oSSHSupport,
aTest };
@ -128,17 +130,18 @@ static ARGPARSE_OPTS opts[] = {
{ oDefCacheTTL, "default-cache-ttl", 4,
N_("|N|expire cached PINs after N seconds")},
{ oMaxCacheTTL, "max-cache-ttl", 4, "@" },
{ oIgnoreCacheForSigning, "ignore-cache-for-signing", 0,
N_("do not use the PIN cache when signing")},
{ oAllowMarkTrusted, "allow-mark-trusted", 0,
N_("allow clients to mark keys as \"trusted\"")},
{ oSSHSupport, "ssh-support", 0, "Enable SSH-Agent emulation" },
{0}
};
#define DEFAULT_CACHE_TTL (10*60) /* 10 minutes */
#define DEFAULT_CACHE_TTL (10*60) /* 10 minutes */
#define MAX_CACHE_TTL (120*60) /* 2 hours */
static volatile int caught_fatal_sig = 0;
@ -181,6 +184,7 @@ static void handle_connections (int listen_fd, int listen_fd_ssh);
GCRY_THREAD_OPTION_PTH_IMPL;
#endif /*USE_GNU_PTH*/
static void check_for_running_agent (void);
@ -286,6 +290,7 @@ set_debug (void)
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1);
gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
}
static void
cleanup_do (char *name)
@ -353,6 +358,7 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
opt.pinentry_program = NULL;
opt.scdaemon_program = NULL;
opt.def_cache_ttl = DEFAULT_CACHE_TTL;
opt.max_cache_ttl = MAX_CACHE_TTL;
opt.ignore_cache_for_signing = 0;
opt.allow_mark_trusted = 0;
return 1;
@ -368,8 +374,9 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
case oDebugLevel: debug_level = pargs->r.ret_str; break;
case oLogFile:
if (!current_logfile || !pargs->r.ret_str
|| strcmp (current_logfile, pargs->r.ret_str))
if (reread
&& (!current_logfile || !pargs->r.ret_str
|| strcmp (current_logfile, pargs->r.ret_str)))
{
log_set_file (pargs->r.ret_str);
xfree (current_logfile);
@ -383,6 +390,7 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
case oScdaemonProgram: opt.scdaemon_program = pargs->r.ret_str; break;
case oDefCacheTTL: opt.def_cache_ttl = pargs->r.ret_ulong; break;
case oMaxCacheTTL: opt.max_cache_ttl = pargs->r.ret_ulong; break;
case oIgnoreCacheForSigning: opt.ignore_cache_for_signing = 1; break;
@ -394,6 +402,7 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
return 1; /* handled */
}
static void
server_socket_create (int *sock,
const char *identifier, char *name, int name_size)
@ -681,7 +690,9 @@ main (int argc, char **argv )
fprintf (stderr, "%s\n", strusage(15) );
}
#ifdef IS_DEVELOPMENT_VERSION
log_info ("NOTE: this is a development version!\n");
/* We don't want to print it here because gpg-agent is useful of its
own and quite matured. */
/*log_info ("NOTE: this is a development version!\n");*/
#endif
set_debug ();
@ -751,9 +762,15 @@ main (int argc, char **argv )
agent_exit (0);
}
/* If this has been called without any options, we merely check
whether an agent is already running. We do this here so that we
don't clobber a logfile but print it directly to stderr. */
if (!pipe_server && !is_daemon)
log_info (_("please use the option `--daemon'"
" to run the program in the background\n"));
{
log_set_prefix (NULL, JNLIB_LOG_WITH_PREFIX);
check_for_running_agent ();
agent_exit (0);
}
#ifdef ENABLE_NLS
/* gpg-agent usually does not output any messages because it runs in
@ -787,12 +804,11 @@ main (int argc, char **argv )
start_command_handler (-1, -1);
}
else if (!is_daemon)
;
; /* NOTREACHED */
else
{ /* regular server mode */
{ /* Regular server mode */
int fd = -1, fd_ssh = -1;
pid_t pid;
//char *p;
/* Remove the DISPLAY variable so that a pinentry does not
default to a specific display. There is still a default
@ -806,7 +822,6 @@ main (int argc, char **argv )
server_socket_create (&fd_ssh, "-ssh",
socket_name_ssh, sizeof (socket_name_ssh));
if (opt.verbose)
{
log_info ("listening on socket `%s'\n", socket_name);
@ -814,6 +829,7 @@ main (int argc, char **argv )
log_info ("listening on socket `%s'\n", socket_name_ssh);
}
fflush (NULL);
pid = fork ();
if (pid == (pid_t)-1)
@ -826,8 +842,6 @@ main (int argc, char **argv )
char *infostr, *infostr_ssh_sock, *infostr_ssh_pid;
close (fd);
if (opt.ssh_support)
close (fd_ssh);
/* create the info string: <name>:<pid>:<protocol_version> */
if (asprintf (&infostr, "GPG_AGENT_INFO=%s:%lu:1",
@ -858,7 +872,7 @@ main (int argc, char **argv )
*socket_name = 0; /* don't let cleanup() remove the socket -
the child should do this from now on */
*socket_name_ssh = 0;
if (argc)
{ /* run the program given on the commandline */
if (putenv (infostr))
@ -994,7 +1008,7 @@ main (int argc, char **argv )
}
close (fd);
}
return 0;
}
@ -1235,6 +1249,7 @@ start_connection_thread (void *arg)
return NULL;
}
static void *
start_connection_thread_ssh (void *arg)
{
@ -1268,7 +1283,12 @@ handle_connections (int listen_fd, int listen_fd_ssh)
int ret = -1;
int fd;
sigemptyset (&sigs);
tattr = pth_attr_new();
pth_attr_set (tattr, PTH_ATTR_JOINABLE, 0);
pth_attr_set (tattr, PTH_ATTR_STACK_SIZE, 64);
pth_attr_set (tattr, PTH_ATTR_NAME, "gpg-agent");
sigemptyset (&sigs );
sigaddset (&sigs, SIGHUP);
sigaddset (&sigs, SIGUSR1);
sigaddset (&sigs, SIGUSR2);
@ -1276,11 +1296,6 @@ handle_connections (int listen_fd, int listen_fd_ssh)
sigaddset (&sigs, SIGTERM);
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
tattr = pth_attr_new();
pth_attr_set (tattr, PTH_ATTR_JOINABLE, 0);
pth_attr_set (tattr, PTH_ATTR_STACK_SIZE, 32*1024);
pth_attr_set (tattr, PTH_ATTR_NAME, "gpg-agent");
FD_ZERO (&fdset);
FD_SET (listen_fd, &fdset);
if (listen_fd_ssh != -1)
@ -1370,4 +1385,58 @@ handle_connections (int listen_fd, int listen_fd_ssh)
cleanup ();
log_info ("%s %s stopped\n", strusage(11), strusage(13));
}
#endif /*USE_GNU_PTH*/
/* Figure out whether an agent is available and running. Prints an
error if not. */
static void
check_for_running_agent ()
{
int rc;
char *infostr, *p;
assuan_context_t ctx;
int prot, pid;
infostr = getenv ("GPG_AGENT_INFO");
if (!infostr || !*infostr)
{
log_error (_("no gpg-agent running in this session\n"));
return;
}
infostr = xstrdup (infostr);
if ( !(p = strchr (infostr, ':')) || p == infostr)
{
log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
xfree (infostr);
return;
}
*p++ = 0;
pid = atoi (p);
while (*p && *p != ':')
p++;
prot = *p? atoi (p+1) : 0;
if (prot != 1)
{
log_error (_("gpg-agent protocol version %d is not supported\n"),
prot);
xfree (infostr);
return;
}
rc = assuan_socket_connect (&ctx, infostr, pid);
xfree (infostr);
if (rc)
{
log_error ("can't connect to the agent: %s\n", assuan_strerror (rc));
return;
}
if (!opt.quiet)
log_info ("gpg-agent running and available\n");
assuan_disconnect (ctx);
}

View File

@ -32,24 +32,45 @@
static int
do_encode_md (const byte * md, size_t mdlen, int algo, gcry_sexp_t * r_hash)
do_encode_md (const byte * md, size_t mdlen, int algo, gcry_sexp_t * r_hash,
int raw_value)
{
gcry_sexp_t hash;
const char *s;
char tmp[16+1];
int i, rc;
int rc;
s = gcry_md_algo_name (algo);
if (s && strlen (s) < 16)
if (! raw_value)
{
for (i=0; i < strlen (s); i++)
tmp[i] = tolower (s[i]);
tmp[i] = '\0';
const char *s;
char tmp[16+1];
int i;
s = gcry_md_algo_name (algo);
if (s && strlen (s) < 16)
{
for (i=0; i < strlen (s); i++)
tmp[i] = tolower (s[i]);
tmp[i] = '\0';
}
rc = gcry_sexp_build (&hash, NULL,
"(data (flags pkcs1) (hash %s %b))",
tmp, mdlen, md);
}
rc = gcry_sexp_build (&hash, NULL,
"(data (flags pkcs1) (hash %s %b))",
tmp,
mdlen, md);
else
{
gcry_mpi_t mpi;
rc = gcry_mpi_scan (&mpi, GCRYMPI_FMT_USG, md, mdlen, NULL);
if (! rc)
{
rc = gcry_sexp_build (&hash, NULL,
"(data (flags raw) (value %m))",
mpi);
gcry_mpi_release (mpi);
}
}
*r_hash = hash;
return rc;
}
@ -115,7 +136,8 @@ agent_pksign_do (CTRL ctrl, const char *desc_text,
rc = do_encode_md (ctrl->digest.value,
ctrl->digest.valuelen,
ctrl->digest.algo,
&s_hash);
&s_hash,
ctrl->digest.raw_value);
if (rc)
goto leave;
@ -143,8 +165,7 @@ agent_pksign_do (CTRL ctrl, const char *desc_text,
leave:
if (! rc)
*signature_sexp = s_sig;
*signature_sexp = s_sig;
gcry_sexp_release (s_skey);
xfree (shadow_info);

View File

@ -41,6 +41,14 @@
#define MAX_OPEN_FDS 20
#endif
/* Because access to the pinentry must be serialized (it is and shall
be a global mutual dialog) we should better timeout further
requests after some time. 2 minutes seem to be a reasonable
time. */
#define LOCK_TIMEOUT (1*60)
static ASSUAN_CONTEXT entry_ctx = NULL;
#ifdef USE_GNU_PTH
static pth_mutex_t entry_lock = PTH_MUTEX_INIT;
@ -104,11 +112,23 @@ start_pinentry (CTRL ctrl)
int i;
#ifdef USE_GNU_PTH
if (!pth_mutex_acquire (&entry_lock, 0, NULL))
{
pth_event_t evt;
evt = pth_event (PTH_EVENT_TIME, pth_timeout (LOCK_TIMEOUT, 0));
if (!pth_mutex_acquire (&entry_lock, 0, evt))
{
log_error ("failed to acquire the entry lock\n");
return gpg_error (GPG_ERR_INTERNAL);
if (pth_event_occurred (evt))
rc = gpg_error (GPG_ERR_TIMEOUT);
else
rc = gpg_error (GPG_ERR_INTERNAL);
pth_event_free (evt, PTH_FREE_THIS);
log_error (_("failed to acquire the pinentry lock: %s\n"),
gpg_strerror (rc));
return rc;
}
pth_event_free (evt, PTH_FREE_THIS);
}
#endif
if (entry_ctx)
@ -132,7 +152,7 @@ start_pinentry (CTRL ctrl)
pgmname++;
argv[0] = pgmname;
if ((ctrl && ctrl->display) && !opt.keep_display)
if (ctrl && ctrl->display && !opt.keep_display)
{
argv[1] = "--display";
argv[2] = ctrl->display;