mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-11 01:02:10 +03:00
Refactor tls_findings into smaller helper functions. (#28)
This change splits the large `tls_findings` function in `src/netsleuth/interpret.py` into three focused helper functions (`_check_tls_error`, `_check_tls_performance`, and `_check_tls_certificate`) to improve readability and maintainability. Also fixes unused imports identified by ruff. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
parent
03d54b900c
commit
38e967bf43
1 changed files with 133 additions and 116 deletions
|
|
@ -755,12 +755,10 @@ def _cpu_bound_ratio(tls_handshake_ms: float | None, tcp_rtt_ms: float | None) -
|
|||
return tls_handshake_ms / tcp_rtt_ms
|
||||
|
||||
|
||||
def tls_findings(results: list[TlsResult], t: Thresholds) -> list[Finding]:
|
||||
findings: list[Finding] = []
|
||||
for r in results:
|
||||
if r.error:
|
||||
findings.append(
|
||||
Finding(
|
||||
def _check_tls_error(r: TlsResult) -> Finding | None:
|
||||
if not r.error:
|
||||
return None
|
||||
return Finding(
|
||||
id=f"tls.unreachable.{r.label}",
|
||||
severity="warn",
|
||||
title=f"TLS handshake to {r.host} failed",
|
||||
|
|
@ -772,8 +770,10 @@ def tls_findings(results: list[TlsResult], t: Thresholds) -> list[Finding]:
|
|||
detail_ru=f"Не удалось установить TLS-соединение с {r.host}:{r.port}: {r.error}",
|
||||
advice_ru="Сервис может быть недоступен, либо порт заблокирован на пути к серверу.",
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
|
||||
def _check_tls_performance(r: TlsResult, t: Thresholds) -> list[Finding]:
|
||||
findings: list[Finding] = []
|
||||
ratio = _cpu_bound_ratio(r.tls_handshake_ms, r.tcp_rtt_ms)
|
||||
if ratio is not None and ratio > t.tls_cpu_bound_ratio and (r.tls_handshake_ms or 0.0) >= 20.0:
|
||||
findings.append(
|
||||
|
|
@ -825,6 +825,11 @@ def tls_findings(results: list[TlsResult], t: Thresholds) -> list[Finding]:
|
|||
advice_ru="Медленный TTFB при быстром рукопожатии указывает на обработку на стороне сервера, а не на сеть.",
|
||||
)
|
||||
)
|
||||
return findings
|
||||
|
||||
|
||||
def _check_tls_certificate(r: TlsResult) -> list[Finding]:
|
||||
findings: list[Finding] = []
|
||||
if r.pin_verdict == "mismatch":
|
||||
findings.append(
|
||||
Finding(
|
||||
|
|
@ -878,6 +883,18 @@ def tls_findings(results: list[TlsResult], t: Thresholds) -> list[Finding]:
|
|||
return findings
|
||||
|
||||
|
||||
def tls_findings(results: list[TlsResult], t: Thresholds) -> list[Finding]:
|
||||
findings: list[Finding] = []
|
||||
for r in results:
|
||||
err = _check_tls_error(r)
|
||||
if err:
|
||||
findings.append(err)
|
||||
continue
|
||||
findings.extend(_check_tls_performance(r, t))
|
||||
findings.extend(_check_tls_certificate(r))
|
||||
return findings
|
||||
|
||||
|
||||
def prefix_findings(bench: PrefixBenchmark, t: Thresholds) -> list[Finding]:
|
||||
findings: list[Finding] = []
|
||||
if not bench.results:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue