[openpgp] Save encryption details
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user