mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge pull request #1566 from DebXWoody/bugfixing/ox
Bugfixes for OX implementation
This commit is contained in:
commit
3a9cffe013
@ -2487,6 +2487,13 @@ _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
|
found = autocomplete_param_with_func(input, "/ox discover", roster_contact_autocomplete, previous, NULL);
|
||||||
|
if (found) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
found = autocomplete_param_with_ac(input, "/ox log", ox_log_ac, TRUE, previous);
|
found = autocomplete_param_with_ac(input, "/ox log", ox_log_ac, TRUE, previous);
|
||||||
if (found) {
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
@ -2523,11 +2530,8 @@ _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
|||||||
}
|
}
|
||||||
|
|
||||||
found = autocomplete_param_with_ac(input, "/ox", ox_ac, TRUE, previous);
|
found = autocomplete_param_with_ac(input, "/ox", ox_ac, TRUE, previous);
|
||||||
if (found) {
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return found;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1724,10 +1724,12 @@ static struct cmd_t command_defs[] = {
|
|||||||
"/ox char <char>",
|
"/ox char <char>",
|
||||||
"/ox sendfile on|off",
|
"/ox sendfile on|off",
|
||||||
"/ox announce <file>",
|
"/ox announce <file>",
|
||||||
"/ox discover",
|
"/ox discover <jid>",
|
||||||
"/ox request <jid>")
|
"/ox request <jid> <keyid>")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"OpenPGP (OX) commands to manage keys, and perform PGP encryption during chat sessions. ")
|
"OpenPGP (OX) commands to manage keys, and perform OpenPGP encryption during chat sessions. "
|
||||||
|
"Your OpenPGP key needs a user-id with your JID URI (xmpp:local@domain.tld). "
|
||||||
|
"A key can be generated with \"gpg --quick-gen-key xmpp:local@domain.tld future-default default 3y\".")
|
||||||
CMD_ARGS(
|
CMD_ARGS(
|
||||||
{ "keys", "List all keys known to the system." },
|
{ "keys", "List all keys known to the system." },
|
||||||
{ "contacts", "Show contacts with assigned public keys." },
|
{ "contacts", "Show contacts with assigned public keys." },
|
||||||
@ -1737,7 +1739,7 @@ static struct cmd_t command_defs[] = {
|
|||||||
{ "log redact", "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." },
|
{ "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." },
|
{ "char <char>", "Set the character to be displayed next to PGP encrypted messages." },
|
||||||
{ "announce <file>", "Announce a public key by pushing it on the XMPP Server" },
|
{ "announce <file>", "Announce a public key by pushing it on the XMPP Server" },
|
||||||
{ "discover <jid>", "Discover public keys of a jid " },
|
{ "discover <jid>", "Discover public keys of a jid. The OpenPGP Key IDs will be displayed" },
|
||||||
{ "request <jid>", "Request public keys" },
|
{ "request <jid>", "Request public keys" },
|
||||||
{ "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." })
|
||||||
CMD_EXAMPLES(
|
CMD_EXAMPLES(
|
||||||
|
@ -7481,6 +7481,22 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(args[0], "char") == 0) {
|
||||||
|
if (args[1] == NULL) {
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
} else if (g_utf8_strlen(args[1], 4) == 1) {
|
||||||
|
if (prefs_set_ox_char(args[1])) {
|
||||||
|
cons_show("OX char set to %s.", args[1]);
|
||||||
|
} else {
|
||||||
|
cons_show_error("Could not set OX char: %s.", args[1]);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// The '/ox keys' command - same like in pgp
|
// The '/ox keys' command - same like in pgp
|
||||||
// Should we move this to a common command
|
// Should we move this to a common command
|
||||||
// e.g. '/openpgp keys'?.
|
// e.g. '/openpgp keys'?.
|
||||||
@ -7625,13 +7641,13 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args)
|
|||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
ox_discover_public_key(args[1]);
|
ox_discover_public_key(args[1]);
|
||||||
} else {
|
} else {
|
||||||
cons_show("JID is required");
|
cons_show("To discover the OpenPGP keys of an user, the JID is required");
|
||||||
}
|
}
|
||||||
} else if (g_strcmp0(args[0], "request") == 0) {
|
} else if (g_strcmp0(args[0], "request") == 0) {
|
||||||
if (args[1] && args[2]) {
|
if (args[1] && args[2]) {
|
||||||
ox_request_public_key(args[1], args[2]);
|
ox_request_public_key(args[1], args[2]);
|
||||||
} else {
|
} else {
|
||||||
cons_show("JID and Fingerprint is required");
|
cons_show("JID and OpenPGP Key ID are required");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cons_show("OX not implemented");
|
cons_show("OX not implemented");
|
||||||
|
@ -1141,6 +1141,11 @@ _ox_key_is_usable(gpgme_key_t key, const char* const barejid, gboolean secret)
|
|||||||
char*
|
char*
|
||||||
p_ox_gpg_decrypt(char* base64)
|
p_ox_gpg_decrypt(char* base64)
|
||||||
{
|
{
|
||||||
|
// if there is no private key avaibale,
|
||||||
|
// we don't try do decrypt
|
||||||
|
if(!ox_is_private_key_available(connection_get_barejid())) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
gpgme_check_version(NULL);
|
gpgme_check_version(NULL);
|
||||||
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
|
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
|
||||||
|
@ -86,7 +86,7 @@ static void _handle_muc_private_message(xmpp_stanza_t* const stanza);
|
|||||||
static void _handle_conference(xmpp_stanza_t* const stanza);
|
static void _handle_conference(xmpp_stanza_t* const stanza);
|
||||||
static void _handle_captcha(xmpp_stanza_t* const stanza);
|
static void _handle_captcha(xmpp_stanza_t* const stanza);
|
||||||
static void _handle_receipt_received(xmpp_stanza_t* const stanza);
|
static void _handle_receipt_received(xmpp_stanza_t* const stanza);
|
||||||
static void _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, const char *result_id, GDateTime* timestamp);
|
static void _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, const char* result_id, GDateTime* timestamp);
|
||||||
static void _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_mam);
|
static void _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_mam);
|
||||||
static xmpp_stanza_t* _handle_carbons(xmpp_stanza_t* const stanza);
|
static xmpp_stanza_t* _handle_carbons(xmpp_stanza_t* const stanza);
|
||||||
static void _send_message_stanza(xmpp_stanza_t* const stanza);
|
static void _send_message_stanza(xmpp_stanza_t* const stanza);
|
||||||
@ -120,7 +120,7 @@ _handle_headline(xmpp_stanza_t* const stanza)
|
|||||||
{
|
{
|
||||||
xmpp_stanza_t* body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
xmpp_stanza_t* body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||||
if (body) {
|
if (body) {
|
||||||
char *text = xmpp_stanza_get_text(body);
|
char* text = xmpp_stanza_get_text(body);
|
||||||
if (text) {
|
if (text) {
|
||||||
cons_show("Headline: %s", text);
|
cons_show("Headline: %s", text);
|
||||||
xmpp_free(connection_get_ctx(), text);
|
xmpp_free(connection_get_ctx(), text);
|
||||||
@ -647,7 +647,7 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
|
|||||||
xmpp_stanza_t* key_stanza = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* key_stanza = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(key_stanza, "key");
|
xmpp_stanza_set_name(key_stanza, "key");
|
||||||
char* rid = g_strdup_printf("%d", key->device_id);
|
char* rid = g_strdup_printf("%d", key->device_id);
|
||||||
log_debug("[OMEMO] Sending to device rid %s", rid == NULL ? "NULL" : rid );
|
log_debug("[OMEMO] Sending to device rid %s", rid == NULL ? "NULL" : rid);
|
||||||
xmpp_stanza_set_attribute(key_stanza, "rid", rid);
|
xmpp_stanza_set_attribute(key_stanza, "rid", rid);
|
||||||
g_free(rid);
|
g_free(rid);
|
||||||
if (key->prekey) {
|
if (key->prekey) {
|
||||||
@ -1004,11 +1004,11 @@ _handle_groupchat(xmpp_stanza_t* const stanza)
|
|||||||
xmpp_ctx_t* ctx = connection_get_ctx();
|
xmpp_ctx_t* ctx = connection_get_ctx();
|
||||||
|
|
||||||
const char* room_jid = xmpp_stanza_get_from(stanza);
|
const char* room_jid = xmpp_stanza_get_from(stanza);
|
||||||
if(!room_jid) {
|
if (!room_jid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Jid* from_jid = jid_create(room_jid);
|
Jid* from_jid = jid_create(room_jid);
|
||||||
if(!from_jid) {
|
if (!from_jid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1180,7 +1180,7 @@ _handle_receipt_received(xmpp_stanza_t* const stanza)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Jid* jidp = jid_create(fulljid);
|
Jid* jidp = jid_create(fulljid);
|
||||||
if(!jidp) {
|
if (!jidp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1310,7 +1310,7 @@ _handle_carbons(xmpp_stanza_t* const stanza)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, const char *result_id, GDateTime* timestamp)
|
_handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, const char* result_id, GDateTime* timestamp)
|
||||||
{
|
{
|
||||||
// some clients send the mucuser namespace with private messages
|
// some clients send the mucuser namespace with private messages
|
||||||
// if the namespace exists, and the stanza contains a body element, assume its a private message
|
// if the namespace exists, and the stanza contains a body element, assume its a private message
|
||||||
@ -1460,37 +1460,39 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m
|
|||||||
message->enc = PROF_MSG_ENC_OX;
|
message->enc = PROF_MSG_ENC_OX;
|
||||||
|
|
||||||
#ifdef HAVE_LIBGPGME
|
#ifdef HAVE_LIBGPGME
|
||||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
||||||
|
|
||||||
xmpp_stanza_t* ox = xmpp_stanza_get_child_by_name_and_ns(stanza, "openpgp", STANZA_NS_OPENPGP_0);
|
xmpp_stanza_t* ox = xmpp_stanza_get_child_by_name_and_ns(stanza, "openpgp", STANZA_NS_OPENPGP_0);
|
||||||
if (!ox) {
|
if (ox) {
|
||||||
return;
|
message->plain = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox));
|
||||||
}
|
if (message->plain) {
|
||||||
|
xmpp_stanza_t* x = xmpp_stanza_new_from_string(connection_get_ctx(), message->plain);
|
||||||
char* ox_text = xmpp_stanza_get_text(ox);
|
if (x) {
|
||||||
if (!ox_text) {
|
xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(x, "payload");
|
||||||
return;
|
if (!p) {
|
||||||
}
|
log_warning("OX Stanza - no Payload");
|
||||||
|
message->plain = "OX error: No payload found";
|
||||||
message->plain = p_ox_gpg_decrypt(ox_text);
|
return;
|
||||||
xmpp_free(ctx, ox_text);
|
}
|
||||||
|
xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(p, "body");
|
||||||
xmpp_stanza_t *x = xmpp_stanza_new_from_string(ctx, message->plain);
|
if (!b) {
|
||||||
xmpp_stanza_t *p = xmpp_stanza_get_child_by_name(x, "payload");
|
log_warning("OX Stanza - no body");
|
||||||
if (p) {
|
message->plain = "OX error: No paylod body found";
|
||||||
xmpp_stanza_t *b = xmpp_stanza_get_child_by_name(p, "body");
|
return;
|
||||||
if (b) {
|
}
|
||||||
message->plain = xmpp_stanza_get_text(b);
|
message->plain = xmpp_stanza_get_text(b);
|
||||||
if(message->plain == NULL ) {
|
message->encrypted = xmpp_stanza_get_text(ox);
|
||||||
message->plain = xmpp_stanza_get_text(stanza);
|
if (message->plain == NULL) {
|
||||||
|
message->plain = xmpp_stanza_get_text(stanza);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)";
|
||||||
|
log_warning("OX Stanza text to stanza failed");
|
||||||
}
|
}
|
||||||
message->encrypted = xmpp_stanza_get_text(ox);
|
} else {
|
||||||
|
message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)";
|
||||||
if (message->plain == NULL) {
|
|
||||||
message->plain = xmpp_stanza_get_text(stanza);
|
|
||||||
}
|
|
||||||
message->encrypted = xmpp_stanza_get_text(ox);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
message->plain = "OX stanza without openpgp name";
|
||||||
|
log_warning("OX Stanza without openpgp stanza");
|
||||||
}
|
}
|
||||||
#endif // HAVE_LIBGPGME
|
#endif // HAVE_LIBGPGME
|
||||||
}
|
}
|
||||||
@ -1513,7 +1515,7 @@ _handle_mam(xmpp_stanza_t* const stanza)
|
|||||||
// same as <stanza-id> from XEP-0359 for live messages
|
// same as <stanza-id> from XEP-0359 for live messages
|
||||||
const char* result_id = xmpp_stanza_get_id(result);
|
const char* result_id = xmpp_stanza_get_id(result);
|
||||||
|
|
||||||
GDateTime *timestamp = stanza_get_delay_from(forwarded, NULL);
|
GDateTime* timestamp = stanza_get_delay_from(forwarded, NULL);
|
||||||
|
|
||||||
xmpp_stanza_t* message_stanza = xmpp_stanza_get_child_by_ns(forwarded, "jabber:client");
|
xmpp_stanza_t* message_stanza = xmpp_stanza_get_child_by_ns(forwarded, "jabber:client");
|
||||||
|
|
||||||
|
@ -45,6 +45,9 @@
|
|||||||
#include "pgp/gpg.h"
|
#include "pgp/gpg.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBGPGME
|
#ifdef HAVE_LIBGPGME
|
||||||
|
|
||||||
|
#define KEYID_LENGTH 40
|
||||||
|
|
||||||
static void _ox_metadata_node__public_key(const char* const fingerprint);
|
static void _ox_metadata_node__public_key(const char* const fingerprint);
|
||||||
static int _ox_metadata_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata);
|
static int _ox_metadata_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata);
|
||||||
|
|
||||||
@ -165,8 +168,8 @@ ox_announce_public_key(const char* const filename)
|
|||||||
void
|
void
|
||||||
ox_discover_public_key(const char* const jid)
|
ox_discover_public_key(const char* const jid)
|
||||||
{
|
{
|
||||||
assert(jid);
|
assert(jid && strlen(jid) > 0);
|
||||||
log_info("Discovering Public Key for %s", jid);
|
log_info("[OX] Discovering Public Key for %s", jid);
|
||||||
cons_show("Discovering Public Key for %s", jid);
|
cons_show("Discovering Public Key for %s", jid);
|
||||||
// iq
|
// iq
|
||||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||||
@ -188,6 +191,7 @@ ox_discover_public_key(const char* const jid)
|
|||||||
|
|
||||||
xmpp_id_handler_add(connection_get_conn(), _ox_metadata_result, id, strdup(jid));
|
xmpp_id_handler_add(connection_get_conn(), _ox_metadata_result, id, strdup(jid));
|
||||||
xmpp_send(connection_get_conn(), iq);
|
xmpp_send(connection_get_conn(), iq);
|
||||||
|
xmpp_stanza_release(iq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -228,7 +232,7 @@ _ox_metadata_node__public_key(const char* const fingerprint)
|
|||||||
{
|
{
|
||||||
log_info("Annonuce OpenPGP metadata: %s", fingerprint);
|
log_info("Annonuce OpenPGP metadata: %s", fingerprint);
|
||||||
assert(fingerprint);
|
assert(fingerprint);
|
||||||
assert(strlen(fingerprint) == 40);
|
assert(strlen(fingerprint) == KEYID_LENGTH);
|
||||||
// iq
|
// iq
|
||||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||||
char* id = xmpp_uuid_gen(ctx);
|
char* id = xmpp_uuid_gen(ctx);
|
||||||
@ -269,7 +273,7 @@ _ox_metadata_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void*
|
|||||||
log_debug("[OX] Processing result %s's metadata.", (char*)userdata);
|
log_debug("[OX] Processing result %s's metadata.", (char*)userdata);
|
||||||
|
|
||||||
if (g_strcmp0(xmpp_stanza_get_type(stanza), "result") != 0) {
|
if (g_strcmp0(xmpp_stanza_get_type(stanza), "result") != 0) {
|
||||||
log_debug("[OX] Error: No result");
|
log_debug("[OX] Error: Unable to load metadata of user %s - Not a stanza result type", (char*)userdata);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// pubsub
|
// pubsub
|
||||||
@ -301,8 +305,11 @@ _ox_metadata_result(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void*
|
|||||||
|
|
||||||
while (pubkeymetadata) {
|
while (pubkeymetadata) {
|
||||||
const char* fingerprint = xmpp_stanza_get_attribute(pubkeymetadata, STANZA_ATTR_V4_FINGERPRINT);
|
const char* fingerprint = xmpp_stanza_get_attribute(pubkeymetadata, STANZA_ATTR_V4_FINGERPRINT);
|
||||||
if (fingerprint) {
|
if ( strlen( fingerprint ) == KEYID_LENGTH ) {
|
||||||
cons_show(fingerprint);
|
cons_show(fingerprint);
|
||||||
|
} else {
|
||||||
|
cons_show("OX: Wrong char size of public key");
|
||||||
|
log_error("[OX] Wrong chat size of public key %s", fingerprint);
|
||||||
}
|
}
|
||||||
pubkeymetadata = xmpp_stanza_get_next(pubkeymetadata);
|
pubkeymetadata = xmpp_stanza_get_next(pubkeymetadata);
|
||||||
}
|
}
|
||||||
@ -332,7 +339,7 @@ _ox_request_public_key(const char* const jid, const char* const fingerprint)
|
|||||||
{
|
{
|
||||||
assert(jid);
|
assert(jid);
|
||||||
assert(fingerprint);
|
assert(fingerprint);
|
||||||
assert(strlen(fingerprint) == 40);
|
assert(strlen(fingerprint) == KEYID_LENGTH);
|
||||||
cons_show("Requesting Public Key %s for %s", fingerprint, jid);
|
cons_show("Requesting Public Key %s for %s", fingerprint, jid);
|
||||||
log_info("[OX] Request %s's public key %s.", jid, fingerprint);
|
log_info("[OX] Request %s's public key %s.", jid, fingerprint);
|
||||||
// iq
|
// iq
|
||||||
|
Loading…
Reference in New Issue
Block a user