Skip to content

Commit c92bf25

Browse files
author
Ananth Bhaskararaman
committed
increase ca validity to five years
1 parent 59bb60e commit c92bf25

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

cmd/bf/ca.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ var caIssueCmd = &cli.Command{
203203
return cli.Exit("Error creating certificate request", 1)
204204
}
205205

206-
notBefore, notAfter, err := tinyca.ParseValidity(notBeforeTime, notAfterTime)
206+
notBefore, notAfter, err := tinyca.ParseValidity(
207+
notBeforeTime,
208+
notAfterTime,
209+
tinyca.MaximumIssueValidity,
210+
)
207211
if err != nil {
208212
bifrost.Logger().ErrorContext(ctx, "error parsing validity", "error", err)
209213
return cli.Exit("Error parsing validity", 1)

cmd/bf/new.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ var newCmd = &cli.Command{
146146
}
147147

148148
id := key.UUID(namespace)
149-
notBefore, notAfter, err := tinyca.ParseValidity(notBeforeTime, notAfterTime)
149+
notBefore, notAfter, err := tinyca.ParseValidity(
150+
notBeforeTime,
151+
notAfterTime,
152+
tinyca.MaximumCACertValidity,
153+
)
150154
if err != nil {
151155
return err
152156
}

tinyca/ca.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import (
2929
"github.com/google/uuid"
3030
)
3131

32+
const (
33+
MaximumIssueValidity = 24 * time.Hour // 1 day
34+
MaximumCACertValidity = 5 * 365 * 24 * time.Hour // 5 year
35+
)
36+
3237
// CA is a simple Certificate Authority.
3338
// The CA issues client certificates signed by a root certificate and private key.
3439
// The CA provides an HTTP handler to issue certificates.
@@ -92,7 +97,7 @@ func (ca *CA) ServeHTTP(w http.ResponseWriter, r *http.Request) {
9297

9398
ctx := r.Context()
9499

95-
notBefore, notAfter, err := ParseValidity(nb, na)
100+
notBefore, notAfter, err := ParseValidity(nb, na, MaximumIssueValidity)
96101
if err != nil {
97102
writeHTTPError(ctx, w, err.Error(), http.StatusBadRequest)
98103
return

tinyca/validity.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import (
66
"time"
77
)
88

9-
// MaxIssueValidity is the maximum validity period for issued certificates.
10-
const MaxIssueValidity = 30 * 24 * time.Hour
11-
129
// ParseValidity parses notBefore and notAfter into time.Time values.
1310
// notBefore and notAfter can either be in RFC3339 format or a duration
1411
// offset from the current time.
1512
// Offset durations are parsed using time.ParseDuration.
1613
// If notBefore is empty or set to "now", it defaults to the current time.
1714
// If notAfter is empty, it behaves as if it is set to "+1h".
1815
// Negative validity periods are not allowed.
19-
func ParseValidity(notBefore string, notAfter string) (time.Time, time.Time, error) {
16+
func ParseValidity(
17+
notBefore string,
18+
notAfter string,
19+
maxIssueValidity time.Duration,
20+
) (time.Time, time.Time, error) {
2021
now := time.Now()
2122
nbf := now
2223
if notBefore != "" && notBefore != "now" {
@@ -38,7 +39,7 @@ func ParseValidity(notBefore string, notAfter string) (time.Time, time.Time, err
3839
return time.Time{}, time.Time{}, errors.New("negative validity period")
3940
}
4041

41-
if naf.Sub(nbf) > MaxIssueValidity {
42+
if naf.Sub(nbf) > maxIssueValidity {
4243
return time.Time{}, time.Time{}, errors.New("validity period is too long")
4344
}
4445

0 commit comments

Comments
 (0)