decrypt GPG messages one after the other. Fixes #7229
This commit is contained in:
parent
f310a41471
commit
7d12dbcc65
|
@ -767,6 +767,9 @@ class ConnectionHandlersBase:
|
|||
# keep track of sessions this connection has with other JIDs
|
||||
self.sessions = {}
|
||||
|
||||
# We decrypt GPG messages one after the other. Keep queue in mem
|
||||
self.gpg_messages_to_decrypt = []
|
||||
|
||||
gajim.ged.register_event_handler('iq-error-received', ged.CORE,
|
||||
self._nec_iq_error_received)
|
||||
gajim.ged.register_event_handler('presence-received', ged.CORE,
|
||||
|
@ -965,6 +968,14 @@ class ConnectionHandlersBase:
|
|||
if sess.enable_encryption:
|
||||
sess.terminate_e2e()
|
||||
|
||||
def decrypt_thread(encmsg, keyID, obj):
|
||||
decmsg = self.gpg.decrypt(encmsg, keyID)
|
||||
decmsg = self.connection.Dispatcher.replace_non_character(decmsg)
|
||||
# \x00 chars are not allowed in C (so in GTK)
|
||||
obj.msgtxt = helpers.decode_string(decmsg.replace('\x00', ''))
|
||||
obj.encrypted = 'xep27'
|
||||
self.gpg_messages_to_decrypt.remove([encmsg, keyID, obj])
|
||||
|
||||
def _nec_message_received(self, obj):
|
||||
if obj.conn.name != self.name:
|
||||
return
|
||||
|
@ -982,20 +993,18 @@ class ConnectionHandlersBase:
|
|||
|
||||
keyID = gajim.config.get_per('accounts', self.name, 'keyid')
|
||||
if keyID:
|
||||
def decrypt_thread(encmsg, keyID, obj):
|
||||
decmsg = self.gpg.decrypt(encmsg, keyID)
|
||||
decmsg = self.connection.Dispatcher.replace_non_character(
|
||||
decmsg)
|
||||
# \x00 chars are not allowed in C (so in GTK)
|
||||
obj.msgtxt = helpers.decode_string(decmsg.replace('\x00',
|
||||
''))
|
||||
obj.encrypted = 'xep27'
|
||||
gajim.thread_interface(decrypt_thread, [encmsg, keyID, obj],
|
||||
self._on_message_decrypted, [obj])
|
||||
self.gpg_messages_to_decrypt.append([encmsg, keyID, obj])
|
||||
if len(self.gpg_messages_to_decrypt) == 1:
|
||||
gajim.thread_interface(self.decrypt_thread, [encmsg, keyID,
|
||||
obj], self._on_message_decrypted, [obj])
|
||||
return
|
||||
self._on_message_decrypted(None, obj)
|
||||
|
||||
def _on_message_decrypted(self, output, obj):
|
||||
if len(self.gpg_messages_to_decrypt):
|
||||
encmsg, keyID, obj = self.gpg_messages_to_decrypt[0]
|
||||
gajim.thread_interface(self.decrypt_thread, [encmsg, keyID, obj],
|
||||
self._on_message_decrypted, [obj])
|
||||
gajim.nec.push_incoming_event(DecryptedMessageReceivedEvent(None,
|
||||
conn=self, msg_obj=obj))
|
||||
|
||||
|
|
Loading…
Reference in New Issue