All checks were successful
CI Code / Check spelling (push) Successful in 18s
CI Code / Check coding style (push) Successful in 34s
CI Code / Code Coverage (push) Successful in 2m36s
CI Code / Linux (debian) (push) Successful in 4m41s
CI Code / Linux (ubuntu) (push) Successful in 4m52s
CI Code / Linux (arch) (push) Successful in 5m40s
Sync with upstream profanity-im/profanity.
Major upstream changes incorporated:
Memory management
- Replace malloc+memset with g_new0 throughout codebase
- Adopt auto_gchar / auto_gcharv / auto_gerror / auto_jid cleanup macros
- Replace free() with g_free() for GAlloc'd memory
Editor rewrite
- Remove pthread-based async editor; use GChildWatch callback API
- New launch_editor(initial_content, callback, user_data) interface
- Proper signal handling (SIGINT, SIGTSTP, SIGPIPE reset in child)
- ui_suspend()/ui_resume() integration for TTY management
OMEMO improvements
- Dual backend support: libsignal-protocol-c and libomemo-c
- Proper pre-key removal after use (XEP-0384 compliance)
- Automatic pre-key regeneration when store drops below threshold
- New functions: omemo_is_device_active(), omemo_is_jid_trusted()
- omemo_get_jid_untrusted_fingerprints() for better error messages
- Fingerprint notifications on new device identity discovery
- Deterministic pre-key ID generation tracking max_pre_key_id
- omemo_trust_changed() UI updates on trust state changes
JID validation
- RFC 6122-compliant validation in jid_is_valid()
- Character-level checks (RFC 6122 forbidden chars: & ' / : < > @)
- Length limits: 1023 per component, 3071 total
- New jid_is_valid_user_jid() for user vs. service JID distinction
Database
- Schema migration v3: UNIQUE constraint on archive_id for deduplication
- Triggers for corrected message tracking (replaces_db_id / replaced_by_db_id)
- db_history_result_t return type, _truncate_datetime_suffix()
UI / console
- win_warn_needed() / win_warn_sent() warning deduplication hash table
- PAD_MIN_HEIGHT dynamic pad sizing with PAD_THRESHOLD auto-cleanup
- Spellcheck integration in input field with Unicode word detection
- cons_spellcheck_setting() for /settings ui output
- /[command]? shortcut for command help
Account config
- Account name sanitization for GKeyFile special chars ([ ] = # \n \r)
- Replace popen() with g_spawn_sync() for eval_password
- TLS policy: add "direct" option alongside legacy
Connection
- Port validation with g_assert (0–65535)
- SHA-256 certificate fingerprint support (XMPP_CERT_PUBKEY_FINGERPRINT_SHA256)
- "direct" TLS policy alias for legacy SSL
Common utilities
- str_xml_sanitize() for XML 1.0 illegal character removal
- string_matches_one_of() with formatted error messages
- valid_tls_policy_option() helper
- prof_date_time_format_iso8601() utility
- Improved strip_arg_quotes() with backslash unescaping
- prof_occurrences() uses g_slist_prepend + reverse for performance
PGP / OX
- Proper GPGME resource cleanup with goto-cleanup pattern
- g_string_free(xmppuri) leak fix in _ox_key_lookup
CSV export
- Use GString + g_file_set_contents instead of raw write() syscalls
Tests
- Restructured into subdirectories: command/, config/, xmpp/, ui/, omemo/, otr/, pgp/
- New test_cmd_ac.c for autocompleter unit tests
- Updated stubs for new UI suspend/resume functions
License headers
- Migrate to SPDX-3.0 identifiers (GPL-3.0-or-later WITH OpenSSL-exception)
────────────────────────────────────────────────────
cproof-specific preservations:
- XEP-0308 LMC: replace_id ?: id logic in message/stanza/omemo
- Force encryption: cmd_force_encryption, test_forced_encryption
- CWE-134: format string protection (cons_show("%s", ...))
- y_start_pos-based paging in window.c
- db_history_result_t return type, _truncate_datetime_suffix()
Merge-time fixes:
- common.c: format-security (-Werror) — cons_show(errmsg) → cons_show("%s", errmsg)
- database.c: null-deref guard — !msg->timestamp → msg && !msg->timestamp
- console.c: implicit size_t → int cast — (int)(maxlen + 1)
- tlscerts.c: %d for size_t — %zu
Build system:
- Kept autotools (Makefile.am, configure.ac); upstream uses Meson
- Restored deleted files: bootstrap.sh, autogen.sh, ax_valgrind_check.m4, configure-debug
- Updated Makefile.am test paths for subdirectory structure
- Added test_cmd_ac, test_forced_encryption to test sources
Functional tests:
- Use cproof version; upstream requires stbbr_for_xmlns from updated stabber
- Not yet available in devs/stabber fork
Closes #64
Merge author: jabber.developer2
Commits authors:
Michael Vetter <jubalh@iodoru.org>
& Steffen Jaeckel <s@jaeckel.eu>
427 lines
13 KiB
C
427 lines
13 KiB
C
/*
|
|
* store.c
|
|
* vim: expandtab:ts=4:sts=4:sw=4
|
|
*
|
|
* Copyright (C) 2019 Paul Fariello <paul@fariello.eu>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
|
*/
|
|
#include <glib.h>
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_LIBOMEMO_C
|
|
#include <omemo/signal_protocol.h>
|
|
#else
|
|
#include <signal/signal_protocol.h>
|
|
#endif
|
|
|
|
#include "log.h"
|
|
#include "omemo/omemo.h"
|
|
#include "omemo/store.h"
|
|
|
|
GHashTable*
|
|
session_store_new(void)
|
|
{
|
|
return g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
|
|
}
|
|
|
|
GHashTable*
|
|
pre_key_store_new(void)
|
|
{
|
|
return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
|
}
|
|
|
|
GHashTable*
|
|
signed_pre_key_store_new(void)
|
|
{
|
|
return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
|
}
|
|
|
|
void
|
|
identity_key_store_new(identity_key_store_t* identity_key_store)
|
|
{
|
|
identity_key_store->trusted = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
|
|
identity_key_store->private = NULL;
|
|
identity_key_store->public = NULL;
|
|
}
|
|
|
|
void
|
|
identity_key_store_destroy(identity_key_store_t* identity_key_store)
|
|
{
|
|
signal_buffer_bzero_free(identity_key_store->private);
|
|
signal_buffer_bzero_free(identity_key_store->public);
|
|
g_hash_table_destroy(identity_key_store->trusted);
|
|
}
|
|
|
|
int
|
|
load_session(signal_buffer** record, signal_buffer** user_record,
|
|
const signal_protocol_address* address, void* user_data)
|
|
{
|
|
GHashTable* session_store = (GHashTable*)user_data;
|
|
GHashTable* device_store = NULL;
|
|
|
|
log_debug("[OMEMO][STORE] Looking for %s in session_store", address->name);
|
|
device_store = g_hash_table_lookup(session_store, address->name);
|
|
if (!device_store) {
|
|
*record = NULL;
|
|
log_info("[OMEMO][STORE] No device store for %s found", address->name);
|
|
return 0;
|
|
}
|
|
|
|
log_debug("[OMEMO][STORE] Looking for device %d of %s ", address->device_id, address->name);
|
|
signal_buffer* original = g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id));
|
|
if (!original) {
|
|
*record = NULL;
|
|
log_warning("[OMEMO][STORE] No device (%d) store for %s found", address->device_id, address->name);
|
|
return 0;
|
|
}
|
|
*record = signal_buffer_copy(original);
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
get_sub_device_sessions(signal_int_list** sessions, const char* name,
|
|
size_t name_len, void* user_data)
|
|
{
|
|
GHashTable* session_store = (GHashTable*)user_data;
|
|
GHashTable* device_store = NULL;
|
|
GHashTableIter iter;
|
|
gpointer key, value;
|
|
|
|
device_store = g_hash_table_lookup(session_store, name);
|
|
if (!device_store) {
|
|
log_debug("[OMEMO][STORE] What?");
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
*sessions = signal_int_list_alloc();
|
|
g_hash_table_iter_init(&iter, device_store);
|
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
|
signal_int_list_push_back(*sessions, GPOINTER_TO_INT(key));
|
|
}
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
store_session(const signal_protocol_address* address,
|
|
uint8_t* record, size_t record_len,
|
|
uint8_t* user_record, size_t user_record_len,
|
|
void* user_data)
|
|
{
|
|
GHashTable* session_store = (GHashTable*)user_data;
|
|
GHashTable* device_store = NULL;
|
|
|
|
log_debug("[OMEMO][STORE] Store session for %s (%d)", address->name, address->device_id);
|
|
device_store = g_hash_table_lookup(session_store, (void*)address->name);
|
|
if (!device_store) {
|
|
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
|
g_hash_table_insert(session_store, strdup(address->name), device_store);
|
|
}
|
|
|
|
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
|
g_hash_table_insert(device_store, GINT_TO_POINTER(address->device_id), buffer);
|
|
|
|
auto_gchar gchar* record_b64 = g_base64_encode(record, record_len);
|
|
auto_gchar gchar* device_id = g_strdup_printf("%d", address->device_id);
|
|
g_key_file_set_string(omemo_sessions_keyfile(), address->name, device_id, record_b64);
|
|
|
|
omemo_sessions_keyfile_save();
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
contains_session(const signal_protocol_address* address, void* user_data)
|
|
{
|
|
GHashTable* session_store = (GHashTable*)user_data;
|
|
GHashTable* device_store = NULL;
|
|
|
|
device_store = g_hash_table_lookup(session_store, address->name);
|
|
if (!device_store) {
|
|
log_debug("[OMEMO][STORE] No Device");
|
|
return 0;
|
|
}
|
|
|
|
if (!g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id))) {
|
|
log_debug("[OMEMO][STORE] No Session for %d ", address->device_id);
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
delete_session(const signal_protocol_address* address, void* user_data)
|
|
{
|
|
GHashTable* session_store = (GHashTable*)user_data;
|
|
GHashTable* device_store = NULL;
|
|
|
|
device_store = g_hash_table_lookup(session_store, address->name);
|
|
if (!device_store) {
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
g_hash_table_remove(device_store, GINT_TO_POINTER(address->device_id));
|
|
|
|
auto_gchar gchar* device_id_str = g_strdup_printf("%d", address->device_id);
|
|
g_key_file_remove_key(omemo_sessions_keyfile(), address->name, device_id_str, NULL);
|
|
omemo_sessions_keyfile_save();
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
delete_all_sessions(const char* name, size_t name_len, void* user_data)
|
|
{
|
|
GHashTable* session_store = (GHashTable*)user_data;
|
|
GHashTable* device_store = NULL;
|
|
|
|
device_store = g_hash_table_lookup(session_store, name);
|
|
if (!device_store) {
|
|
log_debug("[OMEMO][STORE] No device => no delete");
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
guint len = g_hash_table_size(device_store);
|
|
g_hash_table_remove_all(device_store);
|
|
return len;
|
|
}
|
|
|
|
int
|
|
load_pre_key(signal_buffer** record, uint32_t pre_key_id, void* user_data)
|
|
{
|
|
signal_buffer* original;
|
|
GHashTable* pre_key_store = (GHashTable*)user_data;
|
|
|
|
original = g_hash_table_lookup(pre_key_store, GINT_TO_POINTER(pre_key_id));
|
|
if (original == NULL) {
|
|
log_error("[OMEMO][STORE] SG_ERR_INVALID_KEY_ID");
|
|
return SG_ERR_INVALID_KEY_ID;
|
|
}
|
|
|
|
*record = signal_buffer_copy(original);
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
store_pre_key(uint32_t pre_key_id, uint8_t* record, size_t record_len,
|
|
void* user_data)
|
|
{
|
|
GHashTable* pre_key_store = (GHashTable*)user_data;
|
|
|
|
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
|
g_hash_table_insert(pre_key_store, GINT_TO_POINTER(pre_key_id), buffer);
|
|
|
|
/* Long term storage */
|
|
auto_gchar gchar* pre_key_id_str = g_strdup_printf("%d", pre_key_id);
|
|
auto_gchar gchar* record_b64 = g_base64_encode(record, record_len);
|
|
g_key_file_set_string(omemo_identity_keyfile(), OMEMO_STORE_GROUP_PREKEYS, pre_key_id_str, record_b64);
|
|
|
|
omemo_identity_keyfile_save();
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
contains_pre_key(uint32_t pre_key_id, void* user_data)
|
|
{
|
|
GHashTable* pre_key_store = (GHashTable*)user_data;
|
|
|
|
return g_hash_table_lookup(pre_key_store, GINT_TO_POINTER(pre_key_id)) != NULL;
|
|
}
|
|
|
|
int
|
|
remove_pre_key(uint32_t pre_key_id, void* user_data)
|
|
{
|
|
GHashTable* pre_key_store = (GHashTable*)user_data;
|
|
|
|
int ret = g_hash_table_remove(pre_key_store, GINT_TO_POINTER(pre_key_id));
|
|
|
|
/* Long term storage */
|
|
auto_gchar gchar* pre_key_id_str = g_strdup_printf("%d", pre_key_id);
|
|
g_key_file_remove_key(omemo_identity_keyfile(), OMEMO_STORE_GROUP_PREKEYS, pre_key_id_str, NULL);
|
|
|
|
omemo_identity_keyfile_save();
|
|
|
|
if (ret > 0) {
|
|
return SG_SUCCESS;
|
|
} else {
|
|
log_error("[OMEMO][STORE] SG_ERR_INVALID_KEY_ID");
|
|
return SG_ERR_INVALID_KEY_ID;
|
|
}
|
|
}
|
|
|
|
int
|
|
load_signed_pre_key(signal_buffer** record, uint32_t signed_pre_key_id,
|
|
void* user_data)
|
|
{
|
|
signal_buffer* original;
|
|
GHashTable* signed_pre_key_store = (GHashTable*)user_data;
|
|
|
|
original = g_hash_table_lookup(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id));
|
|
if (!original) {
|
|
log_error("[OMEMO][STORE] SG_ERR_INVALID_KEY_ID");
|
|
return SG_ERR_INVALID_KEY_ID;
|
|
}
|
|
|
|
*record = signal_buffer_copy(original);
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
store_signed_pre_key(uint32_t signed_pre_key_id, uint8_t* record,
|
|
size_t record_len, void* user_data)
|
|
{
|
|
GHashTable* signed_pre_key_store = (GHashTable*)user_data;
|
|
|
|
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
|
g_hash_table_insert(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id), buffer);
|
|
|
|
/* Long term storage */
|
|
auto_gchar gchar* signed_pre_key_id_str = g_strdup_printf("%d", signed_pre_key_id);
|
|
auto_gchar gchar* record_b64 = g_base64_encode(record, record_len);
|
|
g_key_file_set_string(omemo_identity_keyfile(), OMEMO_STORE_GROUP_SIGNED_PREKEYS, signed_pre_key_id_str, record_b64);
|
|
|
|
omemo_identity_keyfile_save();
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
contains_signed_pre_key(uint32_t signed_pre_key_id, void* user_data)
|
|
{
|
|
GHashTable* signed_pre_key_store = (GHashTable*)user_data;
|
|
|
|
return g_hash_table_lookup(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id)) != NULL;
|
|
}
|
|
|
|
int
|
|
remove_signed_pre_key(uint32_t signed_pre_key_id, void* user_data)
|
|
{
|
|
GHashTable* signed_pre_key_store = (GHashTable*)user_data;
|
|
|
|
int ret = g_hash_table_remove(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id));
|
|
|
|
/* Long term storage */
|
|
auto_gchar gchar* signed_pre_key_id_str = g_strdup_printf("%d", signed_pre_key_id);
|
|
g_key_file_remove_key(omemo_identity_keyfile(), OMEMO_STORE_GROUP_PREKEYS, signed_pre_key_id_str, NULL);
|
|
|
|
omemo_identity_keyfile_save();
|
|
|
|
return ret;
|
|
}
|
|
|
|
int
|
|
get_identity_key_pair(signal_buffer** public_data, signal_buffer** private_data,
|
|
void* user_data)
|
|
{
|
|
identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;
|
|
|
|
*public_data = signal_buffer_copy(identity_key_store->public);
|
|
*private_data = signal_buffer_copy(identity_key_store->private);
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
get_local_registration_id(void* user_data, uint32_t* registration_id)
|
|
{
|
|
identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;
|
|
|
|
*registration_id = identity_key_store->registration_id;
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
save_identity(const signal_protocol_address* address, uint8_t* key_data,
|
|
size_t key_len, void* user_data)
|
|
{
|
|
identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;
|
|
|
|
if (identity_key_store->recv) {
|
|
/* Do not trust identity automatically */
|
|
/* Instead we perform a real trust check */
|
|
identity_key_store->recv = false;
|
|
int trusted = is_trusted_identity(address, key_data, key_len, user_data);
|
|
identity_key_store->recv = true;
|
|
if (trusted == 0) {
|
|
log_debug("[OMEMO][STORE] trusted 0");
|
|
/* If not trusted we just don't save the identity */
|
|
return SG_SUCCESS;
|
|
}
|
|
}
|
|
|
|
signal_buffer* buffer = signal_buffer_create(key_data, key_len);
|
|
|
|
GHashTable* trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
|
|
if (!trusted) {
|
|
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
|
g_hash_table_insert(identity_key_store->trusted, strdup(address->name), trusted);
|
|
}
|
|
g_hash_table_insert(trusted, GINT_TO_POINTER(address->device_id), buffer);
|
|
|
|
/* Long term storage */
|
|
auto_gchar gchar* key_b64 = g_base64_encode(key_data, key_len);
|
|
auto_gchar gchar* device_id = g_strdup_printf("%d", address->device_id);
|
|
g_key_file_set_string(omemo_trust_keyfile(), address->name, device_id, key_b64);
|
|
|
|
omemo_trust_keyfile_save();
|
|
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
is_trusted_identity(const signal_protocol_address* address, uint8_t* key_data,
|
|
size_t key_len, void* user_data)
|
|
{
|
|
int ret;
|
|
identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;
|
|
log_debug("[OMEMO][STORE] Checking trust %s (%d)", address->name, address->device_id);
|
|
GHashTable* trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
|
|
if (!trusted) {
|
|
if (identity_key_store->recv) {
|
|
log_debug("[OMEMO][STORE] identity_key_store->recv");
|
|
return 1;
|
|
} else {
|
|
log_debug("[OMEMO][STORE] !identity_key_store->recv");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
signal_buffer* buffer = signal_buffer_create(key_data, key_len);
|
|
signal_buffer* original = g_hash_table_lookup(trusted, GINT_TO_POINTER(address->device_id));
|
|
|
|
if (!original) {
|
|
log_debug("[OMEMO][STORE] original not found %s (%d)", address->name, address->device_id);
|
|
}
|
|
ret = original != NULL && signal_buffer_compare(buffer, original) == 0;
|
|
|
|
signal_buffer_free(buffer);
|
|
|
|
if (identity_key_store->recv) {
|
|
log_debug("[OMEMO][STORE] 1 identity_key_store->recv");
|
|
return 1;
|
|
} else {
|
|
log_debug("[OMEMO][STORE] Checking trust %s (%d): %d", address->name, address->device_id, ret);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
int
|
|
store_sender_key(const signal_protocol_sender_key_name* sender_key_name,
|
|
uint8_t* record, size_t record_len, uint8_t* user_record,
|
|
size_t user_record_len, void* user_data)
|
|
{
|
|
return SG_SUCCESS;
|
|
}
|
|
|
|
int
|
|
load_sender_key(signal_buffer** record, signal_buffer** user_record,
|
|
const signal_protocol_sender_key_name* sender_key_name,
|
|
void* user_data)
|
|
{
|
|
return SG_SUCCESS;
|
|
}
|