about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--src/command/cmd_defs.c11
-rw-r--r--src/command/cmd_funcs.c13
-rw-r--r--src/command/cmd_funcs.h2
-rw-r--r--src/omemo/omemo.c24
-rw-r--r--src/omemo/omemo.h3
-rw-r--r--src/profanity.c7
-rw-r--r--src/ui/win_types.h1
-rw-r--r--src/ui/window.c1
9 files changed, 47 insertions, 19 deletions
diff --git a/configure.ac b/configure.ac
index 5ba70464..e886510e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -270,7 +270,7 @@ AM_CONDITIONAL([BUILD_OMEMO], [false])
 if test "x$enable_omemo" != xno; then
     AC_CHECK_LIB([signal-protocol-c], [signal_context_create],
         [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"],
         [AS_IF([test "x$enable_omemo" = xyes],
             [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],
         [AM_CONDITIONAL([BUILD_OMEMO], [true])
-         AC_DEFINE([HAVE_LIBSIGNAL_PROTOCOL], [1], [Have omemo]),
+         AC_DEFINE([HAVE_OMEMO], [1], [Have omemo]),
          LIBS="-lsodium $LIBS"],
         [AS_IF([test "x$enable_omemo" = xyes],
             [AC_MSG_ERROR([libsodium is required for omemo support])],
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 23ab2ebf..af30db34 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2333,19 +2333,22 @@ static struct cmd_t command_defs[] =
     { "/omemo",
         parse_args, 1, 3, NULL,
         CMD_SUBFUNCS(
-            { "init", cmd_omemo_init })
+            { "gen", cmd_omemo_gen })
         CMD_NOMAINFUNC
         CMD_TAGS(
             CMD_TAG_CHAT,
             CMD_TAG_UI)
         CMD_SYN(
-            "/omemo init")
+            "/omemo gen",
+            "/omemo start [<contact>]")
         CMD_DESC(
             "Omemo commands to manage keys, and perform encryption during chat sessions.")
         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(
-            "/omemo init")
+            "/omemo gen",
+            "/omemo start buddy@buddychat.org")
     },
 };
 
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 97ce2025..08aa88df 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -85,7 +85,7 @@
 #include "pgp/gpg.h"
 #endif
 
-#ifdef HAVE_LIBSIGNAL_PROTOCOL
+#ifdef HAVE_OMEMO
 #include "omemo/omemo.h"
 #endif
 
@@ -7878,20 +7878,19 @@ _cmd_set_boolean_preference(gchar *arg, const char *const command,
 }
 
 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) {
-        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;
     }
 
     ProfAccount *account = accounts_get_account(session_get_account_name());
-    omemo_init(account);
-    cons_show("Initialized omemo");
+    omemo_generate_crypto_materials(account);
     return TRUE;
 #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;
 #endif
 }
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index fb81721d..650c9eaf 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -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_omemo_init(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_omemo_gen(ProfWin *window, const char *const command, gchar **args);
 
 #endif
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index 96e07d1c..1b2998b0 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -8,6 +8,7 @@
 
 static void lock(void *user_data);
 static void unlock(void *user_data);
+static void omemo_load_crypto_materials(ProfAccount *account);
 
 struct omemo_context_t {
     pthread_mutexattr_t attr;
@@ -15,8 +16,9 @@ struct omemo_context_t {
 };
 
 void
-omemo_init(ProfAccount *account)
+omemo_init(void)
 {
+    log_info("Initialising OMEMO");
     signal_context *signal_ctx;
     omemo_context *ctx = malloc(sizeof(omemo_context));
     signal_crypto_provider crypto_provider = {
@@ -35,7 +37,7 @@ omemo_init(ProfAccount *account)
     };
 
     if (omemo_crypto_init() != 0) {
-        cons_show("Error initializing Omemo crypto");
+        cons_show("Error initializing OMEMO crypto");
     }
 
     pthread_mutexattr_init(&ctx->attr);
@@ -43,18 +45,32 @@ omemo_init(ProfAccount *account)
     pthread_mutex_init(&ctx->lock, &ctx->attr);
 
     if (signal_context_create(&signal_ctx, ctx) != 0) {
-        cons_show("Error initializing Omemo context");
+        cons_show("Error initializing OMEMO context");
         return;
     }
 
     if (signal_context_set_crypto_provider(signal_ctx, &crypto_provider) != 0) {
-        cons_show("Error initializing Omemo crypto");
+        cons_show("Error initializing OMEMO crypto");
         return;
     }
 
     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(&registration_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
 lock(void *user_data)
 {
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index d34b90bf..825529b1 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -2,4 +2,5 @@
 
 typedef struct omemo_context_t omemo_context;
 
-void omemo_init(ProfAccount *account);
+void omemo_init(void);
+void omemo_generate_crypto_materials(ProfAccount *account);
diff --git a/src/profanity.c b/src/profanity.c
index 1d4a2c35..f21f02c0 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -80,6 +80,10 @@
 #include "pgp/gpg.h"
 #endif
 
+#ifdef HAVE_OMEMO
+#include "omemo/omemo.h"
+#endif
+
 static void _init(char *log_level);
 static void _shutdown(void);
 static void _connect_default(const char * const account);
@@ -197,6 +201,9 @@ _init(char *log_level)
 #ifdef HAVE_LIBGPGME
     p_gpg_init();
 #endif
+#ifdef HAVE_OMEMO
+    omemo_init();
+#endif
     atexit(_shutdown);
     plugins_init();
 #ifdef HAVE_GTK
diff --git a/src/ui/win_types.h b/src/ui/win_types.h
index 92618a36..6fe2811a 100644
--- a/src/ui/win_types.h
+++ b/src/ui/win_types.h
@@ -152,6 +152,7 @@ typedef struct prof_chat_win_t {
     gboolean otr_is_trusted;
     gboolean pgp_send;
     gboolean pgp_recv;
+    gboolean is_omemo;
     char *resource_override;
     gboolean history_shown;
     unsigned long memcheck;
diff --git a/src/ui/window.c b/src/ui/window.c
index cc2c2062..5693e35f 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -143,6 +143,7 @@ win_create_chat(const char *const barejid)
     new_win->otr_is_trusted = FALSE;
     new_win->pgp_recv = FALSE;
     new_win->pgp_send = FALSE;
+    new_win->is_omemo = FALSE;
     new_win->history_shown = FALSE;
     new_win->unread = 0;
     new_win->state = chat_state_new();