Skip to content

Accept a server certificate the system does not trust - #296

Merged
g0shed merged 6 commits into
mainfrom
cert-207
Dec 4, 2026
Merged

g0shed merged 6 commits into
mainfrom
cert-207

Conversation

@g0shed

@g0shed g0shed commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Servers with a company certificate authority, a self-signed certificate or a certificate made for another name could not be used at all. Penguin Mail now shows the certificate and lets the person accept it, as Thunderbird does.

What changes for a person

  • Add Account. When the connection test fails on a certificate, a dialog shows the server and port, why the system refused the certificate, the names it covers, who issued it, the dates it is valid, and the SHA-256 fingerprint in groups of four. It says that someone between the person and the server could read their mail if this is not their server's certificate, and to check the fingerprint with whoever runs the server. Cancel is the default; Accept This Certificate is the destructive button. After Accept the test runs again, so the outgoing server can ask for its own certificate.
  • An account that is already set up. When sync fails on a new or changed certificate, the account shows a Review Certificate banner and a warning in the sidebar. The button opens the same dialog.
  • A changed certificate asks again. A pinned server that shows another certificate never passes silently. The dialog says the certificate changed and shows the old and the new fingerprint.

What is accepted

Exactly one certificate for one host and port on one account: the SHA-256 of the leaf certificate's DER. It is not a CA, not a wildcard and not "skip checks for this server". The handshake signature checks still run. Removing the account removes its pins.

It covers IMAP, SMTP, POP3, ManageSieve, CalDAV and CardDAV. Discovery, Google and Microsoft sign-in and API hosts, JMAP, the web and update checks keep the platform check only and offer nothing. A CalDAV or CardDAV client that signs in with a bearer token is rebuilt without the pin config, so a Google or Microsoft host never offers it.

The 127.0.0.1 Proton Bridge pin works as before.

How it works

  • New crate mailrs-tls builds the ClientConfig for every account connection. Its verifier checks the pin first, then the platform verifier. When the platform refuses, the handshake fails with a typed CertIssue (leaf DER, reason, the previous pin if any). Each protocol error gains a Certificate variant that carries it; reqwest errors are searched through their causes.
  • The pins live in the store (account_certificates, migration 77, deleted with the account) and load into a process-wide list at start. A pin in that list is matched by host and port, so one account's pin also satisfies another account that reaches the same host and port with the same certificate.
  • A new NeedsCertificate account state, and an in-memory note of the certificate each account waits on, drive the banner.
  • x509-parser 0.18 is new (Rusticata project, pure Rust, the usual choice for reading certificates; nothing in the tree parsed names, issuers or dates). rcgen is a test-only dependency (rustls project). No package of the trusted families applies, since this is Rust.

Not done: a settings page listing pins, and the accepted fingerprint in the server settings (no natural place there). Both are outside what the issue asked.

Checked

  • Unit tests for the verifier (match passes, another certificate on a pinned server fails as changed, no pin fails with the reason and the certificate, a pin for another port does not pass), and for the review's words.
  • Against a real TLS server with a self-signed certificate: mailrs-tls, and a CalDAV client through reqwest.
  • Against real Dovecot and an SMTP sink in Docker with a certificate from a root the process does not trust: mailrs_imap::check stops at the IMAP certificate, then at the SMTP one, and passes once both are accepted. A sync test does the first sync and sends one message after accepting.
  • Light, dark, phone width and the changed-certificate dialog and the banner were read as screenshots from the demo.

Fixes #207

Every account connection now builds its TLS config in a shared crate. When the
platform refuses a certificate, the handshake fails with the certificate and the
reason, and a person can accept that exact certificate for that server.
@socket-security

socket-security Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedrcgen@​0.14.109610093100100
Addedx509-parser@​0.18.110010093100100

View full report

@g0shed
g0shed merged commit c31c202 into main Dec 4, 2026
40 of 41 checks passed
@g0shed
g0shed deleted the cert-207 branch December 4, 2026 08:09
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.

Corporative Email server - ERROR AUTH

1 participant