changeset 0ad2a8bf5e82 in /home/hg/repos/gajim-plugins

author: Bahtiar `kalkin-` Gadimov <[email protected]>
branches: 
details:gajim-plugins?cmd=changeset;node=0ad2a8bf5e82
description: Release OMEMO plugin version 0.3

diffstat:

 omemo/CHANGELOG                 |   16 +++++
 omemo/README.md                 |   33 ++++++-----
 omemo/__init__.py               |  112 ++++++++++++++++++++++-----------------
 omemo/manifest.ini              |    2 +-
 omemo/pkgs/PKGBUILD             |   23 ++++++++
 omemo/setup.cfg                 |    2 +
 omemo/state.py                  |   29 +++------
 omemo/store/encryption.py       |   58 ++++++++++++++++++++
 omemo/store/liteaxolotlstore.py |    2 +
 omemo/test_encryption_store.py  |   31 +++++++++++
 omemo/ui.py                     |   52 ++++++------------
 11 files changed, 241 insertions(+), 119 deletions(-)

diffs (truncated from 670 to 300 lines):

diff -r a761d5282b57 -r 0ad2a8bf5e82 omemo/CHANGELOG
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/omemo/CHANGELOG   Sun Jan 10 21:12:12 2016 +0100
@@ -0,0 +1,16 @@
+0.3 / 2016-01-10
+==================
+  * Save if OMEMO is enabled between restarts - #17
+  * Disable OMEMO if dependencies are missing - #9
+  * Make logging less verbose
+  * Add Arch Linux PKGBUILD file (Thanks Tommaso Sardelli)
+  * Extend README
+  * Fix hiding OMEMO controls in muc
+  * Fix "'ChatControl' object has no attribute 'lock_image'" bug - #16
+  * Ui clearly displays which message is encrypted (and how) - #15
+  * Plaintext messages are now always marked - #15
+
+# 2015-12-27 
+- Fix crash, if jid is not in list (Thanks Mic92)
+- Fix clear_device_list, if account is not connected  (Thanks Mic92)
+- Provide python-axolotl installation instructions in README and manifest.ini
diff -r a761d5282b57 -r 0ad2a8bf5e82 omemo/README.md
--- a/omemo/README.md   Sun Dec 27 18:03:23 2015 +0100
+++ b/omemo/README.md   Sun Jan 10 21:12:12 2016 +0100
@@ -8,28 +8,20 @@
 **DO NOT rely on this plugin to protect sensitive information!** 
 
 ## Installation
-You can install this plugin via the Gajim PluginManager or by cloning the git 
repository into Gajim's plugin directory.
-
-```shell
-mkdir ~/.local/share/gajim/plugins -p
-cd ~/.local/share/gajim/plugins
-git clone [email protected]:kalkin/gajim-omemo.git
-```
-
-### Dependencies
-#### Gajim
-You need Gajim version 0.16.4. If your package manager does not provide an up 
to date 
-version you can install it from the official Mercurial repository. 
+Install the current stable version via the Gajim PluginManager. You *need* 
Gajim
+version *0.16.5*. If your package manager does not provide an up to date 
version
+you can install it from the official Mercurial repository. *DO NOT USE* gajim
+0.16.4 it contains a vulnerability, which is fixed in 0.16.5.
 ```shell
 hg clone https://hg.gajim.org/gajim
 cd gajim
-hg update gajim-0.16.4 --clean
+hg update gajim-0.16.5 --clean
 ```
 
-#### Python libraries
+### Python libraries
 You *have* to install `python-axolotl` via `pip`. Depending on your setup you 
might
 want to use `pip2` as Gajim is using python2.7. If you are using the official 
repository,
-do not forget to install the `nxmpp` dependency via pip or you package manager.
+do not forget to install the `nbxmpp` dependency via pip or you package 
manager.
 
 ## Running
 Enable *OMEMO Multi-End Message and Object Encryption* in the Plugin-Manager.
@@ -43,13 +35,22 @@
 To see OMEMO related debug output start Gajim with the parameter `-l
 gajim.plugin_system.omemo=DEBUG`.
 
+## Hacking
+This repository contains the current development version. If you want to
+contribute clone the git repository into your Gajim's plugin directory. 
+```shell
+mkdir ~/.local/share/gajim/plugins -p
+cd ~/.local/share/gajim/plugins
+git clone https://github.com/kalkin/gajim-omemo
+```
+
 ## Support this project
 I develop this project in my free time. Your donation allows me to spend more
 time working on it and on free software generally.
 
 My Bitcoin Address is: `1CnNM3Mree9hU8eRjCXrfCWV mX6oBnEfV1`
 
