aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-04-10 07:23:44 +0000
committerWerner Koch <[email protected]>2003-04-10 07:23:44 +0000
commited16a85de8a28a55d1325613be41bc2853e0bf36 (patch)
tree5d348254cd941f04b4934bff0bc3a9a61bfd7326
parent* passphrase .c (agent_get_passphrase): New arg CANCELED. (diff)
downloadgnupg-ed16a85de8a28a55d1325613be41bc2853e0bf36.tar.gz
gnupg-ed16a85de8a28a55d1325613be41bc2853e0bf36.zip
* passphrase.c (read_passphrase_from_fd): Do a dummy read if the
agent is to be used. Noted by Ingo Kl�cker. (agent_get_passphrase): Inhibit caching when we have no fingerprint. This is required for key generation as well as for symmetric only encryption.
-rw-r--r--g10/ChangeLog8
-rw-r--r--g10/passphrase.c75
2 files changed, 48 insertions, 35 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index ac6050cc5..5a6b97a71 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,11 @@
+2003-04-10 Werner Koch <[email protected]>
+
+ * passphrase.c (read_passphrase_from_fd): Do a dummy read if the
+ agent is to be used. Noted by Ingo Kl�cker.
+ (agent_get_passphrase): Inhibit caching when we have no
+ fingerprint. This is required for key generation as well as for
+ symmetric only encryption.
+
2003-04-09 Werner Koch <[email protected]>
* passphrase .c (agent_get_passphrase): New arg CANCELED.
diff --git a/g10/passphrase.c b/g10/passphrase.c
index 1a421f907..fc2414ca3 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -147,33 +147,43 @@ get_last_passphrase()
void
read_passphrase_from_fd( int fd )
{
- int i, len;
- char *pw;
-
- if ( opt.use_agent )
- return; /* not used here */
-
- if( !opt.batch )
- tty_printf("Reading passphrase from file descriptor %d ...", fd );
- for( pw = NULL, i = len = 100; ; i++ ) {
- if( i >= len-1 ) {
- char *pw2 = pw;
- len += 100;
- pw = m_alloc_secure( len );
- if( pw2 )
- memcpy(pw, pw2, i );
- else
- i=0;
- }
- if( read( fd, pw+i, 1) != 1 || pw[i] == '\n' )
- break;
+ int i, len;
+ char *pw;
+
+ if (opt.use_agent)
+ { /* Not used but we have to do a dummy read, so that it won't end
+ up at the begin of the message if the quite usual trick to
+ prepend the passphtrase to the message is used. */
+ char buf[1];
+
+ while (!(read (fd, buf, 1) != 1 || *buf == '\n' ))
+ ;
+ *buf = 0;
+ return;
+ }
+
+ if( !opt.batch )
+ tty_printf("Reading passphrase from file descriptor %d ...", fd );
+ for (pw = NULL, i = len = 100; ; i++ )
+ {
+ if( i >= len-1 ) {
+ char *pw2 = pw;
+ len += 100;
+ pw = m_alloc_secure( len );
+ if( pw2 )
+ memcpy(pw, pw2, i );
+ else
+ i=0;
+ }
+ if (read( fd, pw+i, 1) != 1 || pw[i] == '\n' )
+ break;
}
- pw[i] = 0;
- if( !opt.batch )
- tty_printf("\b\b\b \n" );
+ pw[i] = 0;
+ if (!opt.batch)
+ tty_printf ("\b\b\b \n" );
- m_free( fd_passwd );
- fd_passwd = pw;
+ m_free( fd_passwd );
+ fd_passwd = pw;
}
static int
@@ -614,6 +624,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
char *pw = NULL;
PKT_public_key *pk = m_alloc_clear( sizeof *pk );
byte fpr[MAX_FINGERPRINT_LEN];
+ int have_fpr = 0;
int prot;
char *orig_codeset = NULL;
@@ -635,21 +646,15 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
#ifdef ENABLE_NLS
/* The Assuan agent protol requires us to trasnmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE, NULL);
- log_debug ("old codeset: `%s'\n", orig_codeset);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
- {
- orig_codeset = nl_langinfo (CODESET);
- log_debug ("assuming `%s'\n", orig_codeset);
- }
+ orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset)
{ /* We only switch when we are able to restore the codeset later. */
orig_codeset = m_strdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE, "utf-8"))
orig_codeset = NULL;
- log_debug ("switched to: `%s'\n",
- bind_textdomain_codeset (PACKAGE, NULL));
}
#endif
@@ -695,6 +700,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
{
size_t dummy;
fingerprint_from_pk( pk, fpr, &dummy );
+ have_fpr = 1;
}
}
@@ -783,12 +789,12 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
tryagain_text = _(tryagain_text);
/* We allocate 2 time the needed space for atext so that there
- is nenough space for escaping */
+ is enough space for escaping */
line = m_alloc (15 + 46
+ 3*strlen (tryagain_text) + 3*strlen (atext) + 2);
strcpy (line, "GET_PASSPHRASE ");
p = line+15;
- if (!mode)
+ if (!mode && have_fpr)
{
for (i=0; i < 20; i++, p +=2 )
sprintf (p, "%02X", fpr[i]);
@@ -872,7 +878,6 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
#ifdef ENABLE_NLS
if (orig_codeset)
bind_textdomain_codeset (PACKAGE, orig_codeset);
- log_debug ("restored to: `%s'\n", bind_textdomain_codeset (PACKAGE, NULL));
#endif
m_free (atext);
if ( fd != -1 )