Skip to content

Commit f3861d3

Browse files
committed
Address review feedback, rename X509Chain to Umbilical
1 parent b43fec7 commit f3861d3

File tree

3 files changed

+63
-52
lines changed

3 files changed

+63
-52
lines changed

ca/ca.go

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ type NewOpts struct {
3434

3535
// Fields below are optional.
3636

37-
SignatureScheme mtc.SignatureScheme
38-
BatchDuration time.Duration
39-
Lifetime time.Duration
40-
StorageDuration time.Duration
41-
EvidencePolicy mtc.EvidencePolicyType
42-
AcceptedRoots []byte
37+
SignatureScheme mtc.SignatureScheme
38+
BatchDuration time.Duration
39+
Lifetime time.Duration
40+
StorageDuration time.Duration
41+
EvidencePolicy mtc.EvidencePolicyType
42+
UmbilicalRootsPEM []byte
4343
}
4444

4545
// Handle for exclusive access to a Merkle Tree CA state.
@@ -49,7 +49,7 @@ type Handle struct {
4949
flock lockfile.Lockfile
5050
path string
5151
closed bool
52-
acceptedRoots *x509.CertPool
52+
umbilicalRoots *x509.CertPool
5353
revocationChecker *revocation.Checker
5454

5555
indices map[uint32]*Index
@@ -126,16 +126,18 @@ func (h *Handle) QueueMultiple(it func(yield func(ar mtc.AssertionRequest) error
126126
bw := bufio.NewWriter(w)
127127

128128
if err := it(func(ar mtc.AssertionRequest) error {
129-
if h.params.EvidencePolicy == mtc.RequireX509ChainEvidencePolicyType {
129+
switch h.params.EvidencePolicy {
130+
case mtc.EmptyEvidencePolicyType:
131+
case mtc.UmbilicalEvidencePolicyType:
130132
var (
131133
err error
132134
chain []*x509.Certificate
133135
)
134136
// TODO this checks only the first matching evidence. Do we want to allow multiple
135137
// of the same evidence type to be submitted, and should we check them all?
136138
for _, ev := range ar.Evidence {
137-
if ev.Type() == mtc.X509ChainEvidenceType {
138-
chain, err = ev.(mtc.X509ChainEvidence).Chain()
139+
if ev.Type() == mtc.UmbilicalEvidenceType {
140+
chain, err = ev.(mtc.UmbilicalEvidence).Chain()
139141
if err != nil {
140142
return err
141143
}
@@ -152,10 +154,12 @@ func (h *Handle) QueueMultiple(it func(yield func(ar mtc.AssertionRequest) error
152154
CA: &h.params,
153155
Number: h.params.ActiveBatches(time.Now()).End + 1,
154156
}
155-
_, err = umbilical.CheckAssertionValidForX509(ar.Assertion, batch, chain, h.acceptedRoots, h.revocationChecker)
157+
_, err = umbilical.CheckAssertionValidForX509(ar.Assertion, batch, chain, h.umbilicalRoots, h.revocationChecker)
156158
if err != nil {
157159
return err
158160
}
161+
default:
162+
return fmt.Errorf("unknown evidence policy: %d", h.params.EvidencePolicy)
159163
}
160164

161165
buf, err := ar.MarshalBinary()
@@ -231,21 +235,25 @@ func Open(path string) (*Handle, error) {
231235
if err != nil {
232236
return nil, fmt.Errorf("parsing %s: %w", h.skPath(), err)
233237
}
234-
if h.params.EvidencePolicy == mtc.RequireX509ChainEvidencePolicyType {
238+
switch h.params.EvidencePolicy {
239+
case mtc.EmptyEvidencePolicyType:
240+
case mtc.UmbilicalEvidencePolicyType:
235241
h.revocationChecker, err = revocation.NewChecker(revocation.Config{Cache: h.revocationCachePath()})
236242
if err != nil {
237243
return nil, fmt.Errorf("creating revocation checker from %s: %w", h.revocationCachePath(), err)
238244
}
239-
h.acceptedRoots = x509.NewCertPool()
240-
pemCerts, err := os.ReadFile(h.rootsPath())
245+
h.umbilicalRoots = x509.NewCertPool()
246+
pemCerts, err := os.ReadFile(h.umbilicalRootsPath())
241247
if err != nil {
242-
return nil, fmt.Errorf("reading %s: %w", h.rootsPath(), err)
248+
return nil, fmt.Errorf("reading %s: %w", h.umbilicalRootsPath(), err)
243249
}
244250
// TODO use AddCertWithConstraint to deal with constrained roots:
245251
// https://chromium.googlesource.com/chromium/src/+/main/net/data/ssl/chrome_root_store/root_store.md#constrained-roots
246-
if !h.acceptedRoots.AppendCertsFromPEM(pemCerts) {
252+
if !h.umbilicalRoots.AppendCertsFromPEM(pemCerts) {
247253
return nil, fmt.Errorf("failed to append root certs")
248254
}
255+
default:
256+
return nil, fmt.Errorf("unknown evidence policy: %d", h.params.EvidencePolicy)
249257
}
250258
return &h, nil
251259
}
@@ -266,8 +274,8 @@ func (h Handle) revocationCachePath() string {
266274
return gopath.Join(h.path, "revocation-cache")
267275
}
268276

269-
func (h Handle) rootsPath() string {
270-
return gopath.Join(h.path, "www", "mtc", "v1", "roots")
277+
func (h Handle) umbilicalRootsPath() string {
278+
return gopath.Join(h.path, "www", "mtc", "v1", "umbilical-roots.pem")
271279
}
272280

273281
func (h Handle) treePath(number uint32) string {
@@ -1167,12 +1175,12 @@ func New(path string, opts NewOpts) (*Handle, error) {
11671175
if opts.StorageDuration.Nanoseconds()%opts.BatchDuration.Nanoseconds() != 0 {
11681176
return nil, errors.New("StorageDuration has to be a multiple of BatchDuration")
11691177
}
1170-
if opts.EvidencePolicy == mtc.RequireX509ChainEvidencePolicyType {
1171-
if opts.AcceptedRoots == nil {
1172-
return nil, errors.New("AcceptedRoots must be set when x509 chain evidence is required")
1178+
if opts.EvidencePolicy == mtc.UmbilicalEvidencePolicyType {
1179+
if opts.UmbilicalRootsPEM == nil {
1180+
return nil, errors.New("UmbilicalRoots is required with the 'umbilical' evidence policy")
11731181
}
1174-
if !x509.NewCertPool().AppendCertsFromPEM(opts.AcceptedRoots) {
1175-
return nil, errors.New("Failed to parse any PEM-encoded roots from AcceptedRoots")
1182+
if !x509.NewCertPool().AppendCertsFromPEM(opts.UmbilicalRootsPEM) {
1183+
return nil, errors.New("Failed to parse any PEM-encoded roots from UmbilicalRootsPEM")
11761184
}
11771185
}
11781186
h.params.ValidityWindowSize = uint64(opts.Lifetime.Nanoseconds() / opts.BatchDuration.Nanoseconds())
@@ -1251,9 +1259,9 @@ func New(path string, opts NewOpts) (*Handle, error) {
12511259
}
12521260

12531261
// Accepted roots
1254-
if h.params.EvidencePolicy == mtc.RequireX509ChainEvidencePolicyType {
1255-
if err := os.WriteFile(h.rootsPath(), opts.AcceptedRoots, 0o644); err != nil {
1256-
return nil, fmt.Errorf("Writing %s: %w", h.rootsPath(), err)
1262+
if h.params.EvidencePolicy == mtc.UmbilicalEvidencePolicyType {
1263+
if err := os.WriteFile(h.umbilicalRootsPath(), opts.UmbilicalRootsPEM, 0o644); err != nil {
1264+
return nil, fmt.Errorf("Writing %s: %w", h.umbilicalRootsPath(), err)
12571265
}
12581266
}
12591267

cmd/mtc/main.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ var (
2929
errArgs = errors.New("Wrong number of arguments")
3030
fCpuProfile *os.File
3131
evPolicyMap = map[string]mtc.EvidencePolicyType{
32-
"empty": mtc.EmptyEvidencePolicyType,
33-
"require-x509-chain": mtc.RequireX509ChainEvidencePolicyType,
32+
"empty": mtc.EmptyEvidencePolicyType,
33+
"umbilical": mtc.UmbilicalEvidencePolicyType,
3434
}
3535
)
3636

@@ -256,7 +256,7 @@ func assertionRequestFromFlagsUnchecked(cc *cli.Context) (*mtc.AssertionRequest,
256256
return nil, fmt.Errorf("from-x509: %s", err)
257257
}
258258

259-
ev, err := mtc.NewX509ChainEvidence(certs)
259+
ev, err := mtc.NewUmbilicalEvidence(certs)
260260
if err != nil {
261261
return nil, err
262262
}
@@ -558,11 +558,11 @@ func handleCaNew(cc *cli.Context) error {
558558
return fmt.Errorf("unknown evidence policy: %s", cc.String("evidence-policy"))
559559
}
560560

561-
var acceptedRoots []byte
562-
if evPolicy == mtc.RequireX509ChainEvidencePolicyType {
563-
acceptedRoots, err = os.ReadFile(cc.String("roots"))
561+
var umbilicalRoots []byte
562+
if evPolicy == mtc.UmbilicalEvidencePolicyType {
563+
umbilicalRoots, err = os.ReadFile(cc.String("umbilical-roots"))
564564
if err != nil {
565-
return fmt.Errorf("reading %s: %w", cc.String("roots"), err)
565+
return fmt.Errorf("reading %s: %w", cc.String("umbilical-roots"), err)
566566
}
567567
}
568568

@@ -572,11 +572,11 @@ func handleCaNew(cc *cli.Context) error {
572572
Issuer: oid,
573573
HttpServer: cc.Args().Get(1),
574574

575-
BatchDuration: cc.Duration("batch-duration"),
576-
StorageDuration: cc.Duration("storage-duration"),
577-
Lifetime: cc.Duration("lifetime"),
578-
EvidencePolicy: evPolicy,
579-
AcceptedRoots: acceptedRoots,
575+
BatchDuration: cc.Duration("batch-duration"),
576+
StorageDuration: cc.Duration("storage-duration"),
577+
Lifetime: cc.Duration("lifetime"),
578+
EvidencePolicy: evPolicy,
579+
UmbilicalRootsPEM: umbilicalRoots,
580580
},
581581
)
582582
if err != nil {
@@ -744,9 +744,9 @@ func writeEvidenceList(w *tabwriter.Writer, el mtc.EvidenceList) error {
744744
fmt.Fprintf(w, "evidence-list (%d entries)\n", len(el))
745745
for _, ev := range el {
746746
switch ev.Type() {
747-
case mtc.X509ChainEvidenceType:
748-
fmt.Fprintf(w, "x509_chain\n")
749-
chain, err := ev.(mtc.X509ChainEvidence).Chain()
747+
case mtc.UmbilicalEvidenceType:
748+
fmt.Fprintf(w, "umbilical\n")
749+
chain, err := ev.(mtc.UmbilicalEvidence).Chain()
750750
if err != nil {
751751
return err
752752
}
@@ -1015,8 +1015,8 @@ func main() {
10151015
Value: "empty",
10161016
},
10171017
&cli.StringFlag{
1018-
Name: "roots",
1019-
Usage: "path to PEM-encode root store when X.509 chain evidence is required",
1018+
Name: "umbilical-roots",
1019+
Usage: "path to PEM-encoded accepted roots for umbilical (X.509 chain) evidence",
10201020
},
10211021
},
10221022
},

mtc.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type Claims struct {
5858
type EvidenceType uint16
5959

6060
const (
61-
X509ChainEvidenceType EvidenceType = iota
61+
UmbilicalEvidenceType EvidenceType = iota
6262
)
6363

6464
type EvidenceList []Evidence
@@ -68,7 +68,7 @@ type Evidence interface {
6868
Info() []byte
6969
}
7070

71-
type X509ChainEvidence []byte
71+
type UmbilicalEvidence []byte
7272

7373
type UnknownEvidence struct {
7474
typ EvidenceType
@@ -78,8 +78,11 @@ type UnknownEvidence struct {
7878
type EvidencePolicyType uint16
7979

8080
const (
81+
// Policy requiring no evidence to queue an assertion request.
8182
EmptyEvidencePolicyType EvidencePolicyType = iota
82-
RequireX509ChainEvidencePolicyType
83+
84+
// Policy requiring an X509 chain to an accepted root to queue an assertion request.
85+
UmbilicalEvidencePolicyType
8386
)
8487

8588
// Represents a claim we do not how to interpret.
@@ -936,12 +939,12 @@ func (a *AbridgedAssertion) unmarshal(s *cryptobyte.String) error {
936939
return nil
937940
}
938941

939-
func (e X509ChainEvidence) Type() EvidenceType { return X509ChainEvidenceType }
940-
func (e X509ChainEvidence) Info() []byte { return e }
941-
func (e X509ChainEvidence) Chain() ([]*x509.Certificate, error) {
942+
func (e UmbilicalEvidence) Type() EvidenceType { return UmbilicalEvidenceType }
943+
func (e UmbilicalEvidence) Info() []byte { return e }
944+
func (e UmbilicalEvidence) Chain() ([]*x509.Certificate, error) {
942945
return x509.ParseCertificates(e)
943946
}
944-
func NewX509ChainEvidence(certs []*x509.Certificate) (X509ChainEvidence, error) {
947+
func NewUmbilicalEvidence(certs []*x509.Certificate) (UmbilicalEvidence, error) {
945948
var b cryptobyte.Builder
946949
for _, cert := range certs {
947950
b.AddBytes(cert.Raw)
@@ -1656,8 +1659,8 @@ func (el *EvidenceList) unmarshal(s *cryptobyte.String) error {
16561659
}
16571660

16581661
switch evidenceType {
1659-
case X509ChainEvidenceType:
1660-
*el = append(*el, X509ChainEvidence(evidenceInfo))
1662+
case UmbilicalEvidenceType:
1663+
*el = append(*el, UmbilicalEvidence(evidenceInfo))
16611664
default:
16621665
*el = append(*el, UnknownEvidence{
16631666
typ: evidenceType,

0 commit comments

Comments
 (0)