Commits

Jajcus committed 8554897

Fix DIGEST-MD5 auth when server address provided

When a specific server address was provided via the settings object
DIGEST-MD5 authentication would fail with:

digest_md5.py", line 345, in _make_response
host = host.encode("idna")
AttributeError: 'NoneType' object has no attribute 'encode'

because 'service-hostname' authentication property would not be set in
such case.

Fixed by setting 'service-hostname' to the server address provided and
using the JID domain for 'service-domain' (as the transport, which
usually sets this property, won't know this in such case)

Comments (0)

Files changed (2)

pyxmpp2/streamsasl.py

             raise SASLNotAvailable("Peer doesn't support SASL")
 
         props = dict(stream.auth_properties)
+        if not props.get("service-domain") and (
+                                        stream.peer and stream.peer.domain):
+            props["service-domain"] = stream.peer.domain
         if username is not None:
             props["username"] = username
         if authzid is not None:

pyxmpp2/transport.py

     def _connected(self):
         """Handle connection success."""
         self._auth_properties['remote-ip'] = self._dst_addr[0]
-        self._auth_properties['service-domain'] = self._dst_name
-        self._auth_properties['service-hostname'] = self._dst_hostname
+        if self._dst_service:
+            self._auth_properties['service-domain'] = self._dst_name
+        if self._dst_hostname is not None:
+            self._auth_properties['service-hostname'] = self._dst_hostname
+        else:
+            self._auth_properties['service-hostname'] = self._dst_addr[0]
         self._auth_properties['security-layer'] = None
         self.event(ConnectedEvent(self._dst_addr))
         self._set_state("connected")