This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients alex, vstinner
Date 2014-11-13.12:52:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1415883149.43.0.395853503644.issue22861@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

I just modified the Trollius project ( http://trollius.readthedocs.org/ ) to support Python 2.7 with the newly backported ssl module. I ran the test suite of the Trollius and some tests are failing because of the exact exception message.

It looks like ssl._dnsname_match() calls repr() on a Unicode string:

    elif len(dnsnames) == 1:
        raise CertificateError("hostname %r "
            "doesn't match %r"
            % (hostname, dnsnames[0]))

Well, I don't know if using repr() on an unicode string is really a bug or not.

By the way, Trollius currently pass the hostname as a bytes string, whereas match_hostname() uses Unicode. No error is raised. Is it safe to compare bytes and Unicode to validate a certificate?

dnsname[0] comes from the commonName of the certificate subject.

The certificate used in Trollius test can be found at:
https://bitbucket.org/enovance/trollius/src/d456dd5103b0e2a35ef27fe0d55583b74a8196dd/tests/keycert3.pem?at=trollius

Example of error:

======================================================================
FAIL: test_create_server_ssl_match_failed (test_events.EPollEventLoopTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_events.py", line 951, in test_create_server_ssl_match_failed
    self.loop.run_until_complete(f_c)
  File "/home/haypo/prog/HG/trollius/trollius/test_utils.py", line 137, in __exit__
    expected_regex.pattern, str(exc_value)))
  File "/home/haypo/prog/HG/trollius/trollius/test_utils.py", line 75, in _raiseFailure
    raise self.test_case.failureException(msg)
AssertionError: "hostname '127.0.0.1' doesn't match 'localhost'" does not match "hostname '127.0.0.1' doesn't match u'localhost'"
History
Date User Action Args
2014-11-13 12:52:29vstinnersetrecipients: + vstinner, alex
2014-11-13 12:52:29vstinnersetmessageid: <1415883149.43.0.395853503644.issue22861@psf.upfronthosting.co.za>
2014-11-13 12:52:29vstinnerlinkissue22861 messages
2014-11-13 12:52:28vstinnercreate