Skip to content

Commit fa7de7b

Browse files
committed
fix: use ssl.create_default_context for the TLS server
SonarCloud python:S4423 wants the stdlib helper instead of a bare SSLContext(PROTOCOL_TLS_SERVER); create_default_context selects the hardened cipher suite list, disables compression, and locks in TLS 1.2 minimum (we keep the explicit minimum_version pin as a belt-and-braces check).
1 parent 417dbd0 commit fa7de7b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

je_load_density/utils/socket_server/load_density_socket_server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ def __init__(
5050
self.server: socket.socket = socket.socket(AF_INET, SOCK_STREAM)
5151
self._tls_context: Optional[ssl.SSLContext] = None
5252
if certfile and keyfile:
53-
self._tls_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
54-
# Pin minimum TLS version so older insecure suites cannot be
55-
# negotiated; PROTOCOL_TLS_SERVER alone permits TLS 1.0/1.1.
53+
# create_default_context picks Python's hardened TLS defaults
54+
# (TLS 1.2+ minimum, restricted ciphers, no compression). We
55+
# pin minimum_version explicitly as belt-and-braces in case
56+
# the default ever loosens on an older interpreter.
57+
self._tls_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
5658
self._tls_context.minimum_version = ssl.TLSVersion.TLSv1_2
5759
self._tls_context.load_cert_chain(certfile=certfile, keyfile=keyfile)
5860

0 commit comments

Comments
 (0)