-[![Support Me via 
Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=_kalkin&url=https://github.com/kalkin/gajim-omemo&title=gajim-omemo&language=en_US&tags=github&category=people)
+[![Support Me via 
Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/thing/5038679)
 
 ## I found a bug
 Please report it to the [issue
diff -r a761d5282b57 -r 0ad2a8bf5e82 omemo/__init__.py
--- a/omemo/__init__.py Sun Dec 27 18:03:23 2015 +0100
+++ b/omemo/__init__.py Sun Jan 10 21:12:12 2016 +0100
@@ -25,7 +25,6 @@
 from plugins import GajimPlugin
 from plugins.helpers import log_calls
 
-from .state import OmemoState
 from .ui import Ui
 from .xmpp import (
     NS_NOTIFY, NS_OMEMO, BundleInformationAnnouncement, BundleInformationQuery,
@@ -34,7 +33,15 @@
 
 iq_ids_to_callbacks = {}
 
+AXOLOTL_MISSING = 'Please install python-axolotl.'
+
 log = logging.getLogger('gajim.plugin_system.omemo')
+try:
+    from .state import OmemoState
+    HAS_AXOLOTL = True
+except ImportError:
+    log.error(AXOLOTL_MISSING)
+    HAS_AXOLOTL = False
 
 
 class OmemoPlugin(GajimPlugin):
@@ -45,6 +52,10 @@
 
     @log_calls('OmemoPlugin')
     def init(self):
+        if not HAS_AXOLOTL:
+            self.activatable = False
+            self.available_text = _(AXOLOTL_MISSING)
+            return
         self.events_handlers = {
             'message-received': (ged.PRECORE, self.message_received),
             'pep-received': (ged.PRECORE, self.handle_device_list_update),
@@ -54,18 +65,24 @@
             (ged.PRECORE, self.handle_outgoing_msgs),
         }
         self.config_dialog = None
-        self.gui_extension_points = {'chat_control_base':
+        self.gui_extension_points = {'chat_control':
                                      (self.connect_ui, None)}
         SUPPORTED_PERSONAL_USER_EVENTS.append(DevicelistPEP)
 
     @log_calls('OmemoPlugin')
     def get_omemo_state(self, account):
+        """ Returns the the OmemoState for specified account. Creates the
+            OmemoState if it does not exist yet.
+        """
         if account not in self.omemo_states:
             self.omemo_states[account] = OmemoState(account)
         return self.omemo_states[account]
 
     @log_calls('OmemoPlugin')
     def signed_in(self, show):
+        """
+            On sign in announce OMEMO support for each account.
+        """
         account = show.conn.name
         state = self.get_omemo_state(account)
         self.announce_support(state)
@@ -160,15 +177,13 @@
         devices_list = unpack_device_list_update(event)
         if len(devices_list) == 0:
             return False
-        account = event.conn.name
+        account_name = event.conn.name
         contact_jid = gajim.get_jid_without_resource(event.fjid)
-        state = self.get_omemo_state(account)
-        my_jid = gajim.get_jid_from_account(account)
-
-        log.debug(account + ' ⇒ Received OMEMO pep for jid ' + contact_jid)
+        state = self.get_omemo_state(account_name)
+        my_jid = gajim.get_jid_from_account(account_name)
 
         if contact_jid == my_jid:
-            log.debug(state.name + ' ⇒ Received own device_list ' + str(
+            log.info(state.name + ' ⇒ Received own device_list:' + str(
                 devices_list))
             state.add_own_devices(devices_list)
 
@@ -181,12 +196,19 @@
                 devices_list.append(state.own_device_id)
                 self.publish_own_devices_list(state)
         else:
+            log.info(account_name + ' ⇒ Received device_list for ' +
+                     contact_jid + ':' + str(devices_list))
             state.add_devices(contact_jid, devices_list)
-            if account in self.ui_list and contact_jid in self.ui_list[
-                    account]:
-                self.ui_list[account][contact_jid].toggle_omemo(True)
+            if account_name in self.ui_list and contact_jid not in 
self.ui_list[
+                    account_name]:
 
-        self.update_prekeys(account, contact_jid)
+                chat_control = gajim.interface.msg_win_mgr.get_control(
+                    contact_jid, account_name)
+
+                if chat_control is not None:
+                    self.connect_ui(chat_control)
+
+        self.update_prekeys(account_name, contact_jid)
 
         return True
 
@@ -204,11 +226,18 @@
 
     @log_calls('OmemoPlugin')
     def connect_ui(self, chat_control):
-        account = chat_control.contact.account.name
-        jid = chat_control.contact.jid
-        if account not in self.ui_list:
-            self.ui_list[account] = {}
-        self.ui_list[account][jid] = Ui(self, chat_control)
+        account_name = chat_control.contact.account.name
+        contact_jid = chat_control.contact.jid
+        if account_name not in self.ui_list:
+            self.ui_list[account_name] = {}
+        state = self.get_omemo_state(account_name)
+        if contact_jid in state.device_ids:
+            log.debug(account_name + " ⇒ Adding OMEMO ui for " + contact_jid)
+            omemo_enabled = state.encryption.is_active(contact_jid)
+            self.ui_list[account_name][contact_jid] = Ui(self, chat_control,
+                                                         omemo_enabled)
+        else:
+            log.warn(account_name + " ⇒ No OMEMO dev_keys for " + contact_jid)
 
     def are_keys_missing(self, contact):
         """ Used by the ui to set the state of the PreKeyButton. """
@@ -218,6 +247,9 @@
         result = 0
         result += len(state.devices_without_sessions(str(contact.jid)))
         result += len(state.own_devices_without_sessions(my_jid))
+        if result > 0:
+            log.warn(account + " ⇒ Missing keys for " + contact.jid + ": " +
+                     str(result))
         return result
 
     @log_calls('OmemoPlugin')
@@ -233,10 +265,13 @@
                 del iq_ids_to_callbacks[id_]
 
     @log_calls('OmemoPlugin')
-    def query_prekey(self, contact):
-        account = contact.account.name
+    def query_prekey(self, recipient):
+        """ Calls OmemoPlugin.fetch_device_bundle_information() for each own or
+            recipient device key missing.
+        """
+        account = recipient.account.name
         state = self.get_omemo_state(account)
-        to_jid = contact.jid
+        to_jid = recipient.jid
         my_jid = gajim.get_jid_from_account(account)
         for device_id in state.devices_without_sessions(to_jid):
             self.fetch_device_bundle_information(state, to_jid, device_id)
@@ -258,8 +293,8 @@
             device_id : int
                 The device_id for which we are missing an axolotl session
         """
-        log.debug(state.name + '→ Fetch bundle information for dev ' + str(
-            device_id) + ' and jid ' + jid)
+        log.debug(state.name + '→ Fetch bundle device ' + str(device_id) + '#'
+                  + jid)
         iq = BundleInformationQuery(jid, device_id)
         iq_id = str(iq.getAttr('id'))
         iq_ids_to_callbacks[iq_id] = \
@@ -366,12 +401,12 @@
         if successful(stanza):
             log.debug(account + ' → Publishing bundle was successful')
             if not state.own_device_id_published():
-                log.debug(account + ' → Device list needs updating')
+                log.warn(account + ' → Device list needs updating')
                 self.publish_own_devices_list(state)
             else:
                 log.debug(account + ' → Device list up to date')
         else:
-            log.debug(account + ' → Publishing bundle was NOT successful')
+            log.error(account + ' → Publishing bundle was NOT successful')
 
     @log_calls('OmemoPlugin')
     def clear_device_list(self, contact):
@@ -397,7 +432,7 @@
         state = self.get_omemo_state(account)
         full_jid = str(event.msg_iq.getAttr('to'))
         to_jid = gajim.get_jid_without_resource(full_jid)
-        if to_jid not in state.omemo_enabled:
+        if not state.encryption.is_active(to_jid):
             return False
         try:
             msg_dict = state.create_msg(
@@ -412,40 +447,19 @@
             return True
 
     @log_calls('OmemoPlugin')
-    def is_omemo_enabled(self, contact):
-        account = contact.account.name
-        state = self.get_omemo_state(account)
-        return contact.jid in state.omemo_enabled
-
-    @log_calls('OmemoPlugin')
     def omemo_enable_for(self, contact):
         """ Used by the ui to enable omemo for a specified contact """
         account = contact.account.name
         state = self.get_omemo_state(account)
-        state.omemo_enabled |= {contact.jid}
+        state.encryption.activate(contact.jid)
 
     @log_calls('OmemoPlugin')
     def omemo_disable_for(self, contact):
         """ Used by the ui to disable omemo for a specified contact """
+        # TODO Migrate this
         account = contact.account.name
         state = self.get_omemo_state(account)
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to