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