changeset 3a75ad3cf116 in /home/hg/repos/gajim-plugins
author: lovetox <[email protected]>
branches:
details:gajim-plugins?cmd=changeset;node=3a75ad3cf116
description: Usability improvements on first contact
diffstat:
omemo/__init__.py | 88 ++++++++++++++++++++++--------------
omemo/omemo/liteaxolotlstore.py | 6 ++
omemo/omemo/liteidentitykeystore.py | 7 +-
omemo/omemo/litesessionstore.py | 11 ++++
omemo/omemo/state.py | 15 ++++++
omemo/ui.py | 29 ++++++++++++
6 files changed, 119 insertions(+), 37 deletions(-)
diffs (truncated from 304 to 300 lines):
diff -r f31aa18ea458 -r 3a75ad3cf116 omemo/__init__.py
--- a/omemo/__init__.py Sun Jul 31 15:41:44 2016 +0200
+++ b/omemo/__init__.py Mon Aug 01 21:41:40 2016 +0200
@@ -88,6 +88,7 @@
SUPPORTED_PERSONAL_USER_EVENTS.append(DevicelistPEP)
self.plugin = self
self.announced = []
+ self.query_for_bundles = []
@log_calls('OmemoPlugin')
def get_omemo_state(self, account):
@@ -124,12 +125,15 @@
account = event.conn.name
log.debug(account +
' => Announce Support after Sign In')
+ self.query_for_bundles = []
+ self.announced = []
self.announced.append(account)
self.publish_bundle(account)
self.query_own_devicelist(account)
@log_calls('OmemoPlugin')
def activate(self):
+ self.query_for_bundles = []
if NS_NOTIFY not in gajim.gajim_common_features:
gajim.gajim_common_features.append(NS_NOTIFY)
self._compute_caps_hash()
@@ -298,6 +302,11 @@
state.set_own_devices(devices_list)
state.store.sessionStore.setActiveState(devices_list, my_jid)
+ # remove contact from list, so on send button pressed
+ # we query for bundle and build a session
+ if contact_jid in self.query_for_bundles:
+ self.query_for_bundles.remove(contact_jid)
+
if not state.own_device_id_published() or anydup(
state.own_devices):
# Our own device_id is not in the list, it could be
@@ -310,6 +319,11 @@
state.set_devices(contact_jid, set(devices_list))
state.store.sessionStore.setActiveState(devices_list, contact_jid)
+ # remove contact from list, so on send button pressed
+ # we query for bundle and build a session
+ if contact_jid in self.query_for_bundles:
+ self.query_for_bundles.remove(contact_jid)
+
# Enable Encryption on receiving first Device List
if not state.encryption.exist(contact_jid):
if account in self.ui_list and \
@@ -331,9 +345,6 @@
if chat_control:
self.connect_ui(chat_control)
- # Look if Public Keys are missing and fetch them
- self.are_keys_missing(account, contact_jid)
-
return True
@log_calls('OmemoPlugin')
@@ -383,14 +394,26 @@
def are_keys_missing(self, account, contact_jid):
""" Check DB if keys are missing and query them """
state = self.get_omemo_state(account)
- devices_without_session = state \
- .devices_without_sessions(contact_jid)
- if devices_without_session:
- for device_id in devices_without_session:
- self.fetch_device_bundle_information(account,
- state,
- contact_jid,
- device_id)
+ if contact_jid not in self.query_for_bundles:
+
+ devices_without_session = state \
+ .devices_without_sessions(contact_jid)
+
+ self.query_for_bundles.append(contact_jid)
+
+ if devices_without_session:
+ for device_id in devices_without_session:
+ self.fetch_device_bundle_information(account,
+ state,
+ contact_jid,
+ device_id)
+
+ if state.getTrustedFingerprints(contact_jid):
+ return False
+ else:
+ return True
+
+
@log_calls('OmemoPlugin')
def handle_iq_received(self, event):
@@ -553,6 +576,11 @@
state.set_own_devices(devices_list)
state.store.sessionStore.setActiveState(devices_list, my_jid)
+ # remove contact from list, so on send button pressed
+ # we query for bundle and build a session
+ if contact_jid in self.query_for_bundles:
+ self.query_for_bundles.remove(contact_jid)
+
if not state.own_device_id_published() or anydup(
state.own_devices):
# Our own device_id is not in the list, it could be
@@ -601,32 +629,23 @@
@log_calls('OmemoPlugin')
def handle_outgoing_stanza(self, event):
- if not event.msg_iq.getTag('body'):
- return
+ try:
+ if not event.msg_iq.getTag('body'):
+ return
- # Delete previous Message out of Correction Message Stanza
- if event.msg_iq.getTag('replace', namespace=NS_CORRECT):
- event.msg_iq.delChild('encrypted')
+ account = event.conn.name
+ state = self.get_omemo_state(account)
+ full_jid = str(event.msg_iq.getAttr('to'))
+ to_jid = gajim.get_jid_without_resource(full_jid)
+ if not state.encryption.is_active(to_jid):
+ return
- plaintext = event.msg_iq.getBody().encode('utf8')
- account = event.conn.name
- state = self.get_omemo_state(account)
- full_jid = str(event.msg_iq.getAttr('to'))
- to_jid = gajim.get_jid_without_resource(full_jid)
- if not state.encryption.is_active(to_jid):
- return False
+ # Delete previous Message out of Correction Message Stanza
+ if event.msg_iq.getTag('replace', namespace=NS_CORRECT):
+ event.msg_iq.delChild('encrypted')
- if not state.store.identityKeyStore.getTrustedFingerprints(to_jid):
- msg = "To send an encrypted message, you have to " \
- "first trust the fingerprint of your contact!"
- if account in self.ui_list and \
- to_jid in self.ui_list[account]:
- self.ui_list[account][to_jid].chat_control. \
- print_conversation_line(msg, 'status', '', None)
+ plaintext = event.msg_iq.getBody().encode('utf8')
- return True
-
- try:
msg_dict = state.create_msg(
gajim.get_jid_from_account(account), to_jid, plaintext)
if not msg_dict:
@@ -638,7 +657,8 @@
store = Node('store', attrs={'xmlns': NS_HINTS})
event.msg_iq.addChild(node=store)
self.print_msg_to_log(event.msg_iq)
- except:
+ except Exception as e:
+ log.debug(e)
return True
@log_calls('OmemoPlugin')
diff -r f31aa18ea458 -r 3a75ad3cf116 omemo/omemo/liteaxolotlstore.py
--- a/omemo/omemo/liteaxolotlstore.py Sun Jul 31 15:41:44 2016 +0200
+++ b/omemo/omemo/liteaxolotlstore.py Mon Aug 01 21:41:40 2016 +0200
@@ -87,6 +87,9 @@
return self.identityKeyStore.isTrustedIdentity(recepientId,
identityKey)
+ def getTrustedFingerprints(self, jid):
+ return self.identityKeyStore.getTrustedFingerprints(jid)
+
def setShownFingerprints(self, jid):
return self.identityKeyStore.setShownFingerprints(jid)
@@ -114,6 +117,9 @@
def getActiveDeviceTuples(self):
return self.sessionStore.getActiveDeviceTuples()
+ def getInactiveSessionsKeys(self, recipientId):
+ return self.sessionStore.getInactiveSessionsKeys(recipientId)
+
def getSubDeviceSessions(self, recepientId):
# TODO Reuse this
return self.sessionStore.getSubDeviceSessions(recepientId)
diff -r f31aa18ea458 -r 3a75ad3cf116 omemo/omemo/liteidentitykeystore.py
--- a/omemo/omemo/liteidentitykeystore.py Sun Jul 31 15:41:44 2016 +0200
+++ b/omemo/omemo/liteidentitykeystore.py Mon Aug 01 21:41:40 2016 +0200
@@ -124,13 +124,14 @@
return result
def getTrustedFingerprints(self, jid):
- q = "SELECT _id FROM identities WHERE recipient_id = ? AND trust = ?"
+ q = "SELECT public_key FROM identities WHERE recipient_id = ? AND
trust = ?"
c = self.dbConn.cursor()
result = []
c.execute(q, (jid, TRUSTED))
- result = c.fetchall()
-
+ rows = c.fetchall()
+ for row in rows:
+ result.append(row[0])
return result
def getUndecidedFingerprints(self, jid):
diff -r f31aa18ea458 -r 3a75ad3cf116 omemo/omemo/litesessionstore.py
--- a/omemo/omemo/litesessionstore.py Sun Jul 31 15:41:44 2016 +0200
+++ b/omemo/omemo/litesessionstore.py Mon Aug 01 21:41:40 2016 +0200
@@ -117,3 +117,14 @@
getPublicKey())
result.append(public_key.serialize())
return result
+
+ def getInactiveSessionsKeys(self, recipientId):
+ q = "SELECT record FROM sessions WHERE active = 0 AND recipient_id = ?"
+ c = self.dbConn.cursor()
+ result = []
+ for row in c.execute(q, (recipientId,)):
+ public_key = (SessionRecord(serialized=row[0]).
+ getSessionState().getRemoteIdentityKey().
+ getPublicKey())
+ result.append(public_key.serialize())
+ return result
diff -r f31aa18ea458 -r 3a75ad3cf116 omemo/omemo/state.py
--- a/omemo/omemo/state.py Sun Jul 31 15:41:44 2016 +0200
+++ b/omemo/omemo/state.py Mon Aug 01 21:41:40 2016 +0200
@@ -285,6 +285,21 @@
return self.store.identityKeyStore. \
isTrustedIdentity(self.cipher.recipientId, self.key)
+ def getTrustedFingerprints(self, recipient_id):
+ log.debug('Inactive fingerprints')
+ log.debug(self.store.getInactiveSessionsKeys(recipient_id))
+ log.debug('trusted fingerprints')
+ log.debug(self.store.getTrustedFingerprints(recipient_id))
+
+ inactive = self.store.getInactiveSessionsKeys(recipient_id)
+ trusted = self.store.getTrustedFingerprints(recipient_id)
+ trusted = set(trusted) - set(inactive)
+
+ log.debug('trusted active fingerprints')
+ log.debug(trusted)
+
+ return trusted
+
def device_list_for(self, jid):
""" Return a list of known device ids for the specified jid.
diff -r f31aa18ea458 -r 3a75ad3cf116 omemo/ui.py
--- a/omemo/ui.py Sun Jul 31 15:41:44 2016 +0200
+++ b/omemo/ui.py Mon Aug 01 21:41:40 2016 +0200
@@ -139,6 +139,29 @@
return menu
self.chat_control.prepare_context_menu = omemo_prepare_context_menu
+ # Hook into Send Button so we can check Stuff before sending
+ self.chat_control.orig_send_message = \
+ self.chat_control.send_message
+
+ def omemo_send_message(message, keyID='', chatstate=None, xhtml=None,
+ process_commands=True, attention=False):
+
+ if self.encryption_active() and \
+ self.plugin.are_keys_missing(self.account,
+ self.contact.jid):
+
+ log.debug(self.account + ' => No Trusted Fingerprints for ' +
+ self.contact.jid)
+ self.no_trusted_fingerprints_warning()
+ else:
+ self.chat_control.orig_send_message(message, keyID, chatstate,
+ xhtml, process_commands,
+ attention)
+ log.debug(self.account + ' => Sending Message to ' +
+ self.contact.jid)
+
+ self.chat_control.send_message = omemo_send_message
+
def set_omemo_state(self, enabled):
"""
Enable or disable OMEMO for this window's contact and update the
@@ -209,6 +232,11 @@
self.chat_control.print_conversation_line(msg, 'status', '', None)
self.refreshAuthLockSymbol()
+ def no_trusted_fingerprints_warning(self):
+ msg = "To send an encrypted message, you have to " \
+ "first trust the fingerprint of your contact!"
+ self.chat_control.print_conversation_line(msg, 'status', '', None)
+
def refreshAuthLockSymbol(self):
if self.encryption_active():
if self.state.store.identityKeyStore. \
@@ -226,6 +254,7 @@
self.actions_hbox.remove(self.omemobutton)
self.chat_control.prepare_context_menu = \
self.chat_control.omemo_orig_prepare_context_menu
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits