about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_ac.c14
-rw-r--r--src/command/cmd_defs.c5
-rw-r--r--src/command/cmd_funcs.c39
-rw-r--r--src/command/cmd_funcs.h1
-rw-r--r--src/config/account.c15
-rw-r--r--src/config/account.h6
-rw-r--r--src/config/accounts.c67
-rw-r--r--src/config/accounts.h2
-rw-r--r--src/config/preferences.c5
-rw-r--r--src/config/preferences.h1
-rw-r--r--src/omemo/omemo.c77
-rw-r--r--src/omemo/omemo.h8
-rw-r--r--src/ui/chatwin.c10
-rw-r--r--src/ui/console.c4
-rw-r--r--src/ui/core.c2
-rw-r--r--src/ui/mucwin.c19
-rw-r--r--src/ui/ui.h1
17 files changed, 253 insertions, 23 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 0cc28bb3..a2d73671 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -164,6 +164,7 @@ static Autocomplete otr_log_ac;
 static Autocomplete otr_policy_ac;
 static Autocomplete omemo_ac;
 static Autocomplete omemo_log_ac;
+static Autocomplete omemo_policy_ac;
 static Autocomplete connect_property_ac;
 static Autocomplete tls_property_ac;
 static Autocomplete alias_ac;
@@ -591,12 +592,18 @@ cmd_ac_init(void)
     autocomplete_add(omemo_ac, "untrust");
     autocomplete_add(omemo_ac, "fingerprint");
     autocomplete_add(omemo_ac, "clear_device_list");
+    autocomplete_add(omemo_ac, "policy");
 
     omemo_log_ac = autocomplete_new();
     autocomplete_add(omemo_log_ac, "on");
     autocomplete_add(omemo_log_ac, "off");
     autocomplete_add(omemo_log_ac, "redact");
 
+    omemo_policy_ac = autocomplete_new();
+    autocomplete_add(omemo_policy_ac, "manual");
+    autocomplete_add(omemo_policy_ac, "automatic");
+    autocomplete_add(omemo_policy_ac, "always");
+
     connect_property_ac = autocomplete_new();
     autocomplete_add(connect_property_ac, "server");
     autocomplete_add(connect_property_ac, "port");
@@ -1080,6 +1087,7 @@ cmd_ac_reset(ProfWin *window)
     autocomplete_reset(otr_policy_ac);
     autocomplete_reset(omemo_ac);
     autocomplete_reset(omemo_log_ac);
+    autocomplete_reset(omemo_policy_ac);
     autocomplete_reset(connect_property_ac);
     autocomplete_reset(tls_property_ac);
     autocomplete_reset(alias_ac);
@@ -1209,6 +1217,7 @@ cmd_ac_uninit(void)
     autocomplete_free(otr_policy_ac);
     autocomplete_free(omemo_ac);
     autocomplete_free(omemo_log_ac);
+    autocomplete_free(omemo_policy_ac);
     autocomplete_free(connect_property_ac);
     autocomplete_free(tls_property_ac);
     autocomplete_free(alias_ac);
@@ -2191,6 +2200,11 @@ _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous)
         return found;
     }
 
+    found = autocomplete_param_with_ac(input, "/omemo policy", omemo_policy_ac, TRUE, previous);
+    if (found) {
+        return found;
+    }
+
     found = autocomplete_param_with_ac(input, "/omemo", omemo_ac, TRUE, previous);
     if (found) {
         return found;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index ee86aaba..358c8d40 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2342,6 +2342,7 @@ static struct cmd_t command_defs[] =
             { "untrust", cmd_omemo_untrust },
             { "fingerprint", cmd_omemo_fingerprint },
             { "char", cmd_omemo_char },
+            { "policy", cmd_omemo_policy },
             { "clear_device_list", cmd_omemo_clear_device_list })
         CMD_NOMAINFUNC
         CMD_TAGS(
@@ -2355,6 +2356,7 @@ static struct cmd_t command_defs[] =
             "/omemo end",
             "/omemo fingerprint [<contact>]",
             "/omemo char <char>",
+            "/omemo policy manual|automatic|always",
             "/omemo clear_device_list")
         CMD_DESC(
             "OMEMO commands to manage keys, and perform encryption during chat sessions.")
