Skip to content

Commit fcd3f7e

Browse files
committed
Generate default ciphers using approach from #1501
1 parent 8e56e9f commit fcd3f7e

File tree

3 files changed

+16
-45
lines changed

3 files changed

+16
-45
lines changed

httpie/cli/definition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
get_available_styles)
2121
from httpie.plugins.builtin import BuiltinAuthPlugin
2222
from httpie.plugins.registry import plugin_manager
23-
from httpie.ssl_ import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS
23+
from httpie.ssl_ import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS_STRING
2424

2525
options = ParserSpec(
2626
'http',
@@ -832,9 +832,9 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False):
832832
help=f"""
833833
834834
A string in the OpenSSL cipher list format. By default, the following
835-
is used:
835+
ciphers are used on your system:
836836
837-
{DEFAULT_SSL_CIPHERS}
837+
{DEFAULT_SSL_CIPHERS_STRING}
838838
839839
""",
840840
)

httpie/ssl_.py

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,7 @@
88
resolve_ssl_version,
99
)
1010

11-
# We used to import default SSL ciphers via `SSL_CIPHERS` from `urllib3` but it’s been removed,
12-
# so we’ve copied the original list here.
13-
# Our issue: <https://github.com/httpie/httpie/issues/1499>
14-
# Removal commit: <https://github.com/urllib3/urllib3/commit/e5eac0c>
15-
DEFAULT_SSL_CIPHERS = ":".join([
16-
# <urllib3>
17-
# A secure default.
18-
# Sources for more information on TLS ciphers:
19-
#
20-
# - https://wiki.mozilla.org/Security/Server_Side_TLS
21-
# - https://www.ssllabs.com/projects/best-practices/index.html
22-
# - https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
23-
#
24-
# The general intent is:
25-
# - prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE),
26-
# - prefer ECDHE over DHE for better performance,
27-
# - prefer any AES-GCM and ChaCha20 over any AES-CBC for better performance and
28-
# security,
29-
# - prefer AES-GCM over ChaCha20 because hardware-accelerated AES is common,
30-
# - disable NULL authentication, MD5 MACs, DSS, and other
31-
# insecure ciphers for security reasons.
32-
# - NOTE: TLS 1.3 cipher suites are managed through a different interface
33-
# not exposed by CPython (yet!) and are enabled by default if they're available.
34-
"ECDHE+AESGCM",
35-
"ECDHE+CHACHA20",
36-
"DHE+AESGCM",
37-
"DHE+CHACHA20",
38-
"ECDH+AESGCM",
39-
"DH+AESGCM",
40-
"ECDH+AES",
41-
"DH+AES",
42-
"RSA+AESGCM",
43-
"RSA+AES",
44-
"!aNULL",
45-
"!eNULL",
46-
"!MD5",
47-
"!DSS",
48-
"!AESCCM",
49-
# </urllib3>
50-
])
11+
5112
SSL_VERSION_ARG_MAPPING = {
5213
'ssl2.3': 'PROTOCOL_SSLv23',
5314
'ssl3': 'PROTOCOL_SSLv3',
@@ -119,6 +80,10 @@ def _create_ssl_context(
11980
cert_reqs=ssl.CERT_REQUIRED if verify else ssl.CERT_NONE
12081
)
12182

83+
@classmethod
84+
def get_default_ciphers_names(cls):
85+
return [cipher['name'] for cipher in cls._create_ssl_context(verify=False).get_ciphers()]
86+
12287

12388
def _is_key_file_encrypted(key_file):
12489
"""Detects if a key file is encrypted or not.
@@ -132,3 +97,9 @@ def _is_key_file_encrypted(key_file):
13297
return True
13398

13499
return False
100+
101+
102+
# We used to import the default set of TLS ciphers from urllib3, but they removed it.
103+
# Instead, now urllib3 uses the list of ciphers configured by the system.
104+
# <https://github.com/httpie/httpie/pull/1501>
105+
DEFAULT_SSL_CIPHERS_STRING = ':'.join(HTTPieHTTPSAdapter.get_default_ciphers_names())

tests/test_ssl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from unittest import mock
99

10-
from httpie.ssl_ import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS
10+
from httpie.ssl_ import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS_STRING
1111
from httpie.status import ExitStatus
1212

1313
from .utils import HTTP_OK, TESTS_ROOT, IS_PYOPENSSL, http
@@ -146,7 +146,7 @@ def test_ciphers(httpbin_secure):
146146
r = http(
147147
httpbin_secure.url + '/get',
148148
'--ciphers',
149-
DEFAULT_SSL_CIPHERS,
149+
DEFAULT_SSL_CIPHERS_STRING,
150150
)
151151
assert HTTP_OK in r
152152

0 commit comments

Comments
 (0)