Author: junglecow
Date: 2006-12-28 00:25:32 +0100 (Thu, 28 Dec 2006)
New Revision: 7727
Modified:
trunk/src/common/connection.py
Log:
Move fingerprint check into its own function.
Modified: trunk/src/common/connection.py
===================================================================
--- trunk/src/common/connection.py 2006-12-27 22:45:23 UTC (rev 7726)
+++ trunk/src/common/connection.py 2006-12-27 23:25:32 UTC (rev 7727)
@@ -434,12 +434,39 @@
resource = gajim.config.get_per('accounts', self.name, 'resource')
self.connection = con
+ fpr_good = self._check_fingerprint(con, con_type)
+ if fpr_good == False:
+ log.error(_("Fingerprint mismatch for %s: Got %s, expected %s"), hostname, got, expected)
+ self.disconnect(on_purpose = True)
+ self.dispatch('STATUS', 'offline')
+ self.dispatch('CONNECTION_LOST',
+ (_('Security error connecting to "%s"') % self._hostname,
+ _("The server's key has changed, or someone is trying to hack your connection.")))
+ if self.on_connect_auth:
+ self.on_connect_auth(None)
+ self.on_connect_auth = None
+ return
+
+ if fpr_good == None:
+ log.warning(_("No fingerprint in database for %s. Connection could be insecure."), hostname)
+
+ if fpr_good == True:
+ log.info("Fingerprint found and matched for %s.", hostname)
+
+ con.auth(name, self.password, resource, 1, self.__on_auth)
+
+ return True
+
+ def _check_fingerprint(self, con, con_type):
+ fpr_good = None # None: No fpr in database, False: mismatch, True: match
+
# FIXME: find a more permanent place for loading servers.xml
servers_xml = os.path.join(gajim.DATA_DIR, 'other', 'servers.xml')
servers = gtkgui_helpers.parse_server_xml(servers_xml)
servers = dict(map(lambda e: (e[0], e), servers))
- fpr_good = None # None: No fpr in database, False: mismatch, True: match
+ hostname = gajim.config.get_per('accounts', self.name, 'hostname')
+
try:
log.debug("con: %s", con)
log.debug("con.Connection: %s", con.Connection)
@@ -465,28 +492,8 @@
else:
log.debug("Connection to %s doesn't seem to have a fingerprint:", hostname, exc_info=True)
- if fpr_good == False:
- log.error(_("Fingerprint mismatch for %s: Got %s, expected %s"), hostname, got, expected)
- self.disconnect(on_purpose = True)
- self.dispatch('STATUS', 'offline')
- self.dispatch('CONNECTION_LOST',
- (_('Security error connecting to "%s"') % self._hostname,
- _("The server's key has changed, or someone is trying to hack your connection.")))
- if self.on_connect_auth:
- self.on_connect_auth(None)
- self.on_connect_auth = None
- return
+ return fpr_good
- if fpr_good == None:
- log.warning(_("No fingerprint in database for %s. Connection could be insecure."), hostname)
-
- if fpr_good == True:
- log.info("Fingerprint found and matched for %s.", hostname)
-
- con.auth(name, self.password, resource, 1, self.__on_auth)
-
- return True
-
def _register_handlers(self, con, con_type):
self.peerhost = con.get_peerhost()
# notify the gui about con_type