File tree 3 files changed +22
-1
lines changed
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,16 @@ class CertificateError(ValueError):
108
108
pass
109
109
110
110
111
- def _dnsname_to_pat (dn ):
111
+ def _dnsname_to_pat (dn , max_wildcards = 1 ):
112
112
pats = []
113
113
for frag in dn .split (r'.' ):
114
+ if frag .count ('*' ) > max_wildcards :
115
+ # Issue #17980: avoid denials of service by refusing more
116
+ # than one wildcard per fragment. A survery of established
117
+ # policy among SSL implementations showed it to be a
118
+ # reasonable choice.
119
+ raise CertificateError (
120
+ "too many wildcards in certificate DNS name: " + repr (dn ))
114
121
if frag == '*' :
115
122
# When '*' is a fragment by itself, it matches a non-empty dotless
116
123
# fragment.
Original file line number Diff line number Diff line change @@ -326,6 +326,17 @@ def fail(cert, hostname):
326
326
self .assertRaises (ValueError , ssl .match_hostname , None , 'example.com' )
327
327
self .assertRaises (ValueError , ssl .match_hostname , {}, 'example.com' )
328
328
329
+ # Issue #17980: avoid denials of service by refusing more than one
330
+ # wildcard per fragment.
331
+ cert = {'subject' : ((('commonName' , 'a*b.com' ),),)}
332
+ ok (cert , 'axxb.com' )
333
+ cert = {'subject' : ((('commonName' , 'a*b.co*' ),),)}
334
+ ok (cert , 'axxb.com' )
335
+ cert = {'subject' : ((('commonName' , 'a*b*.com' ),),)}
336
+ with self .assertRaises (ssl .CertificateError ) as cm :
337
+ ssl .match_hostname (cert , 'axxbxxc.com' )
338
+ self .assertIn ("too many wildcards" , str (cm .exception ))
339
+
329
340
def test_server_side (self ):
330
341
# server_hostname doesn't work for server sockets
331
342
ctx = ssl .SSLContext (ssl .PROTOCOL_SSLv23 )
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.2.5?
10
10
Library
11
11
-------
12
12
13
+ - Issue #17980: Fix possible abuse of ssl.match_hostname() for denial of
14
+ service using certificates with many wildcards (CVE-2013-2099).
15
+
13
16
- Issue #17192: Restore the patch for Issue #11729 and Issue #10309
14
17
which were omitted in 3.2.4 when updating the bundled version of
15
18
libffi used by ctypes.
You can’t perform that action at this time.
0 commit comments