Finish cleaning up unused CT config types (#8174)
The last use of these types was removed in https://github.com/letsencrypt/boulder/pull/8156
This commit is contained in:
		
							parent
							
								
									e625ff3534
								
							
						
					
					
						commit
						faa07f5e36
					
				|  | @ -1,93 +1,9 @@ | ||||||
| package ctconfig | package ctconfig | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" |  | ||||||
| 	"fmt" |  | ||||||
| 	"time" |  | ||||||
| 
 |  | ||||||
| 	"github.com/letsencrypt/boulder/config" | 	"github.com/letsencrypt/boulder/config" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // LogShard describes a single shard of a temporally sharded
 |  | ||||||
| // CT log
 |  | ||||||
| type LogShard struct { |  | ||||||
| 	URI         string |  | ||||||
| 	Key         string |  | ||||||
| 	WindowStart time.Time |  | ||||||
| 	WindowEnd   time.Time |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // TemporalSet contains a set of temporal shards of a single log
 |  | ||||||
| type TemporalSet struct { |  | ||||||
| 	Name   string |  | ||||||
| 	Shards []LogShard |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Setup initializes the TemporalSet by parsing the start and end dates
 |  | ||||||
| // and verifying WindowEnd > WindowStart
 |  | ||||||
| func (ts *TemporalSet) Setup() error { |  | ||||||
| 	if ts.Name == "" { |  | ||||||
| 		return errors.New("Name cannot be empty") |  | ||||||
| 	} |  | ||||||
| 	if len(ts.Shards) == 0 { |  | ||||||
| 		return errors.New("temporal set contains no shards") |  | ||||||
| 	} |  | ||||||
| 	for i := range ts.Shards { |  | ||||||
| 		if !ts.Shards[i].WindowEnd.After(ts.Shards[i].WindowStart) { |  | ||||||
| 			return errors.New("WindowStart must be before WindowEnd") |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // pick chooses the correct shard from a TemporalSet to use for the given
 |  | ||||||
| // expiration time. In the case where two shards have overlapping windows
 |  | ||||||
| // the earlier of the two shards will be chosen.
 |  | ||||||
| func (ts *TemporalSet) pick(exp time.Time) (*LogShard, error) { |  | ||||||
| 	for _, shard := range ts.Shards { |  | ||||||
| 		if exp.Before(shard.WindowStart) { |  | ||||||
| 			continue |  | ||||||
| 		} |  | ||||||
| 		if !exp.Before(shard.WindowEnd) { |  | ||||||
| 			continue |  | ||||||
| 		} |  | ||||||
| 		return &shard, nil |  | ||||||
| 	} |  | ||||||
| 	return nil, fmt.Errorf("no valid shard available for temporal set %q for expiration date %q", ts.Name, exp) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // LogDescription contains the information needed to submit certificates
 |  | ||||||
| // to a CT log and verify returned receipts. If TemporalSet is non-nil then
 |  | ||||||
| // URI and Key should be empty.
 |  | ||||||
| type LogDescription struct { |  | ||||||
| 	URI             string |  | ||||||
| 	Key             string |  | ||||||
| 	SubmitFinalCert bool |  | ||||||
| 
 |  | ||||||
| 	*TemporalSet |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Info returns the URI and key of the log, either from a plain log description
 |  | ||||||
| // or from the earliest valid shard from a temporal log set
 |  | ||||||
| func (ld LogDescription) Info(exp time.Time) (string, string, error) { |  | ||||||
| 	if ld.TemporalSet == nil { |  | ||||||
| 		return ld.URI, ld.Key, nil |  | ||||||
| 	} |  | ||||||
| 	shard, err := ld.TemporalSet.pick(exp) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return "", "", err |  | ||||||
| 	} |  | ||||||
| 	return shard.URI, shard.Key, nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // CTGroup represents a group of CT Logs. Although capable of holding logs
 |  | ||||||
| // grouped by any arbitrary feature, is today primarily used to hold logs which
 |  | ||||||
| // are all operated by the same legal entity.
 |  | ||||||
| type CTGroup struct { |  | ||||||
| 	Name string |  | ||||||
| 	Logs []LogDescription |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // CTConfig is the top-level config object expected to be embedded in an
 | // CTConfig is the top-level config object expected to be embedded in an
 | ||||||
| // executable's JSON config struct.
 | // executable's JSON config struct.
 | ||||||
| type CTConfig struct { | type CTConfig struct { | ||||||
|  | @ -109,13 +25,3 @@ type CTConfig struct { | ||||||
| 	// and final certs to the same log.
 | 	// and final certs to the same log.
 | ||||||
| 	FinalLogs []string | 	FinalLogs []string | ||||||
| } | } | ||||||
| 
 |  | ||||||
| // LogID holds enough information to uniquely identify a CT Log: its log_id
 |  | ||||||
| // (the base64-encoding of the SHA-256 hash of its public key) and its human-
 |  | ||||||
| // readable name/description. This is used to extract other log parameters
 |  | ||||||
| // (such as its URL and public key) from the Chrome Log List.
 |  | ||||||
| type LogID struct { |  | ||||||
| 	Name        string |  | ||||||
| 	ID          string |  | ||||||
| 	SubmitFinal bool |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -1,116 +0,0 @@ | ||||||
| package ctconfig |  | ||||||
| 
 |  | ||||||
| import ( |  | ||||||
| 	"testing" |  | ||||||
| 	"time" |  | ||||||
| 
 |  | ||||||
| 	"github.com/jmhodges/clock" |  | ||||||
| 	"github.com/letsencrypt/boulder/test" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| func TestTemporalSetup(t *testing.T) { |  | ||||||
| 	for _, tc := range []struct { |  | ||||||
| 		ts  TemporalSet |  | ||||||
| 		err string |  | ||||||
| 	}{ |  | ||||||
| 		{ |  | ||||||
| 			ts:  TemporalSet{}, |  | ||||||
| 			err: "Name cannot be empty", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			ts: TemporalSet{ |  | ||||||
| 				Name: "temporal set", |  | ||||||
| 			}, |  | ||||||
| 			err: "temporal set contains no shards", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			ts: TemporalSet{ |  | ||||||
| 				Name: "temporal set", |  | ||||||
| 				Shards: []LogShard{ |  | ||||||
| 					{ |  | ||||||
| 						WindowStart: time.Time{}, |  | ||||||
| 						WindowEnd:   time.Time{}, |  | ||||||
| 					}, |  | ||||||
| 				}, |  | ||||||
| 			}, |  | ||||||
| 			err: "WindowStart must be before WindowEnd", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			ts: TemporalSet{ |  | ||||||
| 				Name: "temporal set", |  | ||||||
| 				Shards: []LogShard{ |  | ||||||
| 					{ |  | ||||||
| 						WindowStart: time.Time{}.Add(time.Hour), |  | ||||||
| 						WindowEnd:   time.Time{}, |  | ||||||
| 					}, |  | ||||||
| 				}, |  | ||||||
| 			}, |  | ||||||
| 			err: "WindowStart must be before WindowEnd", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			ts: TemporalSet{ |  | ||||||
| 				Name: "temporal set", |  | ||||||
| 				Shards: []LogShard{ |  | ||||||
| 					{ |  | ||||||
| 						WindowStart: time.Time{}, |  | ||||||
| 						WindowEnd:   time.Time{}.Add(time.Hour), |  | ||||||
| 					}, |  | ||||||
| 				}, |  | ||||||
| 			}, |  | ||||||
| 			err: "", |  | ||||||
| 		}, |  | ||||||
| 	} { |  | ||||||
| 		err := tc.ts.Setup() |  | ||||||
| 		if err != nil && tc.err != err.Error() { |  | ||||||
| 			t.Errorf("got error %q, wanted %q", err, tc.err) |  | ||||||
| 		} else if err == nil && tc.err != "" { |  | ||||||
| 			t.Errorf("unexpected error %q", err) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestLogInfo(t *testing.T) { |  | ||||||
| 	ld := LogDescription{ |  | ||||||
| 		URI: "basic-uri", |  | ||||||
| 		Key: "basic-key", |  | ||||||
| 	} |  | ||||||
| 	uri, key, err := ld.Info(time.Time{}) |  | ||||||
| 	test.AssertNotError(t, err, "Info failed") |  | ||||||
| 	test.AssertEquals(t, uri, ld.URI) |  | ||||||
| 	test.AssertEquals(t, key, ld.Key) |  | ||||||
| 
 |  | ||||||
| 	fc := clock.NewFake() |  | ||||||
| 	ld.TemporalSet = &TemporalSet{} |  | ||||||
| 	_, _, err = ld.Info(fc.Now()) |  | ||||||
| 	test.AssertError(t, err, "Info should fail with a TemporalSet with no viable shards") |  | ||||||
| 	ld.TemporalSet.Shards = []LogShard{{WindowStart: fc.Now().Add(time.Hour), WindowEnd: fc.Now().Add(time.Hour * 2)}} |  | ||||||
| 	_, _, err = ld.Info(fc.Now()) |  | ||||||
| 	test.AssertError(t, err, "Info should fail with a TemporalSet with no viable shards") |  | ||||||
| 
 |  | ||||||
| 	fc.Add(time.Hour * 4) |  | ||||||
| 	now := fc.Now() |  | ||||||
| 	ld.TemporalSet.Shards = []LogShard{ |  | ||||||
| 		{ |  | ||||||
| 			WindowStart: now.Add(time.Hour * -4), |  | ||||||
| 			WindowEnd:   now.Add(time.Hour * -2), |  | ||||||
| 			URI:         "a", |  | ||||||
| 			Key:         "a", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			WindowStart: now.Add(time.Hour * -2), |  | ||||||
| 			WindowEnd:   now.Add(time.Hour * 2), |  | ||||||
| 			URI:         "b", |  | ||||||
| 			Key:         "b", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			WindowStart: now.Add(time.Hour * 2), |  | ||||||
| 			WindowEnd:   now.Add(time.Hour * 4), |  | ||||||
| 			URI:         "c", |  | ||||||
| 			Key:         "c", |  | ||||||
| 		}, |  | ||||||
| 	} |  | ||||||
| 	uri, key, err = ld.Info(now) |  | ||||||
| 	test.AssertNotError(t, err, "Info failed") |  | ||||||
| 	test.AssertEquals(t, uri, "b") |  | ||||||
| 	test.AssertEquals(t, key, "b") |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in New Issue