mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-22 19:45:54 -04:00
Move OMEMO initialization to profanity intialization
Also store identity keys into account
This commit is contained in:
parent
519cf295f3
commit
2602cbf785
@ -270,7 +270,7 @@ AM_CONDITIONAL([BUILD_OMEMO], [false])
|
|||||||
if test "x$enable_omemo" != xno; then
|
if test "x$enable_omemo" != xno; then
|
||||||
AC_CHECK_LIB([signal-protocol-c], [signal_context_create],
|
AC_CHECK_LIB([signal-protocol-c], [signal_context_create],
|
||||||
[AM_CONDITIONAL([BUILD_OMEMO], [true])
|
[AM_CONDITIONAL([BUILD_OMEMO], [true])
|
||||||
AC_DEFINE([HAVE_LIBSIGNAL_PROTOCOL], [1], [Have omemo]),
|
AC_DEFINE([HAVE_OMEMO], [1], [Have omemo]),
|
||||||
LIBS="-lsignal-protocol-c $LIBS"],
|
LIBS="-lsignal-protocol-c $LIBS"],
|
||||||
[AS_IF([test "x$enable_omemo" = xyes],
|
[AS_IF([test "x$enable_omemo" = xyes],
|
||||||
[AC_MSG_ERROR([libsignal-protocol-c is required for omemo support])],
|
[AC_MSG_ERROR([libsignal-protocol-c is required for omemo support])],
|
||||||
@ -278,7 +278,7 @@ if test "x$enable_omemo" != xno; then
|
|||||||
|
|
||||||
AC_CHECK_LIB([sodium], [sodium_init],
|
AC_CHECK_LIB([sodium], [sodium_init],
|
||||||
[AM_CONDITIONAL([BUILD_OMEMO], [true])
|
[AM_CONDITIONAL([BUILD_OMEMO], [true])
|
||||||
AC_DEFINE([HAVE_LIBSIGNAL_PROTOCOL], [1], [Have omemo]),
|
AC_DEFINE([HAVE_OMEMO], [1], [Have omemo]),
|
||||||
LIBS="-lsodium $LIBS"],
|
LIBS="-lsodium $LIBS"],
|
||||||
[AS_IF([test "x$enable_omemo" = xyes],
|
[AS_IF([test "x$enable_omemo" = xyes],
|
||||||
[AC_MSG_ERROR([libsodium is required for omemo support])],
|
[AC_MSG_ERROR([libsodium is required for omemo support])],
|
||||||
|
@ -2333,19 +2333,22 @@ static struct cmd_t command_defs[] =
|
|||||||
{ "/omemo",
|
{ "/omemo",
|
||||||
parse_args, 1, 3, NULL,
|
parse_args, 1, 3, NULL,
|
||||||
CMD_SUBFUNCS(
|
CMD_SUBFUNCS(
|
||||||
{ "init", cmd_omemo_init })
|
{ "gen", cmd_omemo_gen })
|
||||||
CMD_NOMAINFUNC
|
CMD_NOMAINFUNC
|
||||||
CMD_TAGS(
|
CMD_TAGS(
|
||||||
CMD_TAG_CHAT,
|
CMD_TAG_CHAT,
|
||||||
CMD_TAG_UI)
|
CMD_TAG_UI)
|
||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/omemo init")
|
"/omemo gen",
|
||||||
|
"/omemo start [<contact>]")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"Omemo commands to manage keys, and perform encryption during chat sessions.")
|
"Omemo commands to manage keys, and perform encryption during chat sessions.")
|
||||||
CMD_ARGS(
|
CMD_ARGS(
|
||||||
{ "init", "Initialize omemo" })
|
{ "gen", "Generate OMEMO crytographic materials for current account." },
|
||||||
|
{ "start [<contact>]", "Start an OMEMO session with contact, or current recipient if omitted." })
|
||||||
CMD_EXAMPLES(
|
CMD_EXAMPLES(
|
||||||
"/omemo init")
|
"/omemo gen",
|
||||||
|
"/omemo start buddy@buddychat.org")
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
#include "pgp/gpg.h"
|
#include "pgp/gpg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBSIGNAL_PROTOCOL
|
#ifdef HAVE_OMEMO
|
||||||
#include "omemo/omemo.h"
|
#include "omemo/omemo.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -7878,20 +7878,19 @@ _cmd_set_boolean_preference(gchar *arg, const char *const command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cmd_omemo_init(ProfWin *window, const char *const command, gchar **args)
|
cmd_omemo_gen(ProfWin *window, const char *const command, gchar **args)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBSIGNAL_PROTOCOL
|
#ifdef HAVE_OMEMO
|
||||||
if (connection_get_status() != JABBER_CONNECTED) {
|
if (connection_get_status() != JABBER_CONNECTED) {
|
||||||
cons_show("You must be connected with an account to initialize omemo");
|
cons_show("You must be connected with an account to initialize OMEMO");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfAccount *account = accounts_get_account(session_get_account_name());
|
ProfAccount *account = accounts_get_account(session_get_account_name());
|
||||||
omemo_init(account);
|
omemo_generate_crypto_materials(account);
|
||||||
cons_show("Initialized omemo");
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
cons_show("This version of Profanity has not been built with Omemo support enabled");
|
cons_show("This version of Profanity has not been built with OMEMO support enabled");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -214,6 +214,6 @@ gboolean cmd_wins_swap(ProfWin *window, const char *const command, gchar **args)
|
|||||||
|
|
||||||
gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);
|
gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);
|
||||||
|
|
||||||
gboolean cmd_omemo_init(ProfWin *window, const char *const command, gchar **args);
|
gboolean cmd_omemo_gen(ProfWin *window, const char *const command, gchar **args);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
static void lock(void *user_data);
|
static void lock(void *user_data);
|
||||||
static void unlock(void *user_data);
|
static void unlock(void *user_data);
|
||||||
|
static void omemo_load_crypto_materials(ProfAccount *account);
|
||||||
|
|
||||||
struct omemo_context_t {
|
struct omemo_context_t {
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
@ -15,8 +16,9 @@ struct omemo_context_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
omemo_init(ProfAccount *account)
|
omemo_init(void)
|
||||||
{
|
{
|
||||||
|
log_info("Initialising OMEMO");
|
||||||
signal_context *signal_ctx;
|
signal_context *signal_ctx;
|
||||||
omemo_context *ctx = malloc(sizeof(omemo_context));
|
omemo_context *ctx = malloc(sizeof(omemo_context));
|
||||||
signal_crypto_provider crypto_provider = {
|
signal_crypto_provider crypto_provider = {
|
||||||
@ -35,7 +37,7 @@ omemo_init(ProfAccount *account)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (omemo_crypto_init() != 0) {
|
if (omemo_crypto_init() != 0) {
|
||||||
cons_show("Error initializing Omemo crypto");
|
cons_show("Error initializing OMEMO crypto");
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutexattr_init(&ctx->attr);
|
pthread_mutexattr_init(&ctx->attr);
|
||||||
@ -43,18 +45,32 @@ omemo_init(ProfAccount *account)
|
|||||||
pthread_mutex_init(&ctx->lock, &ctx->attr);
|
pthread_mutex_init(&ctx->lock, &ctx->attr);
|
||||||
|
|
||||||
if (signal_context_create(&signal_ctx, ctx) != 0) {
|
if (signal_context_create(&signal_ctx, ctx) != 0) {
|
||||||
cons_show("Error initializing Omemo context");
|
cons_show("Error initializing OMEMO context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signal_context_set_crypto_provider(signal_ctx, &crypto_provider) != 0) {
|
if (signal_context_set_crypto_provider(signal_ctx, &crypto_provider) != 0) {
|
||||||
cons_show("Error initializing Omemo crypto");
|
cons_show("Error initializing OMEMO crypto");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal_context_set_locking_functions(signal_ctx, lock, unlock);
|
signal_context_set_locking_functions(signal_ctx, lock, unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
omemo_generate_crypto_materials(ProfAccount *account)
|
||||||
|
{
|
||||||
|
ratchet_identity_key_pair *identity_key_pair;
|
||||||
|
uint32_t registration_id;
|
||||||
|
signal_protocol_key_helper_pre_key_list_node *pre_keys_head;
|
||||||
|
session_signed_pre_key *signed_pre_key;
|
||||||
|
|
||||||
|
signal_protocol_key_helper_generate_identity_key_pair(&identity_key_pair, global_context);
|
||||||
|
signal_protocol_key_helper_generate_registration_id(®istration_id, 0, global_context);
|
||||||
|
signal_protocol_key_helper_generate_pre_keys(&pre_keys_head, start_id, 100, global_context);
|
||||||
|
signal_protocol_key_helper_generate_signed_pre_key(&signed_pre_key, identity_key_pair, 5, timestamp, global_context);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lock(void *user_data)
|
lock(void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
typedef struct omemo_context_t omemo_context;
|
typedef struct omemo_context_t omemo_context;
|
||||||
|
|
||||||
void omemo_init(ProfAccount *account);
|
void omemo_init(void);
|
||||||
|
void omemo_generate_crypto_materials(ProfAccount *account);
|
||||||
|
@ -80,6 +80,10 @@
|
|||||||
#include "pgp/gpg.h"
|
#include "pgp/gpg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_OMEMO
|
||||||
|
#include "omemo/omemo.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void _init(char *log_level);
|
static void _init(char *log_level);
|
||||||
static void _shutdown(void);
|
static void _shutdown(void);
|
||||||
static void _connect_default(const char * const account);
|
static void _connect_default(const char * const account);
|
||||||
@ -196,6 +200,9 @@ _init(char *log_level)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBGPGME
|
#ifdef HAVE_LIBGPGME
|
||||||
p_gpg_init();
|
p_gpg_init();
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_OMEMO
|
||||||
|
omemo_init();
|
||||||
#endif
|
#endif
|
||||||
atexit(_shutdown);
|
atexit(_shutdown);
|
||||||
plugins_init();
|
plugins_init();
|
||||||
|
@ -152,6 +152,7 @@ typedef struct prof_chat_win_t {
|
|||||||
gboolean otr_is_trusted;
|
gboolean otr_is_trusted;
|
||||||
gboolean pgp_send;
|
gboolean pgp_send;
|
||||||
gboolean pgp_recv;
|
gboolean pgp_recv;
|
||||||
|
gboolean is_omemo;
|
||||||
char *resource_override;
|
char *resource_override;
|
||||||
gboolean history_shown;
|
gboolean history_shown;
|
||||||
unsigned long memcheck;
|
unsigned long memcheck;
|
||||||
|
@ -143,6 +143,7 @@ win_create_chat(const char *const barejid)
|
|||||||
new_win->otr_is_trusted = FALSE;
|
new_win->otr_is_trusted = FALSE;
|
||||||
new_win->pgp_recv = FALSE;
|
new_win->pgp_recv = FALSE;
|
||||||
new_win->pgp_send = FALSE;
|
new_win->pgp_send = FALSE;
|
||||||
|
new_win->is_omemo = FALSE;
|
||||||
new_win->history_shown = FALSE;
|
new_win->history_shown = FALSE;
|
||||||
new_win->unread = 0;
|
new_win->unread = 0;
|
||||||
new_win->state = chat_state_new();
|
new_win->state = chat_state_new();
|
||||||
|
Loading…
Reference in New Issue
Block a user