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

Fix return certificate expiry time from NearExpiration #29128

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions changelog/29128.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
vault/diagnose: Fix time to expiration reporting within the TLS verification to not be a month off.
```
18 changes: 10 additions & 8 deletions vault/diagnose/tls_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,17 @@ func TLSFileWarningChecks(leafCerts, interCerts, rootCerts []*x509.Certificate)
return warnings, nil
}

// NearExpiration returns a true if a certficate will expire in a month and false otherwise
// NearExpiration returns a true if a certificate will expire in a month
// and false otherwise, along with the duration until the certificate expires
// which can be a negative duration if the certificate has already expired.
func NearExpiration(c *x509.Certificate) (bool, time.Duration) {
oneMonthFromNow := time.Now().Add(30 * 24 * time.Hour)
var timeToExpiry time.Duration
if oneMonthFromNow.After(c.NotAfter) {
timeToExpiry := oneMonthFromNow.Sub(c.NotAfter)
return true, timeToExpiry
}
return false, timeToExpiry
now := time.Now()
timeToExpiry := c.NotAfter.Sub(now)

oneMonthFromNow := now.Add(30 * 24 * time.Hour)
hasExpired := oneMonthFromNow.After(c.NotAfter)
stevendpclark marked this conversation as resolved.
Show resolved Hide resolved

return hasExpired, timeToExpiry
}

// TLSMutualExclusionCertCheck returns error if both TLSDisableClientCerts and TLSRequireAndVerifyClientCert are set
Expand Down
Loading