Skip to content

tls: display expiration date when TLS certificate has expired - #167

Open
AdamMagued wants to merge 1 commit into
sourcegraph:masterfrom
AdamMagued:fix-tls-expiry-date
Open

AdamMagued wants to merge 1 commit into
sourcegraph:masterfrom
AdamMagued:fix-tls-expiry-date

Conversation

@AdamMagued

Copy link
Copy Markdown

Problem

When checking a TLS endpoint whose certificate has already expired, tls.DialWithDialer returns an x509.CertificateInvalidError (with reason x509.Expired) during the TLS handshake. As a result:

  1. conns[i] remains nil.
  2. checks[i].Error records the dial error string.
  3. In conclude(), the generic error check triggers first and returns immediately before inspecting peer certificates on the connection.

Solution

  • In Checker.doChecks(), unwrap connection dial errors using errors.As(err, &certErr).
  • When certErr.Reason == x509.Expired and certErr.Cert != nil, extract certErr.Cert.NotAfter and format checks[i].Error with the duration since expiration.
  • Add unit tests in check/tls/tls_test.go verifying that endpoints with expired certificates report Down = true and include the expiration duration in the attempt error output.

Fixes #147

When connecting to an endpoint with an expired certificate,
tls.DialWithDialer fails during the TLS handshake with
x509.CertificateInvalidError (Reason: x509.Expired). Because dial returned
an error, conn was nil and conclude() aborted on result.Times[i].Error
before reaching the connection certificate inspection.

Inspect dial errors for x509.CertificateInvalidError in doChecks, extract
the certificate expiration timestamp, and record the expiration duration in
the attempt error.

Fixes sourcegraph#147

Signed-off-by: AdamMagued <adamismailmageud@gmail.com>

This branch has not been deployed

No deployments
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.

Expired TLS check doesn't display expiration date

1 participant