@@ -2366,6 +2368,9 @@ static struct cmd_t command_defs[] =
             { "log redact",              "Log OMEMO encrypted messages, but replace the contents with [redacted]. This is the default." },
             { "fingerprint [<contact>]", "Show contact fingerprints, or current recipient if omitted." },
             { "char <char>",             "Set the character to be displayed next to OMEMO encrypted messages." },
+            { "policy manual",           "Set the global OMEMO policy to manual, OMEMO sessions must be started manually." },
+            { "policy automatic",        "Set the global OMEMO policy to opportunistic, an OMEMO session will be attempted upon starting a conversation." },
+            { "policy always",           "Set the global OMEMO policy to always, an error will be displayed if an OMEMO session cannot be initiated upon starting a conversation." },
             { "clear_device_list",       "Clear your own device list on server side. Each client will reannounce itself when connected back."})
         CMD_EXAMPLES(
             "/omemo gen",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 3bba5cb5..abd83492 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -2152,7 +2152,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args)
 
 #ifdef HAVE_OMEMO
 #ifndef HAVE_LIBOTR
-        if (omemo_is_trusted_jid(barejid)) {
+        if (omemo_automatic_start(barejid)) {
             omemo_start_session(barejid);
             chatwin->is_omemo = TRUE;
         }
@@ -2167,10 +2167,10 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args)
 
 #ifdef HAVE_OMEMO
 #ifdef HAVE_LIBOTR
-        if (omemo_is_trusted_jid(barejid) && otr_is_secure(barejid)) {
+        if (omemo_automatic_start(barejid) && otr_is_secure(barejid)) {
             win_println(window, THEME_DEFAULT, '!', "Chat could be either OMEMO or OTR encrypted. Use '/omemo start %s' or '/otr start %s' to start a session.", usr, usr);
             return TRUE;
-        } else if (omemo_is_trusted_jid(barejid)) {
+        } else if (omemo_automatic_start(barejid)) {
             omemo_start_session(barejid);
             chatwin->is_omemo = TRUE;
         }
@@ -8005,6 +8005,7 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
             return TRUE;
         }
 
+        accounts_add_omemo_state(session_get_account_name(), barejid, TRUE);
         omemo_start_session(barejid);
         chatwin->is_omemo = TRUE;
     } else {
@@ -8026,6 +8027,7 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
                 return TRUE;
             }
 
+            accounts_add_omemo_state(session_get_account_name(), chatwin->barejid, TRUE);
             omemo_start_session(chatwin->barejid);
             chatwin->is_omemo = TRUE;
         } else if (window->type == WIN_MUC) {
@@ -8033,6 +8035,7 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
             assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
 
             if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
+                accounts_add_omemo_state(session_get_account_name(), mucwin->roomjid, TRUE);
                 omemo_start_muc_sessions(mucwin->roomjid);
                 mucwin->is_omemo = TRUE;
             } else {
@@ -8119,6 +8122,7 @@ cmd_omemo_end(ProfWin *window, const char *const command, gchar **args)
         }
 
         chatwin->is_omemo = FALSE;
+        accounts_add_omemo_state(session_get_account_name(), chatwin->barejid, FALSE);
     } else if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = (ProfMucWin*)window;
         assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
@@ -8129,6 +8133,7 @@ cmd_omemo_end(ProfWin *window, const char *const command, gchar **args)
         }
 
         mucwin->is_omemo = FALSE;
