1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added UI function to get PGP passphrase

This commit is contained in:
James Booth 2015-09-01 20:16:04 +01:00
parent dd346eefc4
commit 1f4fd0fcb3
3 changed files with 37 additions and 13 deletions

View File

@ -79,17 +79,20 @@ _p_gpg_free_pubkeyid(ProfPGPPubKeyId *pubkeyid)
static gpgme_error_t * static gpgme_error_t *
_p_gpg_passphrase_cb(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd) _p_gpg_passphrase_cb(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd)
{ {
cons_show("Passphrase callback"); GString *pass_term = g_string_new("");
if (uid_hint) {
cons_show(" uid_hind: %s", uid_hint); char *password = ui_ask_pgp_passphrase(uid_hint, prev_was_bad);
if (password) {
g_string_append(pass_term, password);
free(password);
} }
if (passphrase_info) {
cons_show(" passphrase_info: %s", passphrase_info); g_string_append(pass_term, "\n");
}
if (prev_was_bad) { gpgme_io_writen(fd, pass_term->str, pass_term->len);
cons_show(" prev_was_bad");
} g_string_free(pass_term, TRUE);
gpgme_io_writen(fd, "password\n", strlen("password\n"));
return 0; return 0;
} }

View File

@ -2101,9 +2101,29 @@ ui_win_unread(int index)
char * char *
ui_ask_password(void) ui_ask_password(void)
{ {
status_bar_get_password(); status_bar_get_password();
status_bar_update_virtual(); status_bar_update_virtual();
return inp_get_password(); 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 void

View File

@ -102,6 +102,7 @@ win_type_t ui_win_type(int index);
void ui_close_win(int index); void ui_close_win(int index);
int ui_win_unread(int index); int ui_win_unread(int index);
char * ui_ask_password(void); char * ui_ask_password(void);
char * ui_ask_pgp_passphrase(const char *hint, int prev_fail);
void ui_handle_stanza(const char * const msg); void ui_handle_stanza(const char * const msg);