Commit 7ad794da authored by Philipp Hörist's avatar Philipp Hörist

[openpgp] Save encryption details

parent 9b3e23be
......@@ -89,7 +89,7 @@ class PGPContext(gnupg.GPG):
if not result.ok:
raise DecryptionFailed(result.status)
return result.data.decode('utf8')
return result.data.decode('utf8'), result.fingerprint
def get_key(self, fingerprint):
return super().list_keys(keys=[fingerprint])
......
......@@ -28,6 +28,8 @@ from gajim.common import configpaths
from gajim.common.connection_handlers_events import MessageNotSentEvent
from openpgp.modules import util
from openpgp.modules.util import ENCRYPTION_NAME
from openpgp.modules.util import add_additional_data
from openpgp.modules.util import NS_OPENPGP_PUBLIC_KEYS
from openpgp.modules.util import NS_OPENPGP
from openpgp.modules.util import Key
......@@ -40,10 +42,8 @@ from openpgp.backend.pygpg import PGPContext
log = logging.getLogger('gajim.plugin_system.openpgp')
ENCRYPTION_NAME = 'OpenPGP'
# Module name
name = 'OpenPGP'
name = ENCRYPTION_NAME
zeroconf = False
......@@ -198,6 +198,9 @@ class ContactData:
return [k for k in keys if k.active and k.trust in (Trust.VERIFIED,
Trust.BLIND)]
def get_key(self, fingerprint):
return self._key_store.get(fingerprint, None)
def set_trust(self, fingerprint, trust):
self._storage.set_trust(self.jid, fingerprint, trust)
......@@ -269,6 +272,16 @@ class PGPContacts:
except KeyError:
return []
def get_trust(self, jid, fingerprint):
contact_data = self._contacts.get(jid, None)
if contact_data is None:
return Trust.UNKNOWN
key = contact_data.get_key(fingerprint)
if key is None:
return Trust.UNKNOWN
return key.trust
class OpenPGP:
def __init__(self, con):
......@@ -445,7 +458,8 @@ class OpenPGP:
encrypted_payload = b64decode(b64encode_payload)
try:
decrypted_payload = self._pgp.decrypt(encrypted_payload)
decrypted_payload, fingerprint = self._pgp.decrypt(
encrypted_payload)
except DecryptionFailed as error:
log.warning(error)
return
......@@ -482,6 +496,9 @@ class OpenPGP:
if body:
obj.msgtxt = body
add_additional_data(obj.additional_data,
fingerprint)
obj.encrypted = ENCRYPTION_NAME
callback(obj)
......@@ -508,6 +525,9 @@ class OpenPGP:
util.create_openpgp_message(obj, encrypted_payload)
add_additional_data(obj.additional_data,
self._fingerprint)
obj.encrypted = ENCRYPTION_NAME
self.print_msg_to_log(obj.msg_iq)
callback(obj)
......
......@@ -29,6 +29,7 @@ from nbxmpp import Node
from gajim.common.modules.date_and_time import parse_datetime
ENCRYPTION_NAME = 'OpenPGP'
NS_OPENPGP = 'urn:xmpp:openpgp:0'
NS_OPENPGP_PUBLIC_KEYS = 'urn:xmpp:openpgp:0:public-keys'
NS_NOTIFY = NS_OPENPGP_PUBLIC_KEYS + '+notify'
......@@ -206,6 +207,11 @@ def get_info_message():
return '[This message is *encrypted* with OpenPGP (See :XEP:`0373`]'
def add_additional_data(data, fingerprint, trust):
data['encrypted'] = {'name': ENCRYPTION_NAME,
'fingerprint': fingerprint}
class VerifyFailed(Exception):
pass
......
......@@ -32,6 +32,7 @@ from gajim.common.const import CSSPriority
from gajim.gtk.dialogs import ErrorDialog
from openpgp.modules.util import NS_NOTIFY
from openpgp.modules.util import ENCRYPTION_NAME
from openpgp.modules import pgp_keylist
try:
from openpgp.modules import openpgp
......@@ -60,7 +61,7 @@ class OpenPGPPlugin(GajimPlugin):
self.modules = [pgp_keylist,
openpgp]
self.encryption_name = 'OpenPGP'
self.encryption_name = ENCRYPTION_NAME
self.config_dialog = None
self.gui_extension_points = {
'encrypt' + self.encryption_name: (self._encrypt_message, None),
......
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