Skip to content

Commit 1cc2b49

Browse files
committed
fix(net.py): use ssl.PROTOCOL_TLS_CLIENT as "best practice" in fetch_ssl()
1 parent d9b4fe8 commit 1cc2b49

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,37 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
1010

1111
## [Unreleased]
1212

13-
tbd
13+
### Fixed ("fix")
14+
15+
* fix(net.py): use `ssl.PROTOCOL_TLS_CLIENT` as "best practice" in `fetch_ssl()`
16+
1417

1518

1619
## v2.2.0
1720

18-
### Changed ("refactor", "chore", "feat" etc.)
21+
### Added ("feat")
1922

2023
* feat(time.py): add `get_timezone()`
24+
25+
26+
### Changed ("refactor", "chore" etc.)
27+
2128
* refactor(net.py): force `fetch_ssl()` to use TLS 1.2+
2229
* refactor(txt.py): enhance sanitize regex
2330

2431

32+
2533
## v2.1.1.15
2634

27-
### Changed ("refactor", "chore", "feat" etc.)
35+
### Changed ("refactor", "chore" etc.)
2836

2937
* refactor(net.py): add fetch_socket() and fetch_ssl(), improve fetch()
3038

3139

40+
3241
## v2.1.1.7
3342

34-
### Changed ("refactor", "chore", "feat" etc.)
43+
### Changed ("refactor", "chore" etc.)
3544

3645
* refactor(args.py): improve code-style
3746
* refactor(base.py): improve code-style
@@ -79,7 +88,7 @@ tbd
7988
* shell.py: Fix special character decoding in Windows output by explicitly switching to codepage 65001
8089

8190

82-
### Changed ("refactor", "chore", "feat" etc.)
91+
### Changed ("refactor", "chore" etc.)
8392

8493
* docs: improve and convert doc strings to markdown for some libs and create new `docs` folder using `pdoc`
8594
* refactor(base.py, url.py): make use of txt.sanitize_sensitive_data()
@@ -97,7 +106,7 @@ tbd
97106

98107
## v2.1.0.4
99108

100-
### Changed ("refactor", "chore", "feat" etc.)
109+
### Changed ("refactor", "chore" etc.)
101110

102111
* refactor: uptimerobot.py
103112

@@ -110,7 +119,7 @@ tbd
110119
* feat: add uptimerobot.py
111120

112121

113-
### Changed ("refactor", "chore", "feat" etc.)
122+
### Changed ("refactor", "chore" etc.)
114123

115124
* docs(base.py): improve doc strings
116125

@@ -123,7 +132,7 @@ tbd
123132
* fix(txt.py): extract_str()
124133

125134

126-
### Changed ("refactor", "chore", "feat" etc.)
135+
### Changed ("refactor", "chore" etc.)
127136

128137
* chore(endoflifedate.py): bump version numbers
129138
* chore(tools/update-endoflifedate): add openvpn
@@ -159,7 +168,7 @@ Build, CI/CD:
159168
* keycloak.py: This library collects some Keycloak related functions that are needed by more than one Keycloak plugin.
160169

161170

162-
### Changed ("refactor", "chore", "feat" etc.)
171+
### Changed ("refactor", "chore" etc.)
163172

164173
* librenms.py: `get_state()` returns STATE_OK instead of STATE_UNKNOWN
165174
* url.py: Improve error messages and comments

net.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
16-
__version__ = '2025052001'
16+
__version__ = '2025053001'
1717

1818
import random
1919
import re
@@ -327,10 +327,14 @@ def fetch_ssl(host, port, msg=None, timeout=3):
327327
>>> success, response = fetch_ssl('example.com', 443, b'GET / HTTP/1.0\\r\\nHost: example.com\\r\\n\\r\\n')
328328
"""
329329
def open_ssl_socket():
330-
context = ssl.create_default_context()
331-
# forcing TLS 1.2+
332-
ctx.options |= ssl.OP_NO_TLSv1
333-
ctx.options |= ssl.OP_NO_TLSv1_1
330+
# PROTOCOL_TLS_CLIENT automatically disables SSLv2/3 and
331+
# TLSv1.0/1.1 on recent OpenSSL builds
332+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
333+
334+
# context.check_hostname = True
335+
# context.verify_mode = ssl.CERT_REQUIRED
336+
context.minimum_version = ssl.TLSVersion.TLSv1_2 # enforce at least TLS 1.2 just to be sure
337+
334338
raw_sock = socket.socket(socket.AF_INET, SOCK_TCP)
335339
return context.wrap_socket(raw_sock, server_hostname=host)
336340

0 commit comments

Comments
 (0)