Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiet OCSP warnings if the cert has a short lifetime #320

Merged
merged 4 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func (cert Certificate) Expired() bool {
return time.Now().After(expiresAt(cert.Leaf))
}

// Lifetime returns the duration of the certificate's validity.
func (cert Certificate) Lifetime() time.Duration {
if cert.Leaf == nil || cert.Leaf.NotAfter.IsZero() {
return 0
}
return expiresAt(cert.Leaf).Sub(cert.Leaf.NotBefore)
}

// currentlyInRenewalWindow returns true if the current time is within
// (or after) the renewal window, according to the given start/end
// dates and the ratio of the renewal window. If true is returned,
Expand Down
11 changes: 8 additions & 3 deletions ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ func stapleOCSP(ctx context.Context, ocspConfig OCSPConfig, storage Storage, cer
// then we need to request it from the OCSP responder
if ocspResp == nil || len(ocspBytes) == 0 {
ocspBytes, ocspResp, ocspErr = getOCSPForCert(ocspConfig, pemBundle)
// An error here is not a problem because a certificate
// may simply not contain a link to an OCSP server.
if ocspErr != nil {
// An error here is not a problem because a certificate may simply
// not contain a link to an OCSP server. But we should log it anyway.
// For short-lived certificates, this is fine and we can ignore
// logging because OCSP doesn't make much sense for them anyway.
if cert.Lifetime() < 7*24*time.Hour {
return nil
}
// There's nothing else we can do to get OCSP for this certificate,
// so we can return here with the error.
// so we can return here with the error to warn about it.
return fmt.Errorf("no OCSP stapling for %v: %w", cert.Names, ocspErr)
}
gotNewOCSP = true
Expand Down
Loading