mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-22 14:57:02 +01:00
* 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.
This commit is contained in:
parent
3ff3ac5ba4
commit
ed16a85de8
@ -1,3 +1,11 @@
|
|||||||
|
2003-04-10 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
* 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 <wk@gnupg.org>
|
2003-04-09 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* passphrase .c (agent_get_passphrase): New arg CANCELED.
|
* passphrase .c (agent_get_passphrase): New arg CANCELED.
|
||||||
|
@ -147,33 +147,43 @@ get_last_passphrase()
|
|||||||
void
|
void
|
||||||
read_passphrase_from_fd( int fd )
|
read_passphrase_from_fd( int fd )
|
||||||
{
|
{
|
||||||
int i, len;
|
int i, len;
|
||||||
char *pw;
|
char *pw;
|
||||||
|
|
||||||
if ( opt.use_agent )
|
if (opt.use_agent)
|
||||||
return; /* not used here */
|
{ /* 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];
|
||||||
|
|
||||||
if( !opt.batch )
|
while (!(read (fd, buf, 1) != 1 || *buf == '\n' ))
|
||||||
tty_printf("Reading passphrase from file descriptor %d ...", fd );
|
;
|
||||||
for( pw = NULL, i = len = 100; ; i++ ) {
|
*buf = 0;
|
||||||
if( i >= len-1 ) {
|
return;
|
||||||
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" );
|
|
||||||
|
|
||||||
m_free( fd_passwd );
|
if( !opt.batch )
|
||||||
fd_passwd = pw;
|
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" );
|
||||||
|
|
||||||
|
m_free( fd_passwd );
|
||||||
|
fd_passwd = pw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -614,6 +624,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
|
|||||||
char *pw = NULL;
|
char *pw = NULL;
|
||||||
PKT_public_key *pk = m_alloc_clear( sizeof *pk );
|
PKT_public_key *pk = m_alloc_clear( sizeof *pk );
|
||||||
byte fpr[MAX_FINGERPRINT_LEN];
|
byte fpr[MAX_FINGERPRINT_LEN];
|
||||||
|
int have_fpr = 0;
|
||||||
int prot;
|
int prot;
|
||||||
char *orig_codeset = NULL;
|
char *orig_codeset = NULL;
|
||||||
|
|
||||||
@ -635,21 +646,15 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
|
|||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
/* The Assuan agent protol requires us to trasnmit utf-8 strings */
|
/* The Assuan agent protol requires us to trasnmit utf-8 strings */
|
||||||
orig_codeset = bind_textdomain_codeset (PACKAGE, NULL);
|
orig_codeset = bind_textdomain_codeset (PACKAGE, NULL);
|
||||||
log_debug ("old codeset: `%s'\n", orig_codeset);
|
|
||||||
#ifdef HAVE_LANGINFO_CODESET
|
#ifdef HAVE_LANGINFO_CODESET
|
||||||
if (!orig_codeset)
|
if (!orig_codeset)
|
||||||
{
|
orig_codeset = nl_langinfo (CODESET);
|
||||||
orig_codeset = nl_langinfo (CODESET);
|
|
||||||
log_debug ("assuming `%s'\n", orig_codeset);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (orig_codeset)
|
if (orig_codeset)
|
||||||
{ /* We only switch when we are able to restore the codeset later. */
|
{ /* We only switch when we are able to restore the codeset later. */
|
||||||
orig_codeset = m_strdup (orig_codeset);
|
orig_codeset = m_strdup (orig_codeset);
|
||||||
if (!bind_textdomain_codeset (PACKAGE, "utf-8"))
|
if (!bind_textdomain_codeset (PACKAGE, "utf-8"))
|
||||||
orig_codeset = NULL;
|
orig_codeset = NULL;
|
||||||
log_debug ("switched to: `%s'\n",
|
|
||||||
bind_textdomain_codeset (PACKAGE, NULL));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -695,6 +700,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
|
|||||||
{
|
{
|
||||||
size_t dummy;
|
size_t dummy;
|
||||||
fingerprint_from_pk( pk, fpr, &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);
|
tryagain_text = _(tryagain_text);
|
||||||
|
|
||||||
/* We allocate 2 time the needed space for atext so that there
|
/* 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
|
line = m_alloc (15 + 46
|
||||||
+ 3*strlen (tryagain_text) + 3*strlen (atext) + 2);
|
+ 3*strlen (tryagain_text) + 3*strlen (atext) + 2);
|
||||||
strcpy (line, "GET_PASSPHRASE ");
|
strcpy (line, "GET_PASSPHRASE ");
|
||||||
p = line+15;
|
p = line+15;
|
||||||
if (!mode)
|
if (!mode && have_fpr)
|
||||||
{
|
{
|
||||||
for (i=0; i < 20; i++, p +=2 )
|
for (i=0; i < 20; i++, p +=2 )
|
||||||
sprintf (p, "%02X", fpr[i]);
|
sprintf (p, "%02X", fpr[i]);
|
||||||
@ -872,7 +878,6 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text,
|
|||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
if (orig_codeset)
|
if (orig_codeset)
|
||||||
bind_textdomain_codeset (PACKAGE, orig_codeset);
|
bind_textdomain_codeset (PACKAGE, orig_codeset);
|
||||||
log_debug ("restored to: `%s'\n", bind_textdomain_codeset (PACKAGE, NULL));
|
|
||||||
#endif
|
#endif
|
||||||
m_free (atext);
|
m_free (atext);
|
||||||
if ( fd != -1 )
|
if ( fd != -1 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user