diff options
author | Michael Vetter <jubalh@iodoru.org> | 2022-03-21 10:08:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-21 10:08:13 +0100 |
commit | 024694215dce1be21b09b8096eb499f107563f66 (patch) | |
tree | e4136051c50a46e7c852c698cf5a7a52eef69f5c | |
parent | 963065775b0f1008b149b80c19620636a35f8d49 (diff) | |
parent | cdb8383260ce132e1b4784841727a4b210688b91 (diff) | |
download | profani-tty-024694215dce1be21b09b8096eb499f107563f66.tar.gz |
Merge pull request #1644 from profanity-im/ox-polish
Improve OX user experience
-rw-r--r-- | src/command/cmd_ac.c | 23 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 18 | ||||
-rw-r--r-- | src/pgp/gpg.c | 71 | ||||
-rw-r--r-- | src/xmpp/ox.c | 87 |
4 files changed, 97 insertions, 102 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 57484736..bb703cfb 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2554,11 +2554,6 @@ _pgp_autocomplete(ProfWin* window, const char* const input, gboolean previous) return NULL; } -/*! - * \brief Auto completion for XEP-0373: OpenPGP for XMPP command. - * - * - */ static char* _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous) { @@ -2590,23 +2585,9 @@ _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous) return found; } - gboolean result; - gchar** args = parse_args(input, 2, 3, &result); - if ((strncmp(input, "/ox", 4) == 0) && (result == TRUE)) { - GString* beginning = g_string_new("/ox "); - g_string_append(beginning, args[0]); - if (args[1]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[1]); - } - found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key, previous, NULL); - g_string_free(beginning, TRUE); - if (found) { - g_strfreev(args); - return found; - } + if (strncmp(input, "/ox announce ", 13) == 0) { + return cmd_ac_complete_filepath(input, "/ox announce", previous); } - g_strfreev(args); if (conn_status == JABBER_CONNECTED) { found = autocomplete_param_with_func(input, "/ox setkey", roster_barejid_autocomplete, previous, NULL); diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index eabfb4bf..b1aadbf0 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1102,6 +1102,7 @@ cmd_export(ProfWin* window, const char* const command, gchar** args) char* path = get_expanded_path(args[0]); fd = open(path, O_WRONLY | O_CREAT, 00600); + free(path); if (-1 == fd) { cons_show("error: cannot open %s: %s", args[0], strerror(errno)); @@ -7630,7 +7631,22 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args) return TRUE; } else if (g_strcmp0(args[0], "announce") == 0) { if (args[1]) { - ox_announce_public_key(args[1]); + gchar* filename = get_expanded_path(args[1]); + + if (access(filename, R_OK) != 0) { + cons_show_error("File not found: %s", filename); + g_free(filename); + return TRUE; + } + + if (!is_regular_file(filename)) { + cons_show_error("Not a file: %s", filename); + g_free(filename); + return TRUE; + } + + ox_announce_public_key(filename); + free(filename); } else { cons_show("Filename is required"); } diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c index a1300f80..99d37c64 100644 --- a/src/pgp/gpg.c +++ b/src/pgp/gpg.c @@ -792,7 +792,7 @@ ox_gpg_public_keys(void) error = gpgme_new(&ctx); if (error) { - log_error("OX - gpgme_new failed: %s %s", gpgme_strsource(error), gpgme_strerror(error)); + log_error("OX: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error)); return NULL; } @@ -880,13 +880,13 @@ p_ox_gpg_signcrypt(const char* const sender_barejid, const char* const recipient gpgme_error_t error = gpgme_new(&ctx); if (GPG_ERR_NO_ERROR != error) { - printf("gpgme_new: %d\n", error); + log_error("OX: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error)); return NULL; } error = gpgme_set_protocol(ctx, GPGME_PROTOCOL_OPENPGP); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: Signcrypt error: %s", gpgme_strerror(error)); } gpgme_set_armor(ctx, 0); @@ -894,7 +894,7 @@ p_ox_gpg_signcrypt(const char* const sender_barejid, const char* const recipient gpgme_set_offline(ctx, 1); gpgme_set_keylist_mode(ctx, GPGME_KEYLIST_MODE_LOCAL); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: Signcrypt error: %s", gpgme_strerror(error)); } gpgme_key_t recp[3]; @@ -914,22 +914,23 @@ p_ox_gpg_signcrypt(const char* const sender_barejid, const char* const recipient // lookup own key recp[0] = _ox_key_lookup(sender_barejid, TRUE); if (error != 0) { - log_error("Key not found for %s. GpgME Error: %s", xmpp_jid_me, gpgme_strerror(error)); + log_error("OX: Key not found for %s. Error: %s", xmpp_jid_me, gpgme_strerror(error)); return NULL; } error = gpgme_signers_add(ctx, recp[0]); if (error != 0) { - log_error("gpgme_signers_add %s. GpgME Error: %s", xmpp_jid_me, gpgme_strerror(error)); + log_error("OX: gpgme_signers_add %s. Error: %s", xmpp_jid_me, gpgme_strerror(error)); return NULL; } // lookup key of recipient recp[1] = _ox_key_lookup(recipient_barejid, FALSE); if (error != 0) { - log_error("Key not found for %s. GpgME Error: %s", xmpp_jid_recipient, gpgme_strerror(error)); + log_error("OX: Key not found for %s. Error: %s", xmpp_jid_recipient, gpgme_strerror(error)); return NULL; } + recp[2] = NULL; log_debug("%s <%s>", recp[0]->uids->name, recp[0]->uids->email); log_debug("%s <%s>", recp[1]->uids->name, recp[1]->uids->email); @@ -941,24 +942,24 @@ p_ox_gpg_signcrypt(const char* const sender_barejid, const char* const recipient error = gpgme_data_new(&plain); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); return NULL; } error = gpgme_data_new_from_mem(&plain, message, strlen(message), 0); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); return NULL; } error = gpgme_data_new(&cipher); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); return NULL; } error = gpgme_op_encrypt_sign(ctx, recp, flags, plain, cipher); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); return NULL; } @@ -1058,7 +1059,7 @@ static gpgme_key_t _ox_key_lookup(const char* const barejid, gboolean secret_only) { g_assert(barejid); - log_debug("Looking for %s key: %s", secret_only == TRUE ? "Private" : "Public", barejid); + log_debug("OX: Looking for %s key: %s", secret_only == TRUE ? "Private" : "Public", barejid); gpgme_key_t key = NULL; gpgme_error_t error; @@ -1066,7 +1067,7 @@ _ox_key_lookup(const char* const barejid, gboolean secret_only) error = gpgme_new(&ctx); if (error) { - log_error("OX - gpgme_new failed: %s %s", gpgme_strsource(error), gpgme_strerror(error)); + log_error("OX: gpgme_new failed: %s %s", gpgme_strsource(error), gpgme_strerror(error)); return NULL; } @@ -1118,8 +1119,6 @@ _ox_key_is_usable(gpgme_key_t key, const char* const barejid, gboolean secret) /*! * @brief XMPP-OX: Decrypt OX Message. * - * - * * @param base64 base64_encode OpenPGP message. * * @result decrypt XMPP OX Message NULL terminated C-String @@ -1139,13 +1138,13 @@ p_ox_gpg_decrypt(char* base64) gpgme_error_t error = gpgme_new(&ctx); if (GPG_ERR_NO_ERROR != error) { - printf("gpgme_new: %d\n", error); + log_error("OX: gpgme_new failed: %s %s", gpgme_strsource(error), gpgme_strerror(error)); return NULL; } error = gpgme_set_protocol(ctx, GPGME_PROTOCOL_OPENPGP); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); } gpgme_set_armor(ctx, 0); @@ -1153,7 +1152,7 @@ p_ox_gpg_decrypt(char* base64) gpgme_set_offline(ctx, 1); gpgme_set_keylist_mode(ctx, GPGME_KEYLIST_MODE_LOCAL); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); } gpgme_data_t plain = NULL; @@ -1163,19 +1162,19 @@ p_ox_gpg_decrypt(char* base64) guchar* encrypted = g_base64_decode(base64, &s); error = gpgme_data_new_from_mem(&cipher, (char*)encrypted, s, 0); if (error != 0) { - log_error("GpgME Error gpgme_data_new_from_mem: %s", gpgme_strerror(error)); + log_error("OX: gpgme_data_new_from_mem: %s", gpgme_strerror(error)); return NULL; } error = gpgme_data_new(&plain); if (error != 0) { - log_error("GpgME Error: %s", gpgme_strerror(error)); + log_error("OX: %s", gpgme_strerror(error)); return NULL; } error = gpgme_op_decrypt_verify(ctx, cipher, plain); if (error != 0) { - log_error("GpgME Error gpgme_op_decrypt: %s", gpgme_strerror(error)); + log_error("OX: gpgme_op_decrypt: %s", gpgme_strerror(error)); error = gpgme_op_decrypt(ctx, cipher, plain); if (error != 0) { return NULL; @@ -1211,12 +1210,10 @@ p_ox_gpg_decrypt(char* base64) * \param fp result with the fingerprint or NULL * */ - void p_ox_gpg_readkey(const char* const filename, char** key, char** fp) { - - log_info("Read OpenPGP Key from file %s", filename); + log_info("PX: Read OpenPGP Key from file %s", filename); GError* error = NULL; gchar* data = NULL; @@ -1234,13 +1231,13 @@ p_ox_gpg_readkey(const char* const filename, char** key, char** fp) gpgme_error_t error = gpgme_new(&ctx); if (GPG_ERR_NO_ERROR != error) { - log_error("Read OpenPGP key from file: gpgme_new failed: %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_new failed: %s", gpgme_strerror(error)); return; } error = gpgme_set_protocol(ctx, GPGME_PROTOCOL_OPENPGP); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: set GPGME_PROTOCOL_OPENPGP: %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: set GPGME_PROTOCOL_OPENPGP: %s", gpgme_strerror(error)); return; } @@ -1252,36 +1249,36 @@ p_ox_gpg_readkey(const char* const filename, char** key, char** fp) gpgme_data_t gpgme_data = NULL; error = gpgme_data_new(&gpgme_data); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: gpgme_data_new %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_data_new %s", gpgme_strerror(error)); return; } error = gpgme_data_new_from_mem(&gpgme_data, (char*)data, size, 0); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: gpgme_data_new_from_mem %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_data_new_from_mem %s", gpgme_strerror(error)); return; } error = gpgme_op_keylist_from_data_start(ctx, gpgme_data, 0); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: gpgme_op_keylist_from_data_start %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_op_keylist_from_data_start %s", gpgme_strerror(error)); return; } gpgme_key_t gkey; error = gpgme_op_keylist_next(ctx, &gkey); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: gpgme_op_keylist_next %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_op_keylist_next %s", gpgme_strerror(error)); return; } gpgme_key_t end; error = gpgme_op_keylist_next(ctx, &end); if (error == GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: ambiguous key"); + log_error("OX: Read OpenPGP key from file: ambiguous key"); return; } if (gkey->revoked || gkey->expired || gkey->disabled || gkey->invalid || gkey->secret) { - log_error("Read OpenPGP key from file: Key is not valid"); + log_error("OX: Read OpenPGP key from file: Key is not valid"); return; } @@ -1290,7 +1287,7 @@ p_ox_gpg_readkey(const char* const filename, char** key, char** fp) *key = strdup(keybase64); *fp = strdup(gkey->fpr); } else { - log_error("Read OpenPGP key from file: Unable to read file: %s", error->message); + log_error("OX: Read OpenPGP key from file: Unable to read file: %s", error->message); } } @@ -1307,13 +1304,13 @@ p_ox_gpg_import(char* base64_public_key) gpgme_error_t error = gpgme_new(&ctx); if (GPG_ERR_NO_ERROR != error) { - log_error("Read OpenPGP key from file: gpgme_new failed: %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_new failed: %s", gpgme_strerror(error)); return FALSE; } error = gpgme_set_protocol(ctx, GPGME_PROTOCOL_OPENPGP); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: set GPGME_PROTOCOL_OPENPGP: %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: set GPGME_PROTOCOL_OPENPGP: %s", gpgme_strerror(error)); return FALSE; } @@ -1325,14 +1322,14 @@ p_ox_gpg_import(char* base64_public_key) gpgme_data_t gpgme_data = NULL; error = gpgme_data_new(&gpgme_data); if (error != GPG_ERR_NO_ERROR) { - log_error("Read OpenPGP key from file: gpgme_data_new %s", gpgme_strerror(error)); + log_error("OX: Read OpenPGP key from file: gpgme_data_new %s", gpgme_strerror(error)); return FALSE; } gpgme_data_new_from_mem(&gpgme_data, (gchar*)key, size, 0); error = gpgme_op_import(ctx, gpgme_data); if (error != GPG_ERR_NO_ERROR) { - log_error("Failed to import key"); + log_error("OX: Failed to import key"); } return TRUE; diff --git a/src/xmpp/ox.c b/src/xmpp/ox.c index c4efa5d6..012a4017 100644 --- a/src/xmpp/ox.c +++ b/src/xmpp/ox.c @@ -102,50 +102,51 @@ ox_announce_public_key(const char* const filename) if (!(key && fp)) { cons_show("Error during OpenPGP OX announce. See log file for more information"); return FALSE; - } else { - log_info("[OX] Annonuce OpenPGP Key for Fingerprint: %s", fp); - xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = xmpp_uuid_gen(ctx); - xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - xmpp_stanza_set_from(iq, xmpp_conn_get_jid(connection_get_conn())); - - xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB); - xmpp_stanza_set_ns(pubsub, XMPP_FEATURE_PUBSUB); - - GString* node_name = g_string_new(STANZA_NS_OPENPGP_0_PUBLIC_KEYS); - g_string_append(node_name, ":"); - g_string_append(node_name, fp); - - xmpp_stanza_t* publish = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH); - xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, node_name->str); - - xmpp_stanza_t* item = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(item, STANZA_NAME_ITEM); - char* timestamp = _gettimestamp(); - xmpp_stanza_set_attribute(item, STANZA_ATTR_ID, timestamp); - free(timestamp); - - xmpp_stanza_t* pubkey = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(pubkey, STANZA_NAME_PUPKEY); - xmpp_stanza_set_ns(pubkey, STANZA_NS_OPENPGP_0); - - xmpp_stanza_t* data = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(data, STANZA_NAME_DATA); - xmpp_stanza_t* keydata = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(keydata, key); - - xmpp_stanza_add_child(data, keydata); - xmpp_stanza_add_child(pubkey, data); - xmpp_stanza_add_child(item, pubkey); - xmpp_stanza_add_child(publish, item); - xmpp_stanza_add_child(pubsub, publish); - xmpp_stanza_add_child(iq, pubsub); - xmpp_send(connection_get_conn(), iq); - - _ox_metadata_node__public_key(fp); } + + log_info("[OX] Annonuce OpenPGP Key for Fingerprint: %s", fp); + xmpp_ctx_t* const ctx = connection_get_ctx(); + char* id = xmpp_uuid_gen(ctx); + xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); + xmpp_stanza_set_from(iq, xmpp_conn_get_jid(connection_get_conn())); + + xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB); + xmpp_stanza_set_ns(pubsub, XMPP_FEATURE_PUBSUB); + + GString* node_name = g_string_new(STANZA_NS_OPENPGP_0_PUBLIC_KEYS); + g_string_append(node_name, ":"); + g_string_append(node_name, fp); + + xmpp_stanza_t* publish = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH); + xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, node_name->str); + + xmpp_stanza_t* item = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(item, STANZA_NAME_ITEM); + char* timestamp = _gettimestamp(); + xmpp_stanza_set_attribute(item, STANZA_ATTR_ID, timestamp); + free(timestamp); + + xmpp_stanza_t* pubkey = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(pubkey, STANZA_NAME_PUPKEY); + xmpp_stanza_set_ns(pubkey, STANZA_NS_OPENPGP_0); + + xmpp_stanza_t* data = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(data, STANZA_NAME_DATA); + xmpp_stanza_t* keydata = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(keydata, key); + + xmpp_stanza_add_child(data, keydata); + xmpp_stanza_add_child(pubkey, data); + xmpp_stanza_add_child(item, pubkey); + xmpp_stanza_add_child(publish, item); + xmpp_stanza_add_child(pubsub, publish); + xmpp_stanza_add_child(iq, pubsub); + xmpp_send(connection_get_conn(), iq); + + _ox_metadata_node__public_key(fp); + return TRUE; } |