From 095495e99ce327d0fc6cf2064f8a6d871d2f7dd1 Mon Sep 17 00:00:00 2001 From: Paul Tremberth Date: Wed, 24 Feb 2016 01:24:58 +0100 Subject: [PATCH] Backward-compatibility for common Scrapy context factory patterns --- scrapy/core/downloader/contextfactory.py | 13 ++++++++++++- scrapy/core/downloader/tls.py | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/scrapy/core/downloader/contextfactory.py b/scrapy/core/downloader/contextfactory.py index afc52c354..09fcd491a 100644 --- a/scrapy/core/downloader/contextfactory.py +++ b/scrapy/core/downloader/contextfactory.py @@ -30,7 +30,18 @@ try: def getCertificateOptions(self): # setting verify=True will require you to provide CAs # to verify against; in other words: it's not that simple - return CertificateOptions(verify=False, method=self._ssl_method) + + # backward-compatible SSL/TLS method: + # + # * this will respect `method` attribute in often recommended + # `ScrapyClientContextFactory` subclass + # (https://github.com/scrapy/scrapy/issues/1429#issuecomment-131782133) + # + # * getattr() for `_ssl_method` attribute for context factories + # not calling super(..., self).__init__ + return CertificateOptions(verify=False, + method=getattr(self, 'method', + getattr(self, '_ssl_method', None))) # kept for old-style HTTP/1.0 downloader context twisted calls, # e.g. connectSSL() diff --git a/scrapy/core/downloader/tls.py b/scrapy/core/downloader/tls.py index 121ee83ac..64ebb0714 100644 --- a/scrapy/core/downloader/tls.py +++ b/scrapy/core/downloader/tls.py @@ -8,8 +8,8 @@ METHOD_TLSv11 = 'TLSv1.1' METHOD_TLSv12 = 'TLSv1.2' openssl_methods = { - METHOD_TLS: SSL.SSLv23_METHOD, # protocol negotiation (recommended) - METHOD_SSLv3: SSL.SSLv3_METHOD, # SSL 3 (NOT recommended) + METHOD_TLS: SSL.SSLv23_METHOD, # protocol negotiation (recommended) + METHOD_SSLv3: SSL.SSLv3_METHOD, # SSL 3 (NOT recommended) METHOD_TLSv10: SSL.TLSv1_METHOD, # TLS 1.0 only METHOD_TLSv11: getattr(SSL, 'TLSv1_1_METHOD', 5), # TLS 1.1 only METHOD_TLSv12: getattr(SSL, 'TLSv1_2_METHOD', 6), # TLS 1.2 only