File 0001-Use-ssl_match_hostname-from-backports.patch of Package python-pymongo
From 2e070782c83040ae61e45642ca5ec98554c3082b Mon Sep 17 00:00:00 2001
From: Randy Barlow <randy@electronsweatshop.com>
Date: Tue, 2 Feb 2016 19:22:55 -0500
Subject: [PATCH] Use ssl_match_hostname from backports.
Fixes CVE-2013-2099 and CVE-2013-7440.
---
pymongo/errors.py | 2 +-
pymongo/pool.py | 2 +-
pymongo/ssl_match_hostname.py | 62 -------------------------------------------
3 files changed, 2 insertions(+), 64 deletions(-)
delete mode 100644 pymongo/ssl_match_hostname.py
diff --git a/pymongo/errors.py b/pymongo/errors.py
index 63577be..2c2484c 100644
--- a/pymongo/errors.py
+++ b/pymongo/errors.py
@@ -19,7 +19,7 @@ from bson.errors import *
try:
from ssl import CertificateError
except ImportError:
- from pymongo.ssl_match_hostname import CertificateError
+ from backports.ssl_match_hostname import CertificateError
class PyMongoError(Exception):
diff --git a/pymongo/pool.py b/pymongo/pool.py
index af18183..3ed27c6 100644
--- a/pymongo/pool.py
+++ b/pymongo/pool.py
@@ -27,7 +27,7 @@ from pymongo.errors import (CertificateError, ConnectionFailure,
try:
from ssl import match_hostname
except ImportError:
- from pymongo.ssl_match_hostname import match_hostname
+ from backports.ssl_match_hostname import match_hostname
if HAS_SSL:
import ssl
diff --git a/pymongo/ssl_match_hostname.py b/pymongo/ssl_match_hostname.py
deleted file mode 100644
index 840f4d1..0000000
--- a/pymongo/ssl_match_hostname.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# Backport of the match_hostname logic introduced in python 3.2
-# http://svn.python.org/projects/python/branches/release32-maint/Lib/ssl.py
-
-import re
-
-
-class CertificateError(ValueError):
- pass
-
-
-def _dnsname_to_pat(dn):
- pats = []
- for frag in dn.split(r'.'):
- if frag == '*':
- # When '*' is a fragment by itself, it matches a non-empty dotless
- # fragment.
- pats.append('[^.]+')
- else:
- # Otherwise, '*' matches any dotless fragment.
- frag = re.escape(frag)
- pats.append(frag.replace(r'\*', '[^.]*'))
- return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
-
-
-def match_hostname(cert, hostname):
- """Verify that *cert* (in decoded format as returned by
- SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules
- are mostly followed, but IP addresses are not accepted for *hostname*.
-
- CertificateError is raised on failure. On success, the function
- returns nothing.
- """
- if not cert:
- raise ValueError("empty or no certificate")
- dnsnames = []
- san = cert.get('subjectAltName', ())
- for key, value in san:
- if key == 'DNS':
- if _dnsname_to_pat(value).match(hostname):
- return
- dnsnames.append(value)
- if not san:
- # The subject is only checked when subjectAltName is empty
- for sub in cert.get('subject', ()):
- for key, value in sub:
- # XXX according to RFC 2818, the most specific Common Name
- # must be used.
- if key == 'commonName':
- if _dnsname_to_pat(value).match(hostname):
- return
- dnsnames.append(value)
- if len(dnsnames) > 1:
- raise CertificateError("hostname %r "
- "doesn't match either of %s"
- % (hostname, ', '.join(map(repr, dnsnames))))
- elif len(dnsnames) == 1:
- raise CertificateError("hostname %r "
- "doesn't match %r"
- % (hostname, dnsnames[0]))
- else:
- raise CertificateError("no appropriate commonName or "
- "subjectAltName fields were found")
--
2.7.0