Repository: scrapy/scrapy

Issue:
Match pyOpenSSL and service_identity to Twisted
Resolves #5621

Signed-off-by: Gábor Lipták <gliptak@gmail.com>

Correcting https://github.com/scrapy/scrapy/actions/runs/3052958225/jobs/4922962575

```
    from twisted.internet import error, tcp, udp
.tox/py/lib/python3.8/site-packages/twisted/internet/tcp.py:38: in <module>
    from twisted.internet._newtls import (
.tox/py/lib/python3.8/site-packages/twisted/internet/_newtls.py:18: in <module>
    from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
.tox/py/lib/python3.8/site-packages/twisted/protocols/tls.py:45: in <module>
    from twisted.internet._sslverify import _setAcceptableProtocols
.tox/py/lib/python3.8/site-packages/twisted/internet/_sslverify.py:1828: in <module>
    defaultCiphers = OpenSSLAcceptableCiphers.fromOpenSSLCipherString(
.tox/py/lib/python3.8/site-packages/twisted/internet/_sslverify.py:1807: in fromOpenSSLCipherString
    SSL.TLS_METHOD,
E   AttributeError: module 'OpenSSL.SSL' has no attribute 'TLS_METHOD'
```
SSLv3_METHOD where did you come from???????????????
[WHAT THE F](https://github.com/scrapy/scrapy/blob/1.5.0/scrapy/core/downloader/tls.py#L17)

does not exist in pyopenssl

no help anywhere


Discussion:
# [Codecov](https://codecov.io/gh/scrapy/scrapy/pull/5632?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) Report
> Merging [#5632](https://codecov.io/gh/scrapy/scrapy/pull/5632?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) (385acd5) into [master](https://codecov.io/gh/scrapy/scrapy/commit/5f194202114fd38530c78299d51b6966b4802f59?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) (5f19420) will **increase** coverage by `0.19%`.
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff             @@
##           master    #5632      +/-   ##
==========================================
+ Coverage   88.66%   88.85%   +0.19%     
==========================================
  Files         162      162              
  Lines       10965    10965              
  Branches     1894     1894              
==========================================
+ Hits         9722     9743      +21     
+ Misses        963      942      -21     
  Partials      280      280              
```

| [Impacted Files](https://codecov.io/gh/scrapy/scrapy/pull/5632?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy) | Coverage Δ | |
|---|---|---|
| [scrapy/core/downloader/handlers/http11.py](https://codecov.io/gh/scrapy/scrapy/pull/5632/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy#diff-c2NyYXB5L2NvcmUvZG93bmxvYWRlci9oYW5kbGVycy9odHRwMTEucHk=) | `94.11% <0.00%> (+0.98%)` | :arrow_up: |
| [scrapy/robotstxt.py](https://codecov.io/gh/scrapy/scrapy/pull/5632/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scrapy#diff-c2NyYXB5L3JvYm90c3R4dC5weQ==) | `97.53% <0.00%> (+22.22%)` | :arrow_up: |

> @wRAR I would like to hear from you if you think there is some other approach we should explore here.

Nevermind, I believe you were already aware of this, we were just deciding whether the side effect (not supporting TLS ≤1.1) was OK.
Thanks @gliptak!
It seems tests are failing now with a different error, weird! See e.g. https://github.com/scrapy/scrapy/actions/runs/3123148006/jobs/5065580786 - there's a lot of errors like this:

> ___________________ ERROR collecting tests/test_webclient.py ___________________
tests/test_webclient.py:23: in <module>
    from scrapy.core.downloader.contextfactory import ScrapyClientContextFactory
scrapy/core/downloader/contextfactory.py:11: in <module>
    from scrapy.core.downloader.tls import DEFAULT_CIPHERS, openssl_methods, ScrapyClientTLSOptions
scrapy/core/downloader/tls.py:23: in <module>
    METHOD_SSLv3: SSL.SSLv3_METHOD,                     # SSL 3 (NOT recommended)
E   AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv3_METHOD'



Resolving patch:
diff --git a/scrapy/core/downloader/contextfactory.py b/scrapy/core/downloader/contextfactory.py
--- a/scrapy/core/downloader/contextfactory.py
+++ b/scrapy/core/downloader/contextfactory.py
@@ -21,7 +21,7 @@ class ScrapyClientContextFactory(BrowserLikePolicyForHTTPS):
     which allows TLS protocol negotiation
 
     'A TLS/SSL connection established with [this method] may
-     understand the SSLv3, TLSv1, TLSv1.1 and TLSv1.2 protocols.'
+     understand the TLSv1, TLSv1.1 and TLSv1.2 protocols.'
     """
 
     def __init__(self, method=SSL.SSLv23_METHOD, tls_verbose_logging=False, tls_ciphers=None, *args, **kwargs):
diff --git a/scrapy/core/downloader/tls.py b/scrapy/core/downloader/tls.py
--- a/scrapy/core/downloader/tls.py
+++ b/scrapy/core/downloader/tls.py
@@ -11,7 +11,6 @@
 logger = logging.getLogger(__name__)
 
 
-METHOD_SSLv3 = 'SSLv3'
 METHOD_TLS = 'TLS'
 METHOD_TLSv10 = 'TLSv1.0'
 METHOD_TLSv11 = 'TLSv1.1'
@@ -20,7 +19,6 @@
 
 openssl_methods = {
     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


Test patch: