From 820cec8ceedef45109da990c286f947b90a7fa90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 9 Sep 2018 19:51:58 +0200 Subject: [PATCH] [openpgp] Bugfixes - Parse datetime correctly and convert to int - Query contact keys on openpgp activation --- openpgp/modules/openpgp.py | 2 ++ openpgp/modules/pgp_keylist.py | 1 + openpgp/modules/util.py | 12 +++++++++++- openpgp/pgpplugin.py | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/openpgp/modules/openpgp.py b/openpgp/modules/openpgp.py index 3f73917..554b5c9 100644 --- a/openpgp/modules/openpgp.py +++ b/openpgp/modules/openpgp.py @@ -382,6 +382,8 @@ class OpenPGP: else: from_jid = from_jid.getStripped() + log.info('Key list query received from %s', from_jid) + keylist = util.unpack_public_key_list(stanza, from_jid) self.key_list_received(keylist, from_jid) diff --git a/openpgp/modules/pgp_keylist.py b/openpgp/modules/pgp_keylist.py index 32bba9f..02a1398 100644 --- a/openpgp/modules/pgp_keylist.py +++ b/openpgp/modules/pgp_keylist.py @@ -98,6 +98,7 @@ class PGPKeylist(AbstractPEPModule): raise StanzaMalformed('Invalid date timestamp: %s', date) keylist.append(Key(attrs['v4-fingerprint'], int(timestamp))) + return keylist def _notification_received(self, jid, keylist): diff --git a/openpgp/modules/util.py b/openpgp/modules/util.py index 8351184..03fd045 100644 --- a/openpgp/modules/util.py +++ b/openpgp/modules/util.py @@ -27,6 +27,8 @@ from base64 import b64decode, b64encode import nbxmpp from nbxmpp import Node +from gajim.common.modules.date_and_time import parse_datetime + NS_OPENPGP = 'urn:xmpp:openpgp:0' NS_OPENPGP_PUBLIC_KEYS = 'urn:xmpp:openpgp:0:public-keys' NS_NOTIFY = NS_OPENPGP_PUBLIC_KEYS + '+notify' @@ -89,9 +91,17 @@ def unpack_public_key_list(stanza, from_jid): return date = attrs.get('date', None) + if date is None: + log.warning('No date in metadata') + return + + timestamp = parse_datetime(date, epoch=True) + if timestamp is None: + log.warning('Invalid date timestamp: %s', date) + return fingerprints.append( - Key(attrs['v4-fingerprint'], date)) + Key(attrs['v4-fingerprint'], int(timestamp))) return fingerprints diff --git a/openpgp/pgpplugin.py b/openpgp/pgpplugin.py index 90884a0..1560f20 100644 --- a/openpgp/pgpplugin.py +++ b/openpgp/pgpplugin.py @@ -145,6 +145,7 @@ class OpenPGPPlugin(GajimPlugin): keys = app.connections[account].get_module('OpenPGP').get_keys( jid, only_trusted=False) if not keys: + con.get_module('OpenPGP').query_key_list(jid) ErrorDialog( _('No OpenPGP key'), _('We didnt receive a OpenPGP key from this contact.'))