Skip to content

Commit 0033441

Browse files
committed
Move S5527/S4830 + nosemgrep suppressions onto the lines Sonar/Codacy flag
S5527 attaches to the SSLContext(PROTOCOL_TLS_CLIENT) constructor, not to the assignment that sets check_hostname=False. Extract the two GUI client-context paths into module-level _build_verifying_client_context / _build_insecure_client_context, and put NOSONAR S4830 S5527 on the def line of the insecure builder so the suppression sits on the line Sonar's flow analysis blames (test_remote_desktop_tls.py gets the same treatment). Codacy / Opengrep wants the suppression token on the same line as the call; relocate the nosemgrep marker next to the existing nosec B324 on the hashlib.sha1(...) line and use the rule path the scanner actually emits (python.lang.security.insecure-hash-algorithms... — no '.audit').
1 parent 80fd9b5 commit 0033441

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

je_auto_control/gui/remote_desktop_tab.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ def _scroll_amount(angle_delta: int) -> int:
109109
return 0
110110

111111

112+
def _build_verifying_client_context() -> ssl.SSLContext:
113+
"""TLS client context with full hostname + cert verification enabled."""
114+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
115+
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
116+
ctx.load_default_certs()
117+
ctx.check_hostname = True
118+
ctx.verify_mode = ssl.CERT_REQUIRED
119+
return ctx
120+
121+
122+
def _build_insecure_client_context() -> ssl.SSLContext: # NOSONAR S4830 S5527
123+
"""Opt-in self-signed loopback context — verification intentionally off.
124+
125+
Triggered only when the user ticks 'Skip cert verification' on the
126+
Viewer panel; meant for self-signed dev / LAN hosts where the user
127+
has already pinned the host out-of-band (token + 9-digit Host ID).
128+
"""
129+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
130+
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
131+
ctx.check_hostname = False
132+
ctx.verify_mode = ssl.CERT_NONE
133+
return ctx
134+
135+
112136
class _FrameDisplay(QWidget):
113137
"""Paints the latest frame and emits remapped input events.
114138
@@ -713,17 +737,9 @@ def _build_client_ssl_context(
713737
self, transport: str) -> Optional[ssl.SSLContext]:
714738
if transport not in ("TLS", "WSS"):
715739
return None
716-
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
717-
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
718740
if self._tls_insecure.isChecked():
719-
# Explicit user opt-in for self-signed loopback / dev hosts.
720-
ctx.check_hostname = False # NOSONAR S5527
721-
ctx.verify_mode = ssl.CERT_NONE # NOSONAR S4830
722-
else:
723-
ctx.load_default_certs()
724-
ctx.check_hostname = True
725-
ctx.verify_mode = ssl.CERT_REQUIRED
726-
return ctx
741+
return _build_insecure_client_context()
742+
return _build_verifying_client_context()
727743

728744
def _start_audio_player_if_requested(self) -> None:
729745
if not (self._enable_audio.isChecked()

je_auto_control/utils/remote_desktop/ws_protocol.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ def _compute_accept(key: str) -> str:
134134
# RFC 6455 mandates SHA-1 for the Sec-WebSocket-Accept handshake;
135135
# ``usedforsecurity=False`` tells linters this is a protocol-required
136136
# checksum, not a cryptographic primitive.
137-
# nosemgrep: python.lang.security.audit.insecure-hash-algorithms.insecure-hash-algorithm-sha1
138-
digest = hashlib.sha1( # nosec B324 # reason: RFC 6455 handshake
137+
digest = hashlib.sha1( # nosec B324 # nosemgrep: python.lang.security.insecure-hash-algorithms.insecure-hash-algorithm-sha1
139138
key.encode("ascii") + WS_GUID,
140139
usedforsecurity=False,
141140
).digest()

test/unit_test/headless/test_remote_desktop_tls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ def _trusting_client_context(ca_path: Path) -> ssl.SSLContext:
8888
return ctx
8989

9090

91-
def _insecure_client_context() -> ssl.SSLContext:
91+
def _insecure_client_context() -> ssl.SSLContext: # NOSONAR S4830 S5527
9292
"""Self-signed loopback test context — verification deliberately off."""
9393
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
9494
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
95-
ctx.check_hostname = False # NOSONAR S5527 # loopback self-signed test
96-
ctx.verify_mode = ssl.CERT_NONE # NOSONAR S4830 # loopback self-signed test
95+
ctx.check_hostname = False
96+
ctx.verify_mode = ssl.CERT_NONE
9797
return ctx
9898

9999

0 commit comments

Comments
 (0)