Ignore:
Timestamp:
Jan 12, 2013, 4:40:38 PM (8 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Properly encode IDN domain names for SRV lookups.

Before Twisted 12.3.0, the SRV lookup done for outgoing
connections succeeded if passed a unicode string with all-ASCII
code points. A recent change made the DNS code more strict, and
only byte string are accepted as domain name. See
http://twistedmatrix.com/trac/ticket/6245 for details.

This change makes sure domain names are encoded to their ASCII
Compatible Equivalent (ACE) version before passing the resulting
byte string to twisted.names.srvconnect.SRVConnector, as per
RFC 3490.

Note that while connecting to servers with an IDN domain name
now works properly, authentication using MD5-Digest SASL mechanism
will fail until http://twistedmatrix.com/trac/ticket/5066 has been
resolved.

Fixes: #77.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/generic.py

    r171 r178  
    77Generic XMPP protocol helpers.
    88"""
     9
     10from encodings import idna
    911
    1012from zope.interface import implements
     
    328330    def clientConnectionFailed(self, connector, reason):
    329331        self.deferred.errback(reason)
     332
     333
     334
     335def prepareIDNName(name):
     336    """
     337    Encode a unicode IDN Domain Name into its ACE equivalent.
     338
     339    This will encode the domain labels, separated by allowed dot code points,
     340    to their ASCII Compatible Encoding (ACE) equivalent, using punycode. The
     341    result is an ASCII byte string of the encoded labels, separated by the
     342    standard full stop.
     343    """
     344    result = []
     345    labels = idna.dots.split(name)
     346
     347    if labels and len(labels[-1]) == 0:
     348        trailing_dot = b'.'
     349        del labels[-1]
     350    else:
     351        trailing_dot = b''
     352
     353    for label in labels:
     354        result.append(idna.ToASCII(label))
     355
     356    return b'.'.join(result) + trailing_dot
Note: See TracChangeset for help on using the changeset viewer.