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

Check for valid PGP key on start

This commit is contained in:
James Booth 2015-08-23 22:54:41 +01:00
parent c07638746a
commit 57ca441f02
3 changed files with 32 additions and 2 deletions

View File

@ -4337,8 +4337,8 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
}
ProfAccount *account = accounts_get_account(jabber_get_account_name());
if (!account->pgp_keyid) {
ui_current_print_formatted_line('!', 0, "You must specify a PGP key ID for this account to start PGP encryption.");
if (!p_gpg_valid_key(account->pgp_keyid)) {
ui_current_print_formatted_line('!', 0, "You must specify a valid PGP key ID for this account to start PGP encryption.");
account_free(account);
return TRUE;
}

View File

@ -280,6 +280,35 @@ p_gpg_free_key(ProfPGPKey *key)
}
}
gboolean
p_gpg_valid_key(const char * const keyid)
{
gpgme_ctx_t ctx;
gpgme_error_t error = gpgme_new(&ctx);
if (error) {
log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
return FALSE;
}
gpgme_key_t key = NULL;
error = gpgme_get_key(ctx, keyid, &key, 1);
if (error || key == NULL) {
log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
gpgme_release(ctx);
return FALSE;
}
if (key) {
gpgme_release(ctx);
gpgme_key_unref(key);
return TRUE;
}
gpgme_release(ctx);
return FALSE;
}
gboolean
p_gpg_available(const char * const barejid)
{

View File

@ -48,6 +48,7 @@ void p_gpg_on_disconnect(void);
GSList* p_gpg_list_keys(void);
gboolean p_gpg_addkey(const char * const jid, const char * const keyid);
GHashTable* p_gpg_fingerprints(void);
gboolean p_gpg_valid_key(const char * const keyid);
gboolean p_gpg_available(const char * const barejid);
const char* p_gpg_libver(void);
void p_gpg_free_key(ProfPGPKey *key);