+        accounts_add_omemo_state(session_get_account_name(), mucwin->roomjid, FALSE);
     } else {
         win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session.");
         return TRUE;
@@ -8366,3 +8371,31 @@ cmd_omemo_clear_device_list(ProfWin *window, const char *const command, gchar **
     return TRUE;
 #endif
 }
+
+gboolean
+cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args)
+{
+#ifdef HAVE_OMEMO
+    if (args[1] == NULL) {
+        char *policy = prefs_get_string(PREF_OMEMO_POLICY);
+        cons_show("OMEMO policy is now set to: %s", policy);
+        prefs_free_string(policy);
+        return TRUE;
+    }
+
+    char *choice = args[1];
+    if ((g_strcmp0(choice, "manual") != 0) &&
+            (g_strcmp0(choice, "automatic") != 0) &&
+            (g_strcmp0(choice, "always") != 0)) {
+        cons_show("OMEMO policy can be set to: manual, automatic or always.");
+        return TRUE;
+    }
+
+    prefs_set_string(PREF_OMEMO_POLICY, choice);
+    cons_show("OMEMO policy is now set to: %s", choice);
+    return TRUE;
+#else
+    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 249b50fe..8f8d60a9 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -222,6 +222,7 @@ gboolean cmd_omemo_end(ProfWin *window, const char *const command, gchar **args)
 gboolean cmd_omemo_fingerprint(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_trust(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_untrust(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_clear_device_list(ProfWin *window, const char *const command, gchar **args);
 
 #endif
diff --git a/src/config/account.c b/src/config/account.c
index 93ba5078..0c23c585 100644
--- a/src/config/account.c
+++ b/src/config/account.c
@@ -52,7 +52,8 @@ account_new(const gchar *const name, const gchar *const jid,
     int priority_away, int priority_xa, int priority_dnd,
     const gchar *const muc_service, const gchar *const muc_nick,
     const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
-    GList *otr_always, const gchar *const pgp_keyid, const char *const startscript,
+    GList *otr_always,  const gchar *const omemo_policy, GList *omemo_enabled,
+    GList *omemo_disabled, const gchar *const pgp_keyid, const char *const startscript,
     const char *const theme, gchar *tls_policy)
 {
     ProfAccount *new_account = malloc(sizeof(ProfAccount));
@@ -139,6 +140,15 @@ account_new(const gchar *const name, const gchar *const jid,
     new_account->otr_opportunistic = otr_opportunistic;
     new_account->otr_always = otr_always;
 
+    if (omemo_policy) {
+        new_account->omemo_policy = strdup(omemo_policy);
+    } else {
+        new_account->omemo_policy = NULL;
+    }
+
+    new_account->omemo_enabled = omemo_enabled;
+    new_account->omemo_disabled = omemo_disabled;
+
     if (pgp_keyid != NULL) {
         new_account->pgp_keyid = strdup(pgp_keyid);
     } else {
@@ -232,6 +242,7 @@ account_free(ProfAccount *account)
     free(account->muc_service);
     free(account->muc_nick);
     free(account->otr_policy);
+    free(account->omemo_policy);
     free(account->pgp_keyid);
     free(account->startscript);
     free(account->theme);
@@ -239,6 +250,8 @@ account_free(ProfAccount *account)
     g_list_free_full(account->otr_manual, g_free);
     g_list_free_full(account->otr_opportunistic, g_free);
     g_list_free_full(account->otr_always, g_free);
+    g_list_free_full(account->omemo_enabled, g_free);
+    g_list_free_full(account->omemo_disabled, g_free);
     free(account);
 }
 
diff --git a/src/config/account.h b/src/config/account.h
index 68264c47..17b57a46 100644
--- a/src/config/account.h
+++ b/src/config/account.h
@@ -59,6 +59,9 @@ typedef struct prof_account_t {
     GList *otr_manual;
     GList *otr_opportunistic;
     GList *otr_always;
+    gchar *omemo_policy;
+    GList *omemo_enabled;
+    GList *omemo_disabled;
     gchar *pgp_keyid;
     gchar *startscript;
     gchar *theme;
@@ -72,7 +75,8 @@ ProfAccount* account_new(const gchar *const name, const gchar *const jid,
     int priority_away, int priority_xa, int priority_dnd,
     const gchar *const muc_service, const gchar *const muc_nick,
     const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
-    GList *otr_always, const gchar *const pgp_keyid, const char *const startscript,
+    GList *otr_always, const gchar *const omemo_policy, GList *omemo_enabled,
+    GList *omemo_disabled, const gchar *const pgp_keyid, const char *const startscript,
     const char *const theme, gchar *tls_policy);
 char* account_create_connect_jid(ProfAccount *account);
 gboolean account_eval_password(ProfAccount *account);
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 1c6441db..fa8b9c8f 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -275,6 +275,31 @@ accounts_get_account(const char *const name)
             g_strfreev(always);
         }
 
+        gchar *omemo_policy = NULL;
+        if (g_key_file_has_key(accounts, name, "omemo.policy", NULL)) {
+            omemo_policy = g_key_file_get_string(accounts, name, "omemo.policy", NULL);
+        }
+
+        GList *omemo_enabled = NULL;
+        gchar **enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
+        if (enabled_list) {
+            int i = 0;
+            for (i = 0; i < length; i++) {
+                omemo_enabled = g_list_append(omemo_enabled, strdup(enabled_list[i]));
+            }
+            g_strfreev(enabled_list);
+        }
+
+        GList *omemo_disabled = NULL;
+        gchar **disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
+        if (disabled_list) {
+            int i = 0;
+            for (i = 0; i < length; i++) {
+                omemo_disabled = g_list_append(omemo_disabled, strdup(disabled_list[i]));
+            }
+            g_strfreev(disabled_list);
+        }
+
         gchar *pgp_keyid = NULL;
         if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) {
             pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL);
@@ -304,7 +329,8 @@ accounts_get_account(const char *const name)
             server, port, resource, last_presence, login_presence,
             priority_online, priority_chat, priority_away, priority_xa,
             priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
-            otr_opportunistic, otr_always, pgp_keyid, startscript, theme, tls_policy);
+            otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
+            omemo_disabled,  pgp_keyid, startscript, theme, tls_policy);
 
         g_free(jid);
         g_free(password);
@@ -316,6 +342,7 @@ accounts_get_account(const char *const name)
         g_free(muc_service);
         g_free(muc_nick);
         g_free(otr_policy);
+        g_free(omemo_policy);
         g_free(pgp_keyid);
         g_free(startscript);
         g_free(theme);
@@ -385,6 +412,9 @@ accounts_rename(const char *const account_name, const char *const new_name)
         "otr.manual",
         "otr.opportunistic",
         "otr.always",
+        "omemo.policy",
+        "omemo.enabled",
+        "omemo.disabled",
         "pgp.keyid",
         "last.activity",
         "script.start",
@@ -634,6 +664,32 @@ accounts_add_otr_policy(const char *const account_name, const char *const contac
 }
 
 void
+accounts_add_omemo_state(const char *const account_name, const char *const contact_jid, gboolean enabled)
+{
+    if (accounts_account_exists(account_name)) {
+        if (enabled) {
+            conf_string_list_add(accounts, account_name, "omemo.enabled", contact_jid);
+            conf_string_list_remove(accounts, account_name, "omemo.disabled", contact_jid);
+        } else {
+            conf_string_list_add(accounts, account_name, "omemo.disabled", contact_jid);
+            conf_string_list_remove(accounts, account_name, "omemo.enabled", contact_jid);
+        }
+
+        _save_accounts();
+    }
+}
+
+void
+accounts_clear_omemo_state(const char *const account_name, const char *const contact_jid)
+{
+    if (accounts_account_exists(account_name)) {
+        conf_string_list_remove(accounts, account_name, "omemo.enabled", contact_jid);
+        conf_string_list_remove(accounts, account_name, "omemo.disabled", contact_jid);
+        _save_accounts();
+    }
+}
+
+void
 accounts_set_muc_service(const char *const account_name, const char *const value)
 {
     if (accounts_account_exists(account_name)) {
@@ -661,6 +717,15 @@ accounts_set_otr_policy(const char *const account_name, const char *const value)
 }
 
 void
+accounts_set_omemo_policy(const char *const account_name, const char *const value)
+{
+    if (accounts_account_exists(account_name)) {
+        g_key_file_set_string(accounts, account_name, "omemo.policy", value);
+        _save_accounts();
+    }
+}
+
+void
 accounts_set_tls_policy(const char *const account_name, const char *const value)
 {
     if (accounts_account_exists(account_name)) {
diff --git a/src/config/accounts.h b/src/config/accounts.h
index d41fb53e..c1e7a5ae 100644
--- a/src/config/accounts.h
+++ b/src/config/accounts.h
@@ -96,5 +96,7 @@ void accounts_clear_theme(const char *const account_name);
 void accounts_clear_muc(const char *const account_name);
 void accounts_clear_resource(const char *const account_name);
 void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy);
+void accounts_add_omemo_state(const char *const account_name, const char *const contact_jid, gboolean enabled);
+void accounts_clear_omemo_state(const char *const account_name, const char *const contact_jid);
 
 #endif
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 65e7a64d..19d54304 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -1686,6 +1686,7 @@ _get_group(preference_t pref)
         case PREF_PLUGINS_SOURCEPATH:
             return PREF_GROUP_PLUGINS;
         case PREF_OMEMO_LOG:
+        case PREF_OMEMO_POLICY:
             return PREF_GROUP_OMEMO;
         default:
             return NULL;
@@ -1903,6 +1904,8 @@ _get_key(preference_t pref)
             return "statusbar.room";
         case PREF_OMEMO_LOG:
             return "log";
+        case PREF_OMEMO_POLICY:
+            return "policy";
         default:
             return NULL;
     }
@@ -2023,6 +2026,8 @@ _get_default_string(preference_t pref)
             return "room";
         case PREF_OMEMO_LOG:
             return "redact";
+        case PREF_OMEMO_POLICY:
+            return "automatic";
         default:
             return NULL;
     }
diff --git a/src/config/preferences.h b/src/config/preferences.h
index a4d82967..614c3f0f 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -149,6 +149,7 @@ typedef enum {
     PREF_STATUSBAR_CHAT,
     PREF_STATUSBAR_ROOM,
     PREF_OMEMO_LOG,
+    PREF_OMEMO_POLICY,
 } preference_t;
 
 typedef struct prof_alias_t {
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index b85029ee..06174da5 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -14,6 +14,7 @@
 
 #include "config/account.h"
 #include "config/files.h"
+#include "config/preferences.h"
 #include "log.h"
 #include "omemo/crypto.h"
 #include "omemo/omemo.h"
@@ -922,21 +923,6 @@ omemo_known_device_identities(const char *const jid)
 }
 
 gboolean
-omemo_is_trusted_jid(const char *const jid)
-{
-    GHashTable *trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, jid);
-    if (!trusted) {
-        return FALSE;
-    }
-
-    if (g_hash_table_size(trusted) > 0) {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-gboolean
 omemo_is_trusted_identity(const char *const jid, const char *const fingerprint)
 {
     GHashTable *known_identities = g_hash_table_lookup(omemo_ctx.known_devices, jid);
@@ -1197,6 +1183,67 @@ omemo_fingerprint_autocomplete_reset(void)
     autocomplete_reset(omemo_ctx.fingerprint_ac);
 }
 
+gboolean
+omemo_automatic_start(const char *const recipient)
+{
+    gboolean result;
+    char *account_name = session_get_account_name();
+    ProfAccount *account = accounts_get_account(account_name);
+    prof_omemopolicy_t policy;
+
+    if (account->omemo_policy) {
+        // check default account setting
+        if (g_strcmp0(account->omemo_policy, "manual") == 0) {
+            policy = PROF_OMEMOPOLICY_MANUAL;
+        }
+        if (g_strcmp0(account->omemo_policy, "opportunistic") == 0) {
+            policy = PROF_OMEMOPOLICY_AUTOMATIC;
+        }
+        if (g_strcmp0(account->omemo_policy, "always") == 0) {
+            policy = PROF_OMEMOPOLICY_ALWAYS;
+        }
+    } else {
+        // check global setting
+        char *pref_omemo_policy = prefs_get_string(PREF_OMEMO_POLICY);
+
+        // pref defaults to manual
+        policy = PROF_OMEMOPOLICY_AUTOMATIC;
+
+        if (strcmp(pref_omemo_policy, "manual") == 0) {
+            policy = PROF_OMEMOPOLICY_MANUAL;
+        } else if (strcmp(pref_omemo_policy, "always") == 0) {
+            policy = PROF_OMEMOPOLICY_ALWAYS;
+        }
+
+        prefs_free_string(pref_omemo_policy);
+    }
+
+    switch (policy) {
+        case PROF_OMEMOPOLICY_MANUAL:
+            result = FALSE;
+            break;
+        case PROF_OMEMOPOLICY_AUTOMATIC:
+            if (g_list_find_custom(account->omemo_enabled, recipient, (GCompareFunc)g_strcmp0)) {
+                result = TRUE;
+            } else if (g_list_find_custom(account->omemo_disabled, recipient, (GCompareFunc)g_strcmp0)) {
+                result = FALSE;
+            } else {
+                return FALSE;
+            }
+            break;
+        case PROF_OMEMOPOLICY_ALWAYS:
+            if (g_list_find_custom(account->omemo_disabled, recipient, (GCompareFunc)g_strcmp0)) {
+                result = FALSE;
+            } else {
+                return TRUE;
+            }
+            break;
+    }
+
+    account_free(account);
+    return result;
+}
+
 static gboolean
 _load_identity(void)
 {
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index 166a5292..8268491c 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -6,6 +6,12 @@
 #define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000
 #define OMEMO_ERR_GCRYPT -20000
 
+typedef enum {
+    PROF_OMEMOPOLICY_MANUAL,
+    PROF_OMEMOPOLICY_AUTOMATIC,
+    PROF_OMEMOPOLICY_ALWAYS
+} prof_omemopolicy_t;
+
 typedef struct omemo_context_t omemo_context;
 
 typedef struct omemo_key {
@@ -40,10 +46,10 @@ char *omemo_own_fingerprint(gboolean formatted);
 void omemo_trust(const char *const jid, const char *const fingerprint);
 void omemo_untrust(const char *const jid, const char *const fingerprint);
 GList *omemo_known_device_identities(const char *const jid);
-gboolean omemo_is_trusted_jid(const char *const jid);
 gboolean omemo_is_trusted_identity(const char *const jid, const char *const fingerprint);
 char *omemo_fingerprint_autocomplete(const char *const search_str, gboolean previous);
 void omemo_fingerprint_autocomplete_reset(void);
+gboolean omemo_automatic_start(const char *const recipient);
 
 void omemo_start_sessions(void);
 void omemo_start_session(const char *const barejid);
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 5064b194..8e17df8e 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -50,6 +50,9 @@
 #ifdef HAVE_LIBOTR
 #include "otr/otr.h"
 #endif
+#ifdef HAVE_OMEMO
+#include "omemo/omemo.h"
+#endif
 
 static void _chatwin_history(ProfChatWin *chatwin, const char *const contact);
 
@@ -73,6 +76,13 @@ chatwin_new(const char *const barejid)
         }
     }
 
+#ifdef HAVE_OMEMO
+    if (omemo_automatic_start(barejid)) {
+        omemo_start_session(barejid);
+        chatwin->is_omemo = TRUE;
+    }
+#endif
+
     return chatwin;
 }
 
diff --git a/src/ui/console.c b/src/ui/console.c
index 260658c8..812a9184 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -2004,6 +2004,10 @@ cons_show_omemo_prefs(void)
     cons_show("OMEMO preferences:");
     cons_show("");
 
+    char *policy_value = prefs_get_string(PREF_OMEMO_POLICY);
+    cons_show("OMEMO policy (/omemo policy) : %s", policy_value);
+    prefs_free_string(policy_value);
+
     char *log_value = prefs_get_string(PREF_OMEMO_LOG);
     if (strcmp(log_value, "on") == 0) {
         cons_show("OMEMO logging (/omemo log)   : ON");
diff --git a/src/ui/core.c b/src/ui/core.c
index b87e2335..c758ba47 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -763,7 +763,7 @@ ui_room_join(const char *const roomjid, gboolean focus)
 {
     ProfMucWin *mucwin = wins_get_muc(roomjid);
     if (mucwin == NULL) {
-        mucwin = (ProfMucWin*)wins_new_muc(roomjid);
+        mucwin = mucwin_new(roomjid);
     }
     ProfWin *window = (ProfWin*)mucwin;
 
diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c
index cdac610f..fc485b3d 100644
--- a/src/ui/mucwin.c
+++ b/src/ui/mucwin.c
@@ -44,6 +44,25 @@
 #include "ui/window.h"
 #include "ui/win_types.h"
 #include "ui/window_list.h"
+#ifdef HAVE_OMEMO
+#include "omemo/omemo.h"
+#endif
+
+ProfMucWin*
+mucwin_new(const char *const barejid)
+{
+    ProfWin *window = wins_new_muc(barejid);
+    ProfMucWin *mucwin = (ProfMucWin *)window;
+
+#ifdef HAVE_OMEMO
+    if (omemo_automatic_start(barejid)) {
+        omemo_start_muc_sessions(barejid);
+        mucwin->is_omemo = TRUE;
+    }
+#endif
+
+    return mucwin;
+}
 
 void
 mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const actor, const char *const reason)
diff --git a/src/ui/ui.h b/src/ui/ui.h
index b94fe475..350a11bb 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -149,6 +149,7 @@ void chatwin_set_outgoing_char(ProfChatWin *chatwin, const char *const ch);
 void chatwin_unset_outgoing_char(ProfChatWin *chatwin);
 
 // MUC window
+ProfMucWin* mucwin_new(const char *const barejid);
 void mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const actor, const char *const reason);
 void mucwin_affiliation_change(ProfMucWin *mucwin, const char *const affiliation, const char *const actor,
     const char *const reason);