@@ -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
273281func (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
0 commit comments