diff --git a/mercurial/url.py b/mercurial/url.py --- a/mercurial/url.py +++ b/mercurial/url.py @@ -498,7 +498,11 @@ def _verifycert(cert, hostname): 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 --git a/tests/test-url.py b/tests/test-url.py --- a/tests/test-url.py +++ b/tests/test-url.py @@ -36,3 +36,7 @@ check(_verifycert({'subject': ()}, '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')