Skip to content

Commit 440c695

Browse files
authored
CA: Truncate notBefore and notAfter to second-level precision (#8319)
When generating the validity period of a to-be-issued certificate, truncate the notBefore timestamp to second-level precision, trimming off any nanoseconds which won't be represented in the final certificate. Do the same for the notAfter, although this should be a no-op since only whole numbers of seconds are used to compute it from the notBefore. It's possible that this could cause some of the maxBackdate calculations to fail, because truncation can cause the notBefore timestamp to move up to (nearly) 1 second earlier. However, this only becomes a concern in practice if maxBackdate is set to 10 seconds or less. This results in cleaner logs, since Go only prints the fractional seconds portion of a timestamp if it is non-zero: https://go.dev/play/p/iAeSX3VMrJD Fixes #8318
1 parent 80c75ab commit 440c695

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

issuance/cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ func (p *Profile) GenerateValidity(now time.Time) (time.Time, time.Time) {
142142
// Don't use the full maxBackdate, to ensure that the actual backdate remains
143143
// acceptable throughout the rest of the issuance process.
144144
backdate := time.Duration(float64(p.maxBackdate.Nanoseconds()) * 0.9)
145-
notBefore := now.Add(-1 * backdate)
145+
notBefore := now.Add(-1 * backdate).Truncate(time.Second)
146146
// Subtract one second, because certificate validity periods are *inclusive*
147147
// of their final second (Baseline Requirements, Section 1.6.1).
148-
notAfter := notBefore.Add(p.maxValidity).Add(-1 * time.Second)
148+
notAfter := notBefore.Add(p.maxValidity).Add(-1 * time.Second).Truncate(time.Second)
149149
return notBefore, notAfter
150150
}
151151

0 commit comments

Comments
 (0)