From e0cd2d31a181ae7cdf7a4ee30043c8575c8bf527 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Sun, 3 Dec 2006 04:38:53 +0000 Subject: [PATCH] * 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. --- g10/ChangeLog | 7 +++++ g10/gpg.c | 4 +++ g10/options.h | 2 +- g10/passphrase.c | 74 ++++++++++++++++++++++++++++-------------------- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index cc10fec03..cbb030a93 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,10 @@ +2006-12-02 David Shaw + + * 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 * openfile.c (ask_outfile_name): Fixed buffer overflow occurring diff --git a/g10/gpg.c b/g10/gpg.c index 5c9a2b049..691cfffa2 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -219,6 +219,7 @@ enum cmd_and_opt_values oPasswd, oPasswdFD, oPasswdFile, + oPasswdRepeat, oCommandFD, oCommandFile, oQuickRandom, @@ -578,6 +579,7 @@ static ARGPARSE_OPTS opts[] = { { oPasswd, "passphrase",2, "@" }, { oPasswdFD, "passphrase-fd",1, "@" }, { oPasswdFile, "passphrase-file",2, "@" }, + { oPasswdRepeat, "passphrase-repeat", 1, "@"}, { oCommandFD, "command-fd",1, "@" }, { oCommandFile, "command-file",2, "@" }, { oQuickRandom, "quick-random", 0, "@"}, @@ -1819,6 +1821,7 @@ main (int argc, char **argv ) opt.def_sig_expire="0"; opt.def_cert_expire="0"; set_homedir ( default_homedir () ); + opt.passwd_repeat=1; #ifdef ENABLE_CARD_SUPPORT #if defined(_WIN32) || defined(__CYGWIN__) @@ -2440,6 +2443,7 @@ main (int argc, char **argv ) case oPasswdFile: pwfd = open_info_file (pargs.r.ret_str, 0); break; + case oPasswdRepeat: opt.passwd_repeat=pargs.r.ret_int; break; case oCommandFD: opt.command_fd = iobuf_translate_file_handle (pargs.r.ret_int, 0); break; diff --git a/g10/options.h b/g10/options.h index c881196e9..8f866e2ad 100644 --- a/g10/options.h +++ b/g10/options.h @@ -239,7 +239,7 @@ struct /* True if multiple concatenated signatures may be verified. */ int allow_multisig_verification; - + int passwd_repeat; } opt; /* CTRL is used to keep some global variables we currently can't diff --git a/g10/passphrase.c b/g10/passphrase.c index db1080739..4dd2f836d 100644 --- a/g10/passphrase.c +++ b/g10/passphrase.c @@ -1,6 +1,6 @@ /* passphrase.c - Get a passphrase - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, - * 2005 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, + * 2006 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -937,26 +937,32 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo, goto agent_died; pw = xstrdup (""); } - if( *pw && mode == 2 ) { - char *pw2 = agent_get_passphrase ( keyid, 2, NULL, NULL, NULL, - NULL, canceled ); - if (!pw2) - { - if (!opt.use_agent) - { - xfree (pw); - pw = NULL; - goto agent_died; - } - pw2 = xstrdup (""); - } - if( strcmp(pw, pw2) ) { + if( *pw && mode == 2 ) + { + int i; + for(i=0;i