use NEC to handle failed-decrypt events
This commit is contained in:
parent
04b89bc473
commit
e9f5065479
|
@ -1601,6 +1601,8 @@ class ChatControl(ChatControlBase):
|
|||
self._nec_pep_received)
|
||||
gajim.ged.register_event_handler('vcard-received', ged.GUI1,
|
||||
self._nec_vcard_received)
|
||||
gajim.ged.register_event_handler('failed-decrypt', ged.GUI1,
|
||||
self._nec_failed_decrypt)
|
||||
|
||||
# PluginSystem: adding GUI extension point for this ChatControl
|
||||
# instance object
|
||||
|
@ -2589,6 +2591,8 @@ class ChatControl(ChatControlBase):
|
|||
self._nec_pep_received)
|
||||
gajim.ged.remove_event_handler('vcard-received', ged.GUI1,
|
||||
self._nec_vcard_received)
|
||||
gajim.ged.remove_event_handler('failed-decrypt', ged.GUI1,
|
||||
self._nec_failed_decrypt)
|
||||
|
||||
self.send_chatstate('gone', self.contact)
|
||||
self.contact.chatstate = None
|
||||
|
@ -3036,6 +3040,27 @@ class ChatControl(ChatControlBase):
|
|||
self.begin_negotiation()
|
||||
self.session.negotiate_archiving()
|
||||
|
||||
def _nec_failed_decrypt(self, obj):
|
||||
if obj.session != self.session:
|
||||
return
|
||||
|
||||
obj.printed_in_chat = True
|
||||
|
||||
details = _('Unable to decrypt message from %s\nIt may have been '
|
||||
'tampered with.') % obj.fjid
|
||||
self.print_conversation_line(details, 'status', '', obj.timestamp)
|
||||
|
||||
# terminate the session
|
||||
thread_id = self.session.thread_id
|
||||
self.session.terminate_e2e()
|
||||
obj.conn.delete_session(obj.fjid, thread_id)
|
||||
|
||||
# restart the session
|
||||
self.begin_e2e_negotiation()
|
||||
|
||||
# Stop emission so it doesn't go to gui_interface
|
||||
return True
|
||||
|
||||
def got_connected(self):
|
||||
ChatControlBase.got_connected(self)
|
||||
# Refreshing contact
|
||||
|
|
|
@ -1407,8 +1407,8 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
obj.stanza = obj.session.decrypt_stanza(obj.stanza)
|
||||
obj.msgtxt = obj.stanza.getBody()
|
||||
except Exception:
|
||||
self.dispatch('FAILED_DECRYPT', (obj.fjid, obj.timestamp,
|
||||
obj.session))
|
||||
gajim.nec.push_incoming_event(FailedDecryptEvent(None,
|
||||
conn=self, msg_obj=obj))
|
||||
return
|
||||
|
||||
if obj.enc_tag and self.USE_GPG:
|
||||
|
|
|
@ -1562,3 +1562,15 @@ class ZeroconfNameConflictEvent(nec.NetworkIncomingEvent):
|
|||
class PasswordRequiredEvent(nec.NetworkIncomingEvent):
|
||||
name = 'password-required'
|
||||
base_network_events = []
|
||||
|
||||
class FailedDecryptEvent(nec.NetworkIncomingEvent):
|
||||
name = 'failed-decrypt'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.msg_obj.conn
|
||||
self.fjid = self.msg_obj.fjid
|
||||
self.timestamp = self.msg_obj.timestamp
|
||||
self.session = self.msg_obj.session
|
||||
self.printed_in_chat = False
|
||||
return True
|
||||
|
|
|
@ -132,7 +132,7 @@ connection_handlers.ConnectionHandlersBase, connection_handlers.ConnectionJingle
|
|||
try:
|
||||
msg = session.decrypt_stanza(msg)
|
||||
except Exception:
|
||||
self.dispatch('FAILED_DECRYPT', (frm, tim))
|
||||
self.dispatch('FAILED_DECRYPT', (frm, tim, session))
|
||||
|
||||
msgtxt = msg.getBody()
|
||||
subject = msg.getSubject() # if not there, it's None
|
||||
|
|
|
@ -1063,26 +1063,10 @@ class Interface:
|
|||
def handle_atom_entry(self, obj):
|
||||
AtomWindow.newAtomEntry(obj.atom_entry)
|
||||
|
||||
def handle_event_failed_decrypt(self, account, data):
|
||||
jid, tim, session = data
|
||||
|
||||
details = _('Unable to decrypt message from '
|
||||
'%s\nIt may have been tampered with.') % jid
|
||||
|
||||
ctrl = session.control
|
||||
if ctrl:
|
||||
ctrl.print_conversation_line(details, 'status', '', tim)
|
||||
else:
|
||||
dialogs.WarningDialog(_('Unable to decrypt message'),
|
||||
details)
|
||||
|
||||
# terminate the session
|
||||
session.terminate_e2e()
|
||||
session.conn.delete_session(jid, session.thread_id)
|
||||
|
||||
# restart the session
|
||||
if ctrl:
|
||||
ctrl.begin_e2e_negotiation()
|
||||
def handle_event_failed_decrypt(self, obj):
|
||||
details = _('Unable to decrypt message from %s\nIt may have been '
|
||||
'tampered with.') % obj.fjid
|
||||
dialogs.WarningDialog(_('Unable to decrypt message'), details)
|
||||
|
||||
def handle_event_zc_name_conflict(self, obj):
|
||||
def on_ok(new_name):
|
||||
|
@ -1420,11 +1404,11 @@ class Interface:
|
|||
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
|
||||
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
|
||||
'SIGNED_IN': [self.handle_event_signed_in],
|
||||
'FAILED_DECRYPT': [self.handle_event_failed_decrypt],
|
||||
'atom-entry-received': [self.handle_atom_entry],
|
||||
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
|
||||
'bookmarks-received': [self.handle_event_bookmarks],
|
||||
'connection-lost': [self.handle_event_connection_lost],
|
||||
'failed-decrypt': [(self.handle_event_failed_decrypt, ged.GUI2)],
|
||||
'fingerprint-error': [self.handle_event_fingerprint_error],
|
||||
'gc-invitation-received': [self.handle_event_gc_invitation],
|
||||
'gc-presence-received': [self.handle_event_gc_presence],
|
||||
|
@ -1474,7 +1458,11 @@ class Interface:
|
|||
"""
|
||||
for event_name, event_handlers in self.handlers.iteritems():
|
||||
for event_handler in event_handlers:
|
||||
gajim.ged.register_event_handler(event_name, ged.GUI1,
|
||||
prio = ged.GUI1
|
||||
if type(event_handler) == tuple:
|
||||
prio = event_handler[1]
|
||||
event_handler = event_handler[0]
|
||||
gajim.ged.register_event_handler(event_name, prio,
|
||||
event_handler)
|
||||
|
||||
################################################################################
|
||||
|
|
Loading…
Reference in New Issue