gpg: refactor

master
bqv 2 years ago
parent a0d1c104e4
commit 8779ca82dc
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -33,8 +33,7 @@ char *account_options[ACCOUNT_NUM_OPTIONS][2] =
{ (char*)"autoconnect", (char*)"" },
{ (char*)"resource", (char*)"" },
{ (char*)"status", (char*)"probably about to segfault" },
{ (char*)"pgp_pubring_path", (char*)"${weechat_data_dir}/pubring.gpg" },
{ (char*)"pgp_secring_path", (char*)"${weechat_data_dir}/secring.gpg" },
{ (char*)"pgp_path", (char*)"" },
{ (char*)"pgp_keyid", (char*)"" },
};

@ -23,8 +23,7 @@ enum t_account_option
ACCOUNT_OPTION_AUTOCONNECT,
ACCOUNT_OPTION_RESOURCE,
ACCOUNT_OPTION_STATUS,
ACCOUNT_OPTION_PGP_PUBRING_PATH,
ACCOUNT_OPTION_PGP_SECRING_PATH,
ACCOUNT_OPTION_PGP_PATH,
ACCOUNT_OPTION_PGP_KEYID,
ACCOUNT_NUM_OPTIONS,
};
@ -63,10 +62,8 @@ enum t_account_option
weechat_config_string(account->options[ACCOUNT_OPTION_RESOURCE])
#define account_status(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_STATUS])
#define account_pgp_pubring_path(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_PUBRING_PATH])
#define account_pgp_secring_path(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_SECRING_PATH])
#define account_pgp_path(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_PATH])
#define account_pgp_keyid(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_KEYID])

@ -204,27 +204,11 @@ config__account_new_option (struct t_config_file *config_file,
callback_change_data,
NULL, NULL, NULL);
break;
case ACCOUNT_OPTION_PGP_PUBRING_PATH:
case ACCOUNT_OPTION_PGP_PATH:
new_option = weechat_config_new_option (
config_file, section,
option_name, "string",
N_("XMPP Account PGP Public Keyring Path"),
NULL, 0, 0,
default_value, value,
null_value_allowed,
callback_check_value,
callback_check_value_pointer,
callback_check_value_data,
callback_change,
callback_change_pointer,
callback_change_data,
NULL, NULL, NULL);
break;
case ACCOUNT_OPTION_PGP_SECRING_PATH:
new_option = weechat_config_new_option (
config_file, section,
option_name, "string",
N_("XMPP Account PGP Secure Keyring Path"),
N_("XMPP Account PGP Keyring Dir"),
NULL, 0, 0,
default_value, value,
null_value_allowed,

@ -1218,11 +1218,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_handler_add(conn, &connection__iq_handler,
NULL, "iq", NULL, account);
pgp__init(&account->pgp,
weechat_string_eval_expression(account_pgp_pubring_path(account),
NULL, NULL, NULL),
weechat_string_eval_expression(account_pgp_secring_path(account),
NULL, NULL, NULL));
pgp__init(&account->pgp);
/* Send initial <presence/> so that we appear online to contacts */
children = (xmpp_stanza_t**)malloc(sizeof(*children) * (3 + 1));

@ -19,7 +19,7 @@
const char *PGP_ADVICE = "[PGP encrypted message (XEP-0027)]";
void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec)
void pgp__init(struct t_pgp **pgp)
{
struct t_pgp *new_pgp;
gpgme_error_t err;
@ -31,35 +31,37 @@ void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec)
err = gpgme_new(&new_pgp->gpgme);
if (err) {
weechat_printf(nullptr, "gpg (error): %s - %s",
gpgme_strsource(err), gpgme_strerror(err));
return;
}
gpgme_set_armor(new_pgp->gpgme, true);
err = gpgme_data_new_from_file(&keydata, pub, true);
if (err) {
return;
}
//err = gpgme_data_new_from_file(&keydata, pub, true);
//if (err) {
// return;
//}
err = gpgme_op_import(new_pgp->gpgme, keydata);
if (err) {
return;
}
//err = gpgme_op_import(new_pgp->gpgme, keydata);
//if (err) {
// return;
//}
gpgme_import_result_t impRes = gpgme_op_import_result(new_pgp->gpgme);
weechat_printf(nullptr, "(gpg) imported %d keys", impRes->imported);
//gpgme_import_result_t impRes = gpgme_op_import_result(new_pgp->gpgme);
//weechat_printf(nullptr, "(gpg) imported %d keys", impRes->imported);
err = gpgme_data_new_from_file(&keydata, sec, true);
if (err) {
return;
}
//err = gpgme_data_new_from_file(&keydata, sec, true);
//if (err) {
// return;
//}
err = gpgme_op_import(new_pgp->gpgme, keydata);
if (err) {
return;
}
//err = gpgme_op_import(new_pgp->gpgme, keydata);
//if (err) {
// return;
//}
impRes = gpgme_op_import_result(new_pgp->gpgme);
weechat_printf(nullptr, "(gpg) imported %d secret keys", impRes->imported);
//impRes = gpgme_op_import_result(new_pgp->gpgme);
//weechat_printf(nullptr, "(gpg) imported %d secret keys", impRes->imported);
*pgp = new_pgp;
}

@ -14,7 +14,7 @@ struct t_pgp
const char *keyid;
};
void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec);
void pgp__init(struct t_pgp **pgp);
void pgp__free(struct t_pgp *pgp);

Loading…
Cancel
Save