Security

Verifying a certificate correctly from C#

Duende Software Blog Khalid Abuhakmeh, Maarten Balliauw
Security

Duende's team explains why silencing TLS errors with a callback that returns true undermines the whole point of HTTPS, then shows the correct path: `X509Chain`, revocation checking, custom trust stores and SAN or thumbprint validation. A practical reference for any .NET developer who would rather verify a certificate than suppress the error.

Key points

  • `X509CertificateLoader` (.NET 9) makes the format explicit; several `X509Certificate2` constructors are obsolete.
  • Always log `ChainStatus` when `X509Chain.Build` returns false; swallowing it makes production TLS failures undebuggable.
  • Use `RevocationMode.Online` for security-sensitive flows; keep `NoCheck` for documented, network-isolated scenarios only.
  • `X509ChainTrustMode.CustomRootTrust` ignores the OS root store and trusts only the roots you add.
  • Match hosts with `X509SubjectAlternativeNameExtension.EnumerateDnsNames()`; common name fallback is no longer honored.
  • In `ServerCertificateCustomValidationCallback`, return false when `sslErrors` is populated instead of discarding the built-in verdict.

Real-world use

  • Service-to-service mTLS where both sides present certificates from an internal CA
  • Background jobs that validate a signing certificate or a client certificate
  • Sensitive internal service calls pinned to a specific issuer or thumbprint

This summary was generated by the agent from the original post on Duende Software Blog. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message