Commit aae1a0a9 authored by Tijmen de Mes's avatar Tijmen de Mes

Enable decryption of incoming sip messages

parent b36cd04f
...@@ -1610,6 +1610,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -1610,6 +1610,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidSucceed') notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidSucceed')
notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidFail') notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidFail')
notification_center.add_observer(self, name='BlinkMessageHistoryLastContactsDidSucceed') notification_center.add_observer(self, name='BlinkMessageHistoryLastContactsDidSucceed')
notification_center.add_observer(self, name='PGPMessageDidNotDecrypt')
# self.splitter.splitterMoved.connect(self._SH_SplitterMoved) # check this and decide on what size to have in the window (see Notes) -Dan # self.splitter.splitterMoved.connect(self._SH_SplitterMoved) # check this and decide on what size to have in the window (see Notes) -Dan
...@@ -2367,6 +2368,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2367,6 +2368,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename) sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename)
if session.chat_widget.history_loaded: if session.chat_widget.history_loaded:
session.chat_widget.add_message(ChatMessage(content, sender, 'incoming', id=message.id)) session.chat_widget.add_message(ChatMessage(content, sender, 'incoming', id=message.id))
session.chat_widget.update_message_encryption(message.id, message.is_secure)
else: else:
self.render_after_load.append(ChatMessage(content, sender, 'incoming', id=message.id)) self.render_after_load.append(ChatMessage(content, sender, 'incoming', id=message.id))
...@@ -2414,6 +2416,13 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2414,6 +2416,13 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
session.chat_widget.add_message(ChatStatus(f'Delivery failed: {notification.data.data.code} - {notification.data.data.reason}')) session.chat_widget.add_message(ChatStatus(f'Delivery failed: {notification.data.data.code} - {notification.data.data.reason}'))
session.chat_widget.update_message_status(id=notification.data.id, status='failed') session.chat_widget.update_message_status(id=notification.data.id, status='failed')
def _NH_PGPMessageDidNotDecrypt(self, notification):
blink_session = notification.sender
session = blink_session.items.chat
if session is None:
return
session.chat_widget.add_message(ChatStatus(f'Decryption failed: {notification.data.data.error}'))
def _NH_BlinkMessageHistoryLoadDidSucceed(self, notification): def _NH_BlinkMessageHistoryLoadDidSucceed(self, notification):
blink_session = notification.sender blink_session = notification.sender
session = blink_session.items.chat session = blink_session.items.chat
...@@ -2463,7 +2472,8 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2463,7 +2472,8 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
MessageManager().send_imdn_message(blink_session, message.message_id, message.timestamp, 'displayed') MessageManager().send_imdn_message(blink_session, message.message_id, message.timestamp, 'displayed')
else: else:
self.pending_displayed_notifications.setdefault(blink_session, []).append((message.message_id, message.timestamp)) self.pending_displayed_notifications.setdefault(blink_session, []).append((message.message_id, message.timestamp))
if 'OpenPGP' in message.encryption_type:
session.chat_widget.update_message_encryption(message.message_id, True)
session.chat_widget.history_loaded = True session.chat_widget.history_loaded = True
while len(self.render_after_load) > 0: while len(self.render_after_load) > 0:
......
...@@ -498,6 +498,8 @@ class MessageManager(object, metaclass=Singleton): ...@@ -498,6 +498,8 @@ class MessageManager(object, metaclass=Singleton):
notification_center.add_observer(self, name='BlinkSessionNewOutgoing') notification_center.add_observer(self, name='BlinkSessionNewOutgoing')
notification_center.add_observer(self, name='BlinkSessionWasDeleted') notification_center.add_observer(self, name='BlinkSessionWasDeleted')
notification_center.add_observer(self, name='PGPKeysDidGenerate') notification_center.add_observer(self, name='PGPKeysDidGenerate')
notification_center.add_observer(self, name='PGPMessageDidNotDecrypt')
notification_center.add_observer(self, name='PGPMessageDidDecrypt')
def _add_contact_to_messages_group(self, session): # Maybe this needs to be placed in Contacts? -- Tijmen def _add_contact_to_messages_group(self, session): # Maybe this needs to be placed in Contacts? -- Tijmen
if not session.account.sms.add_unknown_contacts: if not session.account.sms.add_unknown_contacts:
...@@ -569,6 +571,17 @@ class MessageManager(object, metaclass=Singleton): ...@@ -569,6 +571,17 @@ class MessageManager(object, metaclass=Singleton):
return True return True
return False return False
def _handle_incoming_message(self, message, session):
notification_center = NotificationCenter()
notification_center.post_notification('BlinkMessageIsParsed', sender=session, data=message)
if message is not None and 'positive-delivery' in message.disposition:
print("-- Should send delivered imdn")
self.send_imdn_message(session, message.id, message.timestamp, 'delivered')
self._add_contact_to_messages_group(session)
notification_center.post_notification('BlinkGotMessage', sender=session, data=message)
def _send_message(self, outgoing_message): def _send_message(self, outgoing_message):
self._outgoing_message_queue.append(outgoing_message) self._outgoing_message_queue.append(outgoing_message)
self._send_outgoing_messages() self._send_outgoing_messages()
...@@ -720,6 +733,14 @@ class MessageManager(object, metaclass=Singleton): ...@@ -720,6 +733,14 @@ class MessageManager(object, metaclass=Singleton):
return return
else: else:
blink_session = session_manager.create_session(contact, contact_uri, [StreamDescription('messages')], account=account, connect=False) blink_session = session_manager.create_session(contact, contact_uri, [StreamDescription('messages')], account=account, connect=False)
else:
if blink_session.fake_streams.get('messages') is None:
stream = StreamDescription('messages')
blink_session.fake_streams.extend([stream.create_stream()])
blink_session._delete_when_done = False
if account.sms.enable_pgp and account.sms.private_key is not None and os.path.exists(account.sms.private_key.normalized):
blink_session.fake_streams.get('messages').enable_pgp()
notification_center.post_notification('BlinkSessionWillAddStream', sender=blink_session, data=NotificationData(stream=stream))
if content_type.lower() in ['text/pgp-public-key', 'text/pgp-private-key']: if content_type.lower() in ['text/pgp-public-key', 'text/pgp-private-key']:
notification_center.post_notification('PGPKeysShouldReload', sender=blink_session) notification_center.post_notification('PGPKeysShouldReload', sender=blink_session)
...@@ -751,14 +772,13 @@ class MessageManager(object, metaclass=Singleton): ...@@ -751,14 +772,13 @@ class MessageManager(object, metaclass=Singleton):
return return
message = BlinkMessage(body, content_type, sender, timestamp=timestamp, id=message_id, disposition=disposition) message = BlinkMessage(body, content_type, sender, timestamp=timestamp, id=message_id, disposition=disposition)
notification_center.post_notification('BlinkMessageIsParsed', sender=blink_session, data=message)
if disposition is not None and 'positive-delivery' in disposition: if encryption == 'OpenPGP':
# print("-- Should send delivered imdn") if blink_session.fake_streams.get('messages').can_decrypt:
self.send_imdn_message(blink_session, message_id, timestamp, 'delivered') blink_session.fake_streams.get('messages').decrypt(message)
return
self._add_contact_to_messages_group(blink_session) self._handle_incoming_message(message, blink_session)
notification_center.post_notification('BlinkGotMessage', sender=blink_session, data=message)
else: else:
# TODO handle replicated messages # TODO handle replicated messages
pass pass
...@@ -801,6 +821,22 @@ class MessageManager(object, metaclass=Singleton): ...@@ -801,6 +821,22 @@ class MessageManager(object, metaclass=Singleton):
outgoing_message = OutgoingMessage(session.account, session.contact, str(notification.data.public_key), 'text/pgp-public-key', session=session) outgoing_message = OutgoingMessage(session.account, session.contact, str(notification.data.public_key), 'text/pgp-public-key', session=session)
self._send_message(outgoing_message) self._send_message(outgoing_message)
def _NH_PGPMessageDidDecrypt(self, notification):
if not isinstance(notification.data.message, BlinkMessage):
return
session = notification.sender
notification.data.message.is_secure = True
notification_center = NotificationCenter()
notification_center.post_notification('BlinkMessageDidDecrypt', sender=session, data=NotificationData(message=notification.data.message))
self._handle_incoming_message(notification.data.message, session)
def _NH_PGPMessageDidNotDecrypt(self, notification):
session = notification.sender
data = notification.data.message
self.send_imdn_message(session, data.message_id, data.timestamp, 'error')
def export_private_key(self, account): def export_private_key(self, account):
if account is None: if account is 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