"ssl" module doesn't validate that domain of certificate is correct
nagle at animats.com
Mon Apr 19 19:49:19 CEST 2010
exarkun at twistedmatrix.com wrote:
> On 04:51 pm, nagle at animats.com wrote:
>> I'm converting some code from M2Crypto to the new "ssl" module, and
>> I've found what looks like a security hole. The "ssl" module will
>> validate the certificate chain, but it doesn't check that the certificate
>> is valid for the domain.
> It's a bit debatable. There probably should be a way to make this
> happen, but it's far from clear that it's the only correct behavior.
> And, as it turns out, there is a way to make it happen - call
> getpeercert() and perform the check yourself. ;)
"Checking it yourself" is non-trivial. The checking code has to
understand DNS wildcards and additional domains in cert extensions.
The SSL module doesn't seem to let you read all the cert extensions,
(in particular, you don't get "certificatePolicies", so you can't
tell if a cert is an "extended validation" cert) but it looks like
you do get the subjectAltName fields present in the extensions, like this:
subjectAltName = (('DNS', 'www.chapinfurniture.com'),
So it's at least possible to check. Almost.
(DNS wildcards look like this: "*.example.com". It's also possible
to have "*.*.example.com". However, no DNS wildcard cert should cover
more than one second-level domain (huge security hole if you allow that)
and no extended validation cert should have a wildcard.)
There may also be issues with internationalized domain names.
It's very bad for the "ssl" module to both ignore this check and
not have that mentioned prominently in the documentation. This is
a security-critical function. Somewhere, there's a Python program that
can be exploited due to this bug.
Here's a comparison of what M2Crypto and the SSL module return, for
"verisign.com", which uses most cert features.
Trying domain "www.verisign.com"
Host: www.verisign.com Port: 443
Info from "M2Crypto: module:
Cipher = DHE-RSA-AES256-SHA
Subject info: [('CN', 'verisign.com'),
('OU', 'production Security Services '),
('O', 'VeriSign, Inc.'),
('streetAddress', '487 East Middlefield Road'),
('L', 'Mountain View'),
('22.214.171.124', 'V1.0, Clause 5.(b)'),
Certificate has 10 extensions.
Extension #0: subjectAltName = DNS:verisign.com, DNS:www.verisign.com,
DNS:verisign.mobi, DNS:www.verisign.mobi, DNS:verisign.eu, DN
Extension #1: basicConstraints = CA:FALSE
Extension #2: subjectKeyIdentifier =
Extension #3: keyUsage = Digital Signature, Key Encipherment
Extension #4: crlDistributionPoints =
Extension #5: certificatePolicies = Policy: 2.16.840.1.1137126.96.36.199.6
Extension #6: extendedKeyUsage = TLS Web Server Authentication, TLS Web Client
Authentication, Netscape Server Gated Crypto
Extension #7: authorityKeyIdentifier =
Extension #8: authorityInfoAccess = OCSP - URI:http://EVIntl-ocsp.verisign.com
CA Issuers - URI:http://EVIntl-aia.verisign.com/EVIntl2006.cer
Extension #9: UNDEF = None
Info from "ssl" module:
SSL cert for "www.verisign.com":
notAfter = Apr 2 23:59:59 2012 GMT
subject = ((('188.8.131.52.4.1.3184.108.40.206.3', u'US'),),
(('220.127.116.11', u'V1.0, Clause 5.(b)'),),
(('localityName', u'Mountain View'),),
(('streetAddress', u'487 East Middlefield Road'),),
(('organizationName', u'VeriSign, Inc.'),),
(('organizationalUnitName', u'production Security Services '),),
More information about the Python-list