1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-11 21:48:50 +01:00

* options.h, gpg.c (main), passphrase.c (passphrase_to_dek): Add

--passphrase-repeat option to control how many times gpg will
re-prompt for a passphrase to ensure the user has typed it correctly.
Defaults to 1.
This commit is contained in:
David Shaw 2006-12-03 04:38:53 +00:00
parent 29f48b5fdc
commit e0cd2d31a1
4 changed files with 55 additions and 32 deletions

View File

@ -1,3 +1,10 @@
2006-12-02 David Shaw <dshaw@jabberwocky.com>
* options.h, gpg.c (main), passphrase.c (passphrase_to_dek): Add
--passphrase-repeat option to control how many times gpg will
re-prompt for a passphrase to ensure the user has typed it
correctly. Defaults to 1.
2006-11-27 Werner Koch <wk@g10code.com> 2006-11-27 Werner Koch <wk@g10code.com>
* openfile.c (ask_outfile_name): Fixed buffer overflow occurring * openfile.c (ask_outfile_name): Fixed buffer overflow occurring

View File

@ -219,6 +219,7 @@ enum cmd_and_opt_values
oPasswd, oPasswd,
oPasswdFD, oPasswdFD,
oPasswdFile, oPasswdFile,
oPasswdRepeat,
oCommandFD, oCommandFD,
oCommandFile, oCommandFile,
oQuickRandom, oQuickRandom,
@ -578,6 +579,7 @@ static ARGPARSE_OPTS opts[] = {
{ oPasswd, "passphrase",2, "@" }, { oPasswd, "passphrase",2, "@" },
{ oPasswdFD, "passphrase-fd",1, "@" }, { oPasswdFD, "passphrase-fd",1, "@" },
{ oPasswdFile, "passphrase-file",2, "@" }, { oPasswdFile, "passphrase-file",2, "@" },
{ oPasswdRepeat, "passphrase-repeat", 1, "@"},
{ oCommandFD, "command-fd",1, "@" }, { oCommandFD, "command-fd",1, "@" },
{ oCommandFile, "command-file",2, "@" }, { oCommandFile, "command-file",2, "@" },
{ oQuickRandom, "quick-random", 0, "@"}, { oQuickRandom, "quick-random", 0, "@"},
@ -1819,6 +1821,7 @@ main (int argc, char **argv )
opt.def_sig_expire="0"; opt.def_sig_expire="0";
opt.def_cert_expire="0"; opt.def_cert_expire="0";
set_homedir ( default_homedir () ); set_homedir ( default_homedir () );
opt.passwd_repeat=1;
#ifdef ENABLE_CARD_SUPPORT #ifdef ENABLE_CARD_SUPPORT
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32) || defined(__CYGWIN__)
@ -2440,6 +2443,7 @@ main (int argc, char **argv )
case oPasswdFile: case oPasswdFile:
pwfd = open_info_file (pargs.r.ret_str, 0); pwfd = open_info_file (pargs.r.ret_str, 0);
break; break;
case oPasswdRepeat: opt.passwd_repeat=pargs.r.ret_int; break;
case oCommandFD: case oCommandFD:
opt.command_fd = iobuf_translate_file_handle (pargs.r.ret_int, 0); opt.command_fd = iobuf_translate_file_handle (pargs.r.ret_int, 0);
break; break;

View File

@ -239,7 +239,7 @@ struct
/* True if multiple concatenated signatures may be verified. */ /* True if multiple concatenated signatures may be verified. */
int allow_multisig_verification; int allow_multisig_verification;
int passwd_repeat;
} opt; } opt;
/* CTRL is used to keep some global variables we currently can't /* CTRL is used to keep some global variables we currently can't

View File

@ -1,6 +1,6 @@
/* passphrase.c - Get a passphrase /* passphrase.c - Get a passphrase
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -937,26 +937,32 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
goto agent_died; goto agent_died;
pw = xstrdup (""); pw = xstrdup ("");
} }
if( *pw && mode == 2 ) { if( *pw && mode == 2 )
char *pw2 = agent_get_passphrase ( keyid, 2, NULL, NULL, NULL, {
NULL, canceled ); int i;
if (!pw2) for(i=0;i<opt.passwd_repeat;i++)
{ {
if (!opt.use_agent) char *pw2 = agent_get_passphrase ( keyid, 2, NULL, NULL, NULL,
{ NULL, canceled );
xfree (pw); if (!pw2)
pw = NULL; {
goto agent_died; if (!opt.use_agent)
} {
pw2 = xstrdup (""); xfree (pw);
} pw = NULL;
if( strcmp(pw, pw2) ) { goto agent_died;
}
pw2 = xstrdup ("");
}
if( strcmp(pw, pw2) )
{
xfree(pw2);
xfree(pw);
return NULL;
}
xfree(pw2); xfree(pw2);
xfree(pw); }
return NULL; }
}
xfree(pw2);
}
} }
else if( fd_passwd ) { else if( fd_passwd ) {
/* Return the passphrase we have store in FD_PASSWD. */ /* Return the passphrase we have store in FD_PASSWD. */
@ -972,17 +978,23 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
/* Read the passphrase from the tty or the command-fd. */ /* Read the passphrase from the tty or the command-fd. */
pw = cpr_get_hidden("passphrase.enter", _("Enter passphrase: ") ); pw = cpr_get_hidden("passphrase.enter", _("Enter passphrase: ") );
tty_kill_prompt(); tty_kill_prompt();
if( mode == 2 && !cpr_enabled() ) { if( mode == 2 && !cpr_enabled() )
char *pw2 = cpr_get_hidden("passphrase.repeat", {
_("Repeat passphrase: ") ); int i;
tty_kill_prompt(); for(i=0;i<opt.passwd_repeat;i++)
if( strcmp(pw, pw2) ) { {
char *pw2 = cpr_get_hidden("passphrase.repeat",
_("Repeat passphrase: ") );
tty_kill_prompt();
if( strcmp(pw, pw2) )
{
xfree(pw2);
xfree(pw);
return NULL;
}
xfree(pw2); xfree(pw2);
xfree(pw); }
return NULL; }
}
xfree(pw2);
}
} }
if( !pw || !*pw ) if( !pw || !*pw )