Skip to content

Commit aa36e03

Browse files
committed
ari: Handle invalid window times (fix #40)
1 parent c0bce6b commit aa36e03

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

acme/ari.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,15 @@ func (c *Client) GetRenewalInfo(ctx context.Context, leafCert *x509.Certificate)
210210
// https://github.com/aarongable/draft-acme-ari/issues/70
211211
// We add 1 to the start time since we are dealing in seconds for
212212
// simplicity, but the server may provide sub-second timestamps.
213+
// We also try our best with invalid start/end values (see #40).
213214
start, end := ari.SuggestedWindow.Start.Unix()+1, ari.SuggestedWindow.End.Unix()
214-
ari.SelectedTime = time.Unix(rand.Int63n(end-start)+start, 0).UTC()
215+
if end > start {
216+
ari.SelectedTime = time.Unix(rand.Int63n(end-start)+start, 0).UTC()
217+
} else if start > 0 {
218+
ari.SelectedTime = time.Unix(start, 0).UTC()
219+
} else if end > 0 {
220+
ari.SelectedTime = time.Unix(end, 0).UTC()
221+
}
215222

216223
if c.Logger != nil {
217224
c.Logger.LogAttrs(ctx, slog.LevelInfo, "got renewal info",

0 commit comments

Comments
 (0)