Skip to content

tls: add optional server certificate verification - #5144

Open
KernelClint wants to merge 1 commit into
secdev:masterfrom
KernelClint:tls-optional-server-verification
Open

tls: add optional server certificate verification#5144
KernelClint wants to merge 1 commit into
secdev:masterfrom
KernelClint:tls-optional-server-verification

Conversation

@KernelClint

Copy link
Copy Markdown
Contributor

TLSClientAutomaton completes a handshake and sends application data without checking the server's
certificate against a trust store or the hostname it asked for. It is a test client, and it does
not claim otherwise — but there is no way to ask it to check, which makes it awkward to use against
a real service where that is the point.

The relevant states pass the certificate through without a policy:
scapy/layers/tls/automaton_cli.py:118-142
takes the server name but has no trust store, and :396-405 advances past a TLS 1.2 Certificate
message without authenticating it.

The change adds verification and makes it selectable. When enabled, an explicit CA bundle is used if
one is supplied and the system trust store otherwise, the requested hostname is checked, and the
connection closes on failure. verify=False keeps the current behaviour for the cases where
talking to an untrusted server is the whole point of the exercise.

The added regressions cover a self-signed server, a valid certificate for the wrong hostname, and a
correct server, asserting the first two close the connection and the third completes. Without the
source change they fail.

On cost. Performance was measured on one computer, before and after the fix, but there is not
much of a "before" to measure: the client performs no verification today, so its valid path does
nothing. Verifying took 2.9 µs per handshake, against 819 ns of test overhead — roughly 2.1 µs
added, once per connection, for a full chain and hostname check. A percentage against a path that
does no work would not mean anything, so none is quoted.

AI-Assisted: yes (GPT-5.6-Cyber)
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.38776% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.63%. Comparing base (b3bbcc8) to head (de83345).

Files with missing lines Patch % Lines
scapy/layers/tls/automaton_cli.py 68.75% 15 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5144   +/-   ##
=======================================
  Coverage   80.63%   80.63%           
=======================================
  Files         390      390           
  Lines       96936    96982   +46     
=======================================
+ Hits        78168    78206   +38     
- Misses      18768    18776    +8     
Files with missing lines Coverage Δ
scapy/layers/tls/session.py 86.78% <100.00%> (+0.01%) ⬆️
scapy/layers/tls/automaton_cli.py 86.17% <68.75%> (-0.74%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant