From 4fb9b442c80f6513f9f05fcced0641aa21fffa64 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 24 Nov 2010 17:00:14 +0100 Subject: [PATCH] use NEC to handle fingerprint error events --- src/common/connection.py | 5 +++-- src/common/connection_handlers_events.py | 4 ++++ src/gui_interface.py | 15 +++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 8ae3a9e3f..597bf5627 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1260,8 +1260,9 @@ class Connection(CommonConnection, ConnectionHandlers): if saved_fingerprint: # Check sha1 fingerprint if con.Connection.ssl_fingerprint_sha1 != saved_fingerprint: - self.dispatch('FINGERPRINT_ERROR', - (con.Connection.ssl_fingerprint_sha1,)) + gajim.nec.push_incoming_event(FingerprintErrorEvent(None, + conn=self, + new_fingerprint=con.Connection.ssl_fingerprint_sha1)) return True else: gajim.config.set_per('accounts', self.name, 'ssl_fingerprint_sha1', diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 4761e57a7..b29d26a83 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1447,3 +1447,7 @@ class InsecureSSLConnectionEvent(nec.NetworkIncomingEvent): class SSLErrorEvent(nec.NetworkIncomingEvent): name = 'ssl-error' base_network_events = [] + +class FingerprintErrorEvent(nec.NetworkIncomingEvent): + name = 'fingerprint-error' + base_network_events = [] diff --git a/src/gui_interface.py b/src/gui_interface.py index c81c1e914..ea8b7f482 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -1468,26 +1468,29 @@ class Interface: dialogs.ConfirmationDialogDoubleCheck(pritext, sectext, checktext1, checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel) - def handle_event_fingerprint_error(self, account, data): + def handle_event_fingerprint_error(self, obj): # ('FINGERPRINT_ERROR', account, (new_fingerprint,)) + account = obj.conn.name def on_yes(is_checked): del self.instances[account]['online_dialog']['fingerprint_error'] gajim.config.set_per('accounts', account, 'ssl_fingerprint_sha1', - data[0]) + obj.new_fingerprint) # Reset the ignored ssl errors gajim.config.set_per('accounts', account, 'ignore_ssl_errors', '') - gajim.connections[account].ssl_certificate_accepted() + obj.conn.ssl_certificate_accepted() + def on_no(): del self.instances[account]['online_dialog']['fingerprint_error'] - gajim.connections[account].disconnect(on_purpose=True) + obj.conn.disconnect(on_purpose=True) self.handle_event_status(account, 'offline') + pritext = _('SSL certificate error') sectext = _('It seems the SSL certificate of account %(account)s has ' 'changed or your connection is being hacked.\nOld fingerprint: ' '%(old)s\nNew fingerprint: %(new)s\n\nDo you still want to connect ' 'and update the fingerprint of the certificate?') % \ {'account': account, 'old': gajim.config.get_per('accounts', - account, 'ssl_fingerprint_sha1'), 'new': data[0]} + account, 'ssl_fingerprint_sha1'), 'new': obj.new_fingerprint} if 'fingerprint_error' in self.instances[account]['online_dialog']: self.instances[account]['online_dialog']['fingerprint_error'].\ destroy() @@ -1642,11 +1645,11 @@ class Interface: 'UNIQUE_ROOM_ID_SUPPORTED': \ [self.handle_event_unique_room_id_supported], 'PASSWORD_REQUIRED': [self.handle_event_password_required], - 'FINGERPRINT_ERROR': [self.handle_event_fingerprint_error], '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], + 'fingerprint-error': [self.handle_event_fingerprint_error], 'gc-invitation-received': [self.handle_event_gc_invitation], 'gc-presence-received': [self.handle_event_gc_presence], 'gmail-notify': [self.handle_event_gmail_notify],