Skip to content

fix: fail handshake() when the peer certificate is rejected - #174

Merged
larseggert merged 1 commit into
mozilla:mainfrom
uwezkhan:handshake-reject-cert
Aug 31, 2026
Merged

larseggert merged 1 commit into
mozilla:mainfrom
uwezkhan:handshake-reject-cert

Conversation

@uwezkhan

Copy link
Copy Markdown
Contributor

When the application rejects a peer certificate by passing a non-zero status to authenticated(), the next handshake() call runs SSL_AuthCertificateComplete(fd, err) and uses its return value for the state transition. NSS returns SECSuccess from that call even when err rejects the certificate, so the client moves to Complete and is_connected() becomes true while a fatal certificate alert has already been queued. handshake_raw does not have this problem because it always drives SSL_ForceHandshake afterward and transitions on that instead.

On the rejected path the fix now forces the handshake after SSL_AuthCertificateComplete and transitions on that result, which fails as expected. The accepted path (err == 0) still transitions on the SSL_AuthCertificateComplete return, so a valid handshake completes in a single call and only the rejection path gains the extra SSL_ForceHandshake. The added regression test rejects the certificate and asserts that handshake() returns an error with the agent in Failed rather than connected.

@codecov-commenter

codecov-commenter commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.53%. Comparing base (b7d4581) to head (1069478).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   72.30%   72.53%   +0.22%     
==========================================
  Files          28       28              
  Lines        3405     3411       +6     
  Branches     3405     3411       +6     
==========================================
+ Hits         2462     2474      +12     
+ Misses        726      723       -3     
+ Partials      217      214       -3     
Flag Coverage Δ
freebsd 72.53% <100.00%> (+0.22%) ⬆️
linux 72.53% <100.00%> (+0.22%) ⬆️
macos 72.53% <100.00%> (+0.22%) ⬆️
windows 72.53% <100.00%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@martinthomson martinthomson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. The CI failures need attention from other angles, so don't worry too much about them.

@larseggert
larseggert merged commit 8db88a2 into mozilla:main Aug 31, 2026
46 of 54 checks passed
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.

4 participants