Commit 74ed3291 authored by Philipp Hörist's avatar Philipp Hörist

[pgp] Don’t assign keys automatically

Fixes #519
parent 2cc719be
......@@ -78,7 +78,7 @@ class PGPLegacy(BaseModule):
self._store = KeyStore(self._account, self.own_jid, self._log,
self._always_trust = []
self._presence_key_id_store = {}
self._presence_fingerprint_store = {}
def pgp_backend(self):
......@@ -101,39 +101,43 @@ class PGPLegacy(BaseModule):
if key_data is None:
return False
key_id = key_data['key_id']
announced_key_id = self._presence_key_id_store.get(jid)
if announced_key_id is None:
announced_fingerprint = self._presence_fingerprint_store.get(jid)
if announced_fingerprint is None:
return True
if announced_key_id == key_id:
if announced_fingerprint == key_id:
return True
raise KeyMismatch(announced_key_id)
raise KeyMismatch(announced_fingerprint)
def _on_presence_received(self, _con, _stanza, properties):
if properties.signed is None:
jid = properties.jid.getBare()
key_id = self._pgp.verify(properties.status, properties.signed)'Presence from %s was signed with key-id: %s',
jid, key_id)
if key_id is None:
fingerprint = self._pgp.verify(properties.status, properties.signed)
if fingerprint is None:'Presence from %s was signed but no corresponding '
'key was found', jid)
self._presence_key_id_store[jid] = key_id
self._presence_fingerprint_store[jid] = fingerprint'Presence from %s was verified successfully, '
'fingerprint: %s', jid, fingerprint)
key_data = self.get_contact_key_data(jid)
if key_data is not None:
if key_data is None:'No key assigned for contact: %s', jid)
key = self._pgp.get_key(key_id)
if not key:'Key-id %s not found in keyring, cant assign to %s',
key_id, jid)
if key_data['key_id'] != fingerprint:
self._log.warning('Fingerprint mismatch, '
'Presence was signed with fingerprint: %s, '
'Assigned key fingerprint: %s',
fingerprint, key_data['key_id'])
return'Assign key-id: %s to %s', key_id, jid)
self.set_contact_key_data(jid, (key_id, key[0]['uids'][0]))
def _message_received(self, _con, stanza, properties):
if not properties.is_pgp_legacy or properties.from_muc:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment