# HG changeset patch # User Yuya Nishihara # Date 1294491145 -32400 # Node ID 00411a4fa1bb28630d4b737c4aa8086394fbe941 # Parent a01c52b08c5fbd6347f985e89e58acab00c7717f url: fix UnicodeDecodeError on certificate verification error SSLSocket.getpeercert() returns tuple containing unicode for 'subject'. Since Mercurial does't support IDN at all, it just returns error for non-ascii certname. diff -r a01c52b08c5f -r 00411a4fa1bb mercurial/url.py --- a/mercurial/url.py Sat Jan 08 11:18:38 2011 +0100 +++ b/mercurial/url.py Sat Jan 08 21:52:25 2011 +0900 @@ -498,7 +498,11 @@ for s in cert.get('subject', []): key, value = s[0] if key == 'commonName': - certname = value.lower() + try: + # 'subject' entries are unicode + certname = value.lower().encode('ascii') + except UnicodeEncodeError: + return _('IDN in certificate not supported') if (certname == dnsname or '.' in dnsname and certname == '*.' + dnsname.split('.', 1)[1]): return None diff -r a01c52b08c5f -r 00411a4fa1bb tests/test-url.py --- a/tests/test-url.py Sat Jan 08 11:18:38 2011 +0100 +++ b/tests/test-url.py Sat Jan 08 21:52:25 2011 +0900 @@ -36,3 +36,7 @@ 'no commonName found in certificate') check(_verifycert(None, 'example.com'), 'no certificate received') + +# Unicode (IDN) certname isn't supported +check(_verifycert(cert(u'\u4f8b.jp'), 'example.jp'), + 'IDN in certificate not supported')