Add /pgp sendpub command

Command allows to share your PGP pub key with ease,
it's not described in XEP-0027, but used in some clients,
such as PSI, Pidgin.
Fix typos
Minor improvements
This commit is contained in:
John Hernandez
2023-06-30 14:28:28 +02:00
parent f3265565e8
commit a59623a007
7 changed files with 126 additions and 31 deletions

View File

@@ -910,6 +910,7 @@ cmd_ac_init(void)
autocomplete_add(pgp_ac, "log");
autocomplete_add(pgp_ac, "char");
autocomplete_add(pgp_ac, "sendfile");
autocomplete_add(pgp_ac, "sendpub");
pgp_log_ac = autocomplete_new();
autocomplete_add(pgp_log_ac, "on");

View File

@@ -1705,7 +1705,8 @@ static const struct cmd_t command_defs[] = {
"/pgp end",
"/pgp log on|off|redact",
"/pgp char <char>",
"/pgp sendfile on|off")
"/pgp sendfile on|off",
"/pgp sendpub")
CMD_DESC(
"Open PGP commands to manage keys, and perform PGP encryption during chat sessions. "
"See the /account command to set your own PGP key.")
@@ -1719,7 +1720,8 @@ static const struct cmd_t command_defs[] = {
{ "log on|off", "Enable or disable plaintext logging of PGP encrypted messages." },
{ "log redact", "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." },
{ "char <char>", "Set the character to be displayed next to PGP encrypted messages." },
{ "sendfile on|off", "Allow /sendfile to send unencrypted files while otherwise using PGP." })
{ "sendfile on|off", "Allow /sendfile to send unencrypted files while otherwise using PGP." },
{ "sendpub", "Used in chat. Sends a message to the current recipient with your PGP public key." })
CMD_EXAMPLES(
"/pgp log off",
"/pgp setkey odin@valhalla.edda BA19CACE5A9592C5",

View File

@@ -7489,12 +7489,12 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args)
if (g_strcmp0(args[0], "start") == 0) {
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You must be connected to start PGP encrpytion.");
cons_show("You must be connected to start PGP encryption.");
return TRUE;
}
if (window->type != WIN_CHAT && args[1] == NULL) {
cons_show("You must be in a regular chat window to start PGP encrpytion.");
cons_show("You must be in a regular chat window to start PGP encryption.");
return TRUE;
}
@@ -7533,14 +7533,17 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args)
}
ProfAccount* account = accounts_get_account(session_get_account_name());
char* err_str = NULL;
if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) {
win_println(window, THEME_DEFAULT, "!", "Invalid PGP key ID %s: %s, cannot start PGP encryption.", account->pgp_keyid, err_str);
free(err_str);
if (account->pgp_keyid == NULL) {
win_println(window, THEME_DEFAULT, "!", "Couldn't start PGP session. Please, set your PGP key using /account set %s pgpkeyid <pgpkeyid>. To list pgp keys, use /pgp keys.", account->name);
account_free(account);
return TRUE;
}
auto_char char* err_str = NULL;
if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) {
win_println(window, THEME_DEFAULT, "!", "Invalid PGP key ID %s: %s, cannot start PGP encryption.", account->pgp_keyid, err_str);
account_free(account);
return TRUE;
}
free(err_str);
account_free(account);
if (!p_gpg_available(chatwin->barejid)) {
@@ -7562,7 +7565,7 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args)
}
if (window->type != WIN_CHAT) {
cons_show("You must be in a regular chat window to end PGP encrpytion.");
cons_show("You must be in a regular chat window to end PGP encryption.");
return TRUE;
}
@@ -7583,6 +7586,31 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
if (g_strcmp0(args[0], "sendpub") == 0) {
if (window->type != WIN_CHAT) {
cons_show_error("Please, use this command only in chat windows.");
return TRUE;
}
ProfChatWin* chatwin = (ProfChatWin*)window;
ProfAccount* account = accounts_get_account(session_get_account_name());
if (account->pgp_keyid == NULL) {
cons_show_error("Please, set the PGP key first using /account set %s pgpkeyid <pgpkeyid>. To list pgp keys, use /pgp keys.", account->name);
account_free(account);
return TRUE;
}
auto_char char* pubkey = p_gpg_get_pubkey(account->pgp_keyid);
if (pubkey == NULL) {
cons_show_error("Couldn't get your PGP public key. Please, check error logs.");
account_free(account);
return TRUE;
}
cl_ev_send_msg(chatwin, pubkey, NULL);
cons_show("PGP key has been shared with %s.", chatwin->barejid);
account_free(account);
return TRUE;
}
cons_bad_cmd_usage(command);
return TRUE;
#else
@@ -7691,12 +7719,12 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args)
} else if (g_strcmp0(args[0], "start") == 0) {
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You must be connected to start OX encrpytion.");
cons_show("You must be connected to start OX encryption.");
return TRUE;
}
if (window->type != WIN_CHAT && args[1] == NULL) {
cons_show("You must be in a regular chat window to start OX encrpytion.");
cons_show("You must be in a regular chat window to start OX encryption.");
return TRUE;
}