aboutsummaryrefslogtreecommitdiffstats
path: root/g10/passphrase.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-09-30 08:00:08 +0000
committerWerner Koch <[email protected]>2003-09-30 08:00:08 +0000
commit8062cb418a4757c603447fb5fad2d06bf54cadb3 (patch)
treec4290b18aed7add7b1355acd16b5d0876edc8ac3 /g10/passphrase.c
parent2003-09-28 Timo Schulz <[email protected]> (diff)
downloadgnupg-8062cb418a4757c603447fb5fad2d06bf54cadb3.tar.gz
gnupg-8062cb418a4757c603447fb5fad2d06bf54cadb3.zip
* keygen.c (do_add_key_flags, parse_parameter_usage): Add support
the proposed AUTH key flag. * getkey.c (fixup_uidnode, merge_selfsigs_main) (merge_selfsigs_subkey, premerge_public_with_secret): Ditto. * keylist.c (print_capabilities): Ditto. * parse-packet.c (parse_key): Allow to parse the divert-to-card S2K mode. * build-packet.c (do_secret_key): Handle divert-to-card S2K * seckey-cert.c (is_secret_key_protected): Ditto. (check_secret_key): Ditto. * keygen.c (do_ask_passphrase): Renamed from ask_passphrase. * passphrase.c (ask_passphrase): New.
Diffstat (limited to 'g10/passphrase.c')
-rw-r--r--g10/passphrase.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/g10/passphrase.c b/g10/passphrase.c
index a48f220a2..10dd3ff81 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -1004,22 +1004,57 @@ passphrase_clear_cache ( u32 *keyid, int algo )
/****************
- * Get a passphrase for the secret key with KEYID, display TEXT
- * if the user needs to enter the passphrase.
- * mode 0 = standard, 1 = same but don't show key info,
- * 2 = create new passphrase
- * Returns: a DEK with a session key; caller must free
- * or NULL if the passphrase was not correctly repeated.
- * (only for mode 2)
- * a dek->keylen of 0 means: no passphrase entered.
- * (only for mode 2)
- *
- * pubkey_algo is only informational. Note that TRYAGAIN_TEXT must
- * not be translated as this is done within this function (required to
- * switch to utf-8 when the agent is in use). If CANCELED is not
- * NULL, it is set to 1 if the user choosed to cancel the operation,
- * otherwise it will be set to 0.
+ * Ask for a passphrase and return that string.
*/
+char *
+ask_passphrase (const char *description, const char *prompt, int *canceled)
+{
+ char *pw = NULL;
+
+ if (canceled)
+ *canceled = 0;
+
+ if (is_status_enabled())
+ write_status_text( STATUS_NEED_PASSPHRASE_SYM, "0 0 0");
+
+ if (!opt.batch && description)
+ tty_printf ("\n%s\n",description);
+
+ agent_died:
+ if ( opt.use_agent )
+ {
+ pw = agent_get_passphrase (NULL, 0, description, canceled );
+ if (!pw)
+ {
+ if (!opt.use_agent)
+ goto agent_died;
+ pw = NULL;
+ }
+ }
+ else if (fd_passwd)
+ {
+ pw = m_alloc_secure (strlen(fd_passwd)+1);
+ strcpy (pw, fd_passwd);
+ }
+ else if (opt.batch)
+ {
+ log_error(_("can't query password in batchmode\n"));
+ pw = NULL;
+ }
+ else {
+ pw = cpr_get_hidden("passphrase.ask",
+ prompt?prompt : _("Enter passphrase: ") );
+ tty_kill_prompt();
+ }
+
+ if (!pw || !*pw)
+ write_status( STATUS_MISSING_PASSPHRASE );
+
+ return pw;
+}
+
+
+
DEK *
passphrase_to_dek( u32 *keyid, int pubkey_algo,
int cipher_algo, STRING2KEY *s2k, int mode,