From fb678f7d050331130dda5acf178ce362dbce267f Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 1 May 2006 14:16:33 +0000 Subject: Handle prompts from GnuPG asking for the user's PIN for their SmartCard. 2006-05-01 Jeffrey Stedfast * camel-gpg-context.c (gpg_ctx_parse_status): Handle prompts from GnuPG asking for the user's PIN for their SmartCard. Fixes bug #335386. --- camel/ChangeLog | 17 +++++++--- camel/camel-gpg-context.c | 81 +++++++++++++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 33 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index 2191b5e9b..51d5ee5b9 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,9 @@ +2006-05-01 Jeffrey Stedfast + + * camel-gpg-context.c (gpg_ctx_parse_status): Handle prompts from + GnuPG asking for the user's PIN for their SmartCard. Fixes bug + #335386. + 2006-04-19 Jeffrey Stedfast * camel-mime-filter-pgp.c (filter_run): You cannot CANNOT modify @@ -36,14 +42,15 @@ ** See bug 272307 - * camel-mime-utils.c: (header_decode_mailbox): - Do not decode_lwsp if there is a space in mail id, just append it. - Also do not truncate address if addr is not NULL. + * camel-mime-utils.c (header_decode_mailbox): Do not decode_lwsp + if there is a space in mail id, just append it. Also do not + truncate address if addr is not NULL. 2006-03-20 Srinivasa Ragavan - * camel-gpg-context.c: (gpg_ctx_parse_status): Added flag to ask for - pass phrase. + * camel-gpg-context.c (gpg_ctx_parse_status): Added flag to ask + for pass phrase. + * camel-session.h: Added the flag for passphrase. 2006-03-20 Srinivasa Ragavan diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c index 59b4d7238..8b685f8ef 100644 --- a/camel/camel-gpg-context.c +++ b/camel/camel-gpg-context.c @@ -794,46 +794,71 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) g_free (gpg->need_id); gpg->need_id = userid; - } else if (!strncmp (status, "GET_HIDDEN passphrase.enter", 27)) { + } else if (!strncmp (status, "NEED_PASSPHRASE_PIN ", 20)) { + char *userid; + + status += 20; + + status = next_token (status, &userid); + if (!userid) { + camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, + _("Failed to parse gpg passphrase request.")); + return -1; + } + + g_free (gpg->need_id); + gpg->need_id = userid; + } else if (!strncmp (status, "GET_HIDDEN ", 11)) { char *prompt, *passwd; const char *name; - - if (gpg->need_id) { - name = g_hash_table_lookup (gpg->userid_hint, gpg->need_id); - if (!name) - name = gpg->need_id; - - prompt = g_strdup_printf (_("You need a passphrase to unlock the key for\n" - "user: \"%s\""), name); - } else { + guint32 flags; + + status += 11; + + if (gpg->need_id && !(name = g_hash_table_lookup (gpg->userid_hint, gpg->need_id))) + name = gpg->need_id; + else name = ""; + + if (!strncmp (status, "passphrase.pin.ask", 18)) { + prompt = g_strdup_printf (_("You need a PIN to unlock the key for your\n" + "SmartCard: \"%s\""), name); + } else if (!strncmp (status, "passphrase.enter", 16)) { prompt = g_strdup_printf (_("You need a passphrase to unlock the key for\n" - "user: \"%s\""), name); + "user: \"%s\""), name); + } else { + next_token (status, &prompt); + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Unexpected request from GnuPG for `%s'"), prompt); + g_free (prompt); + return -1; } - if ((passwd = camel_session_get_password (gpg->session, NULL, NULL, prompt, gpg->need_id, CAMEL_SESSION_PASSWORD_SECRET|CAMEL_SESSION_PASSPHRASE, ex)) && !gpg->utf8) { - char *opasswd = passwd; - - if ((passwd = g_locale_to_utf8 (passwd, -1, &nread, &nwritten, NULL))) { - memset (opasswd, 0, strlen (opasswd)); - g_free (opasswd); - } else { - passwd = opasswd; + flags = CAMEL_SESSION_PASSWORD_SECRET | CAMEL_SESSION_PASSPHRASE; + if ((passwd = camel_session_get_password (gpg->session, NULL, NULL, prompt, gpg->need_id, flags, ex))) { + if (!gpg->utf8) { + char *opasswd = passwd; + + if ((passwd = g_locale_to_utf8 (passwd, -1, &nread, &nwritten, NULL))) { + memset (opasswd, 0, strlen (opasswd)); + g_free (opasswd); + } else { + passwd = opasswd; + } } - } - g_free (prompt); - - if (passwd == NULL) { + + gpg->passwd = g_strdup_printf ("%s\n", passwd); + memset (passwd, 0, strlen (passwd)); + g_free (passwd); + + gpg->send_passwd = TRUE; + } else { if (!camel_exception_is_set (ex)) camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled.")); return -1; } - gpg->passwd = g_strdup_printf ("%s\n", passwd); - memset (passwd, 0, strlen (passwd)); - g_free (passwd); - - gpg->send_passwd = TRUE; + g_free (prompt); } else if (!strncmp (status, "GOOD_PASSPHRASE", 15)) { gpg->bad_passwds = 0; } else if (!strncmp (status, "BAD_PASSPHRASE", 14)) { -- cgit v1.2.1