Merge upstream/master into merge/upstream-full
All checks were successful
CI Code / Check coding style (pull_request) Successful in 32s
CI Code / Check spelling (pull_request) Successful in 15s
CI Code / Linux (debian) (pull_request) Successful in 6m43s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m49s
CI Code / Linux (arch) (pull_request) Successful in 8m52s
CI Code / Code Coverage (pull_request) Successful in 7m19s
All checks were successful
CI Code / Check coding style (pull_request) Successful in 32s
CI Code / Check spelling (pull_request) Successful in 15s
CI Code / Linux (debian) (pull_request) Successful in 6m43s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m49s
CI Code / Linux (arch) (pull_request) Successful in 8m52s
CI Code / Code Coverage (pull_request) Successful in 7m19s
Merge profanity-im/profanity master (373 commits) into cproof fork.
Source changes (manual merge):
- src/command/: cmd_defs, cmd_funcs, cmd_ac — upstream g_new0, auto_gchar,
launch_editor callback; keep our XEP-0308 LMC, force-encryption, CWE-134
- src/config/: preferences, tlscerts, account — upstream UNIQUE dedup,
dynamic pad capacity; keep our db_history_result_t, scroll logic
- src/database.*: upstream g_new0 memory mgmt; keep our return types,
add null-check fix for msg->timestamp
- src/omemo/, src/pgp/: upstream _gpgme_key_get_email, g_new0;
keep our replace_id in omemo_on_message_send
- src/tools/: editor, http_upload, bookmark_ignore — upstream launch_editor
callback API
- src/ui/: console, window, chatwin, mucwin, inputwin, buffer —
upstream win_warn_needed/sent dedup, PAD_MIN_HEIGHT dynamic pads;
keep our y_start_pos scroll, _truncate_datetime_suffix
- src/xmpp/: message, stanza, presence, roster_list, iq, session —
upstream connection_get_available_resources; keep our LMC stanza logic
- src/common.c: fix format-security (cons_show)
Build system:
- Makefile.am: updated test paths to subdirectory structure, added
test_cmd_ac, test_forced_encryption
- Restored autotools files deleted by upstream meson migration:
bootstrap.sh, autogen.sh, m4/ax_valgrind_check.m4, configure-debug
Tests:
- Unit tests: upstream unittests.c base + our forced_encryption tests
(482 passed, 0 failed across all 4 configurations)
- Functional tests: kept our version (93 passed, 0 failed)
upstream version requires stbbr_for_xmlns not yet in our stabber fork
- Updated test stubs: stub_xmpp.c, stub_omemo.c from upstream
Compile fixes:
- src/common.c: cons_show(errmsg) -> cons_show("%s", errmsg)
- src/database.c: null-check before msg->timestamp access
- src/ui/console.c: size_t -> (int) cast for format width
- src/config/tlscerts.c: %d -> %zu for size_t
This commit is contained in:
106
src/xmpp/omemo.c
106
src/xmpp/omemo.c
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2019 Paul Fariello <paul@fariello.eu>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -116,6 +90,11 @@ omemo_devicelist_request(const char* const jid)
|
||||
void
|
||||
omemo_bundle_publish(gboolean first)
|
||||
{
|
||||
if (!connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
|
||||
cons_show("OMEMO: Cannot publish bundle: no PUBSUB feature announced");
|
||||
log_debug("[OMEMO] Cannot publish bundle: no PUBSUB feature announced");
|
||||
return;
|
||||
}
|
||||
log_debug("[OMEMO] publish own OMEMO bundle");
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
unsigned char* identity_key = NULL;
|
||||
@@ -141,14 +120,10 @@ omemo_bundle_publish(gboolean first)
|
||||
g_list_free(lengths);
|
||||
g_list_free(ids);
|
||||
|
||||
if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
|
||||
stanza_attach_publish_options_va(ctx, iq,
|
||||
4, // 2 * number of key-value pairs
|
||||
"pubsub#persist_items", "true",
|
||||
"pubsub#access_model", "open");
|
||||
} else {
|
||||
log_debug("[OMEMO] Cannot publish bundle: no PUBSUB feature announced");
|
||||
}
|
||||
stanza_attach_publish_options_va(ctx, iq,
|
||||
4, // 2 * number of key-value pairs
|
||||
"pubsub#persist_items", "true",
|
||||
"pubsub#access_model", "open");
|
||||
|
||||
iq_id_handler_add(id, _omemo_bundle_publish_result, NULL, GINT_TO_POINTER(first));
|
||||
|
||||
@@ -243,7 +218,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
|
||||
continue;
|
||||
}
|
||||
|
||||
omemo_key_t* key = malloc(sizeof(omemo_key_t));
|
||||
omemo_key_t* key = g_new0(omemo_key_t, 1);
|
||||
key->data = NULL;
|
||||
|
||||
const char* prekey_id_text = xmpp_stanza_get_attribute(prekey, "preKeyId");
|
||||
@@ -349,8 +324,12 @@ out:
|
||||
}
|
||||
|
||||
char*
|
||||
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted, omemo_error_t* error)
|
||||
{
|
||||
if (!stanza || !trusted || !error) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* plaintext = NULL;
|
||||
const char* type = xmpp_stanza_get_type(stanza);
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
@@ -359,6 +338,9 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
unsigned char* payload_raw = NULL;
|
||||
char* iv_text = NULL;
|
||||
char* payload_text = NULL;
|
||||
size_t payload_len = 0;
|
||||
|
||||
*error = OMEMO_ERR_NONE;
|
||||
|
||||
xmpp_stanza_t* encrypted = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_OMEMO);
|
||||
if (!encrypted) {
|
||||
@@ -367,41 +349,44 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
|
||||
xmpp_stanza_t* header = xmpp_stanza_get_child_by_name(encrypted, "header");
|
||||
if (!header) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* sid_text = xmpp_stanza_get_attribute(header, "sid");
|
||||
if (!sid_text) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
return NULL;
|
||||
}
|
||||
uint32_t sid = strtoul(sid_text, NULL, 10);
|
||||
|
||||
xmpp_stanza_t* iv = xmpp_stanza_get_child_by_name(header, "iv");
|
||||
if (!iv) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
return NULL;
|
||||
}
|
||||
iv_text = xmpp_stanza_get_text(iv);
|
||||
if (!iv_text) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
return NULL;
|
||||
}
|
||||
size_t iv_len;
|
||||
iv_raw = g_base64_decode(iv_text, &iv_len);
|
||||
if (!iv_raw) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmpp_stanza_t* payload = xmpp_stanza_get_child_by_name(encrypted, "payload");
|
||||
if (!payload) {
|
||||
goto quit;
|
||||
}
|
||||
payload_text = xmpp_stanza_get_text(payload);
|
||||
if (!payload_text) {
|
||||
goto quit;
|
||||
}
|
||||
size_t payload_len;
|
||||
payload_raw = g_base64_decode(payload_text, &payload_len);
|
||||
if (!payload_raw) {
|
||||
goto quit;
|
||||
if (payload) {
|
||||
payload_text = xmpp_stanza_get_text(payload);
|
||||
if (payload_text) {
|
||||
payload_raw = g_base64_decode(payload_text, &payload_len);
|
||||
if (!payload_raw) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmpp_stanza_t* key_stanza;
|
||||
@@ -410,7 +395,7 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
continue;
|
||||
}
|
||||
|
||||
omemo_key_t* key = malloc(sizeof(omemo_key_t));
|
||||
omemo_key_t* key = g_new0(omemo_key_t, 1);
|
||||
char* key_text = xmpp_stanza_get_text(key_stanza);
|
||||
if (!key_text) {
|
||||
free(key);
|
||||
@@ -437,7 +422,7 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
|
||||
plaintext = omemo_on_message_recv(from, sid, iv_raw, iv_len,
|
||||
keys, payload_raw, payload_len,
|
||||
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted);
|
||||
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted, error);
|
||||
|
||||
if (keys) {
|
||||
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
|
||||
@@ -722,3 +707,24 @@ _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char*
|
||||
omemo_error_to_string(omemo_error_t error)
|
||||
{
|
||||
switch (error) {
|
||||
case OMEMO_ERR_NO_KEY:
|
||||
return g_strdup("OMEMO message received but no key for this device found.");
|
||||
case OMEMO_ERR_NOT_TRUSTED:
|
||||
return g_strdup("OMEMO message received but sender identity is untrusted.");
|
||||
case OMEMO_ERR_NO_SESSION:
|
||||
return g_strdup("OMEMO message received but no session found. Try '/omemo start'.");
|
||||
case OMEMO_ERR_DECRYPT_FAILED:
|
||||
return g_strdup("OMEMO message received but decryption failed.");
|
||||
case OMEMO_ERR_KEY_TRANSPORT:
|
||||
return NULL;
|
||||
case OMEMO_ERR_NONE:
|
||||
return NULL;
|
||||
default:
|
||||
return g_strdup("OMEMO message received but could not be decrypted.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user