diff options
-rw-r--r-- | src/pgp/gpg.c | 23 | ||||
-rw-r--r-- | src/ui/core.c | 26 | ||||
-rw-r--r-- | src/ui/ui.h | 1 |
3 files changed, 37 insertions, 13 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c index aeb88e5a..96821f0f 100644 --- a/src/pgp/gpg.c +++ b/src/pgp/gpg.c @@ -79,17 +79,20 @@ _p_gpg_free_pubkeyid(ProfPGPPubKeyId *pubkeyid) static gpgme_error_t * _p_gpg_passphrase_cb(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd) { - cons_show("Passphrase callback"); - if (uid_hint) { - cons_show(" uid_hind: %s", uid_hint); - } - if (passphrase_info) { - cons_show(" passphrase_info: %s", passphrase_info); - } - if (prev_was_bad) { - cons_show(" prev_was_bad"); + GString *pass_term = g_string_new(""); + + char *password = ui_ask_pgp_passphrase(uid_hint, prev_was_bad); + if (password) { + g_string_append(pass_term, password); + free(password); } - gpgme_io_writen(fd, "password\n", strlen("password\n")); + + g_string_append(pass_term, "\n"); + + gpgme_io_writen(fd, pass_term->str, pass_term->len); + + g_string_free(pass_term, TRUE); + return 0; } diff --git a/src/ui/core.c b/src/ui/core.c index 9ee8b9a5..da18ddbf 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -2101,9 +2101,29 @@ ui_win_unread(int index) char * ui_ask_password(void) { - status_bar_get_password(); - status_bar_update_virtual(); - return inp_get_password(); + status_bar_get_password(); + status_bar_update_virtual(); + return inp_get_password(); +} + +char * +ui_ask_pgp_passphrase(const char *hint, int prev_fail) +{ + ProfWin *current = wins_get_current(); + + if (prev_fail) { + win_print(current, '!', 0, NULL, 0, 0, NULL, "Incorrect passphrase"); + } + + if (hint) { + win_vprint(current, '!', 0, NULL, 0, 0, NULL, "Enter PGP key passphrase for %s", hint); + } else { + win_print(current, '!', 0, NULL, 0, 0, NULL, "Enter PGP key passphrase"); + } + + status_bar_get_password(); + status_bar_update_virtual(); + return inp_get_password(); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index e47cbddd..27395048 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -102,6 +102,7 @@ win_type_t ui_win_type(int index); void ui_close_win(int index); int ui_win_unread(int index); char * ui_ask_password(void); +char * ui_ask_pgp_passphrase(const char *hint, int prev_fail); void ui_handle_stanza(const char * const msg); |