-
-
Notifications
You must be signed in to change notification settings - Fork 589
/
crl.go
108 lines (88 loc) · 2.65 KB
/
crl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package issuance
import (
"crypto/rand"
"crypto/x509"
"fmt"
"math/big"
"time"
"github.com/zmap/zlint/v3/lint"
"github.com/letsencrypt/boulder/config"
"github.com/letsencrypt/boulder/crl/idp"
"github.com/letsencrypt/boulder/linter"
)
type CRLProfileConfig struct {
ValidityInterval config.Duration
MaxBackdate config.Duration
}
type CRLProfile struct {
validityInterval time.Duration
maxBackdate time.Duration
lints lint.Registry
}
func NewCRLProfile(config CRLProfileConfig) (*CRLProfile, error) {
lifetime := config.ValidityInterval.Duration
if lifetime >= 10*24*time.Hour {
return nil, fmt.Errorf("crl lifetime cannot be more than 10 days, got %q", lifetime)
} else if lifetime <= 0*time.Hour {
return nil, fmt.Errorf("crl lifetime must be positive, got %q", lifetime)
}
if config.MaxBackdate.Duration < 0 {
return nil, fmt.Errorf("crl max backdate must be non-negative, got %q", config.MaxBackdate)
}
reg, err := linter.NewRegistry(nil)
if err != nil {
return nil, fmt.Errorf("creating lint registry: %w", err)
}
return &CRLProfile{
validityInterval: config.ValidityInterval.Duration,
maxBackdate: config.MaxBackdate.Duration,
lints: reg,
}, nil
}
type CRLRequest struct {
Number *big.Int
Shard int64
ThisUpdate time.Time
Entries []x509.RevocationListEntry
}
func (i *Issuer) IssueCRL(prof *CRLProfile, req *CRLRequest) ([]byte, error) {
backdatedBy := i.clk.Now().Sub(req.ThisUpdate)
if backdatedBy > prof.maxBackdate {
return nil, fmt.Errorf("ThisUpdate is too far in the past (%s>%s)", backdatedBy, prof.maxBackdate)
}
if backdatedBy < 0 {
return nil, fmt.Errorf("ThisUpdate is in the future (%s>%s)", req.ThisUpdate, i.clk.Now())
}
template := &x509.RevocationList{
RevokedCertificateEntries: req.Entries,
Number: req.Number,
ThisUpdate: req.ThisUpdate,
NextUpdate: req.ThisUpdate.Add(-time.Second).Add(prof.validityInterval),
}
if i.crlURLBase == "" {
return nil, fmt.Errorf("CRL must contain an issuingDistributionPoint")
}
// Concat the base with the shard directly, since we require that the base
// end with a single trailing slash.
idp, err := idp.MakeUserCertsExt([]string{
fmt.Sprintf("%s%d.crl", i.crlURLBase, req.Shard),
})
if err != nil {
return nil, fmt.Errorf("creating IDP extension: %w", err)
}
template.ExtraExtensions = append(template.ExtraExtensions, idp)
err = i.Linter.CheckCRL(template, prof.lints)
if err != nil {
return nil, err
}
crlBytes, err := x509.CreateRevocationList(
rand.Reader,
template,
i.Cert.Certificate,
i.Signer,
)
if err != nil {
return nil, err
}
return crlBytes, nil
}