Skip to content

Commit

Permalink
Remove multiconfig (#207)
Browse files Browse the repository at this point in the history
* remove LogConfigSet

* edit the rest of the code accordinly

* don't run key checks accross multiple logs

* remove origin empty test
  • Loading branch information
phbnf authored Sep 5, 2024
1 parent 7b5263e commit acab2b3
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 283 deletions.
35 changes: 6 additions & 29 deletions personalities/sctfe/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,33 @@ type ValidatedLogConfig struct {
NotAfterLimit *time.Time
}

// LogConfigSetFromFile creates a slice of LogConfigSet options from the given
// LogConfigFromFile creates a LogConfig options from the given
// filename, which should contain text or binary-encoded protobuf configuration
// data.
func LogConfigSetFromFile(filename string) (*configpb.LogConfigSet, error) {
func LogConfigFromFile(filename string) (*configpb.LogConfig, error) {
cfgBytes, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

var cfg configpb.LogConfigSet
var cfg configpb.LogConfig
if txtErr := prototext.Unmarshal(cfgBytes, &cfg); txtErr != nil {
if binErr := proto.Unmarshal(cfgBytes, &cfg); binErr != nil {
return nil, fmt.Errorf("failed to parse LogConfigSet from %q as text protobuf (%v) or binary protobuf (%v)", filename, txtErr, binErr)
return nil, fmt.Errorf("failed to parse LogConfig from %q as text protobuf (%v) or binary protobuf (%v)", filename, txtErr, binErr)
}
}

if len(cfg.Config) == 0 {
return nil, errors.New("empty log config found")
}
return &cfg, nil
}

// validateLogConfig checks that a single log config is valid. In particular:
// ValidateLogConfig checks that a single log config is valid. In particular:
// - A log has a private, and optionally a public key (both valid).
// - Each of NotBeforeStart and NotBeforeLimit, if set, is a valid timestamp
// proto. If both are set then NotBeforeStart <= NotBeforeLimit.
// - Merge delays (if present) are correct.
//
// Returns the validated structures (useful to avoid double validation).
func validateLogConfig(cfg *configpb.LogConfig) (*ValidatedLogConfig, error) {
func ValidateLogConfig(cfg *configpb.LogConfig) (*ValidatedLogConfig, error) {
if len(cfg.Origin) == 0 {
return nil, errors.New("empty log origin")
}
Expand Down Expand Up @@ -152,26 +149,6 @@ func validateLogConfig(cfg *configpb.LogConfig) (*ValidatedLogConfig, error) {
return &vCfg, nil
}

// ValidateLogConfigSet validate each configs independently and makes sure
// there aren't any duplicate entries.
func ValidateLogConfigSet(cfg *configpb.LogConfigSet) ([]*ValidatedLogConfig, error) {
logNameMap := make(map[string]bool)
ret := []*ValidatedLogConfig{}
for _, logCfg := range cfg.Config {
vcfg, err := validateLogConfig(logCfg)
if err != nil {
return nil, fmt.Errorf("log config: %v: %v", err, logCfg)
}
if logNameMap[logCfg.Origin] {
return nil, fmt.Errorf("log config: duplicate origin: %s: %v", logCfg.Origin, logCfg)
}
logNameMap[logCfg.Origin] = true
ret = append(ret, vcfg)
}

return ret, nil
}

var stringToKeyUsage = map[string]x509.ExtKeyUsage{
"Any": x509.ExtKeyUsageAny,
"ServerAuth": x509.ExtKeyUsageServerAuth,
Expand Down
63 changes: 1 addition & 62 deletions personalities/sctfe/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestValidateLogConfig(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
vc, err := validateLogConfig(tc.cfg)
vc, err := ValidateLogConfig(tc.cfg)
if len(tc.wantErr) == 0 && err != nil {
t.Errorf("ValidateLogConfig()=%v, want nil", err)
}
Expand All @@ -258,64 +258,3 @@ func TestValidateLogConfig(t *testing.T) {
})
}
}

func TestValidateLogConfigSet(t *testing.T) {
privKey := mustMarshalAny(&keyspb.PEMKeyFile{Path: "../testdata/ct-http-server.privkey.pem", Password: "dirk"})
for _, tc := range []struct {
desc string
cfg *configpb.LogConfigSet
wantErr string
}{
// TODO(phboneff): add config for multiple storage
{
desc: "duplicate-prefix",
wantErr: "duplicate origin",
cfg: &configpb.LogConfigSet{
Config: []*configpb.LogConfig{
{
Origin: "pref1",
StorageConfig: &configpb.LogConfig_Gcp{Gcp: &configpb.GCPConfig{Bucket: "bucket", SpannerDbPath: "spanner"}},
PrivateKey: privKey,
},
{
Origin: "pref1",
StorageConfig: &configpb.LogConfig_Gcp{Gcp: &configpb.GCPConfig{Bucket: "bucket", SpannerDbPath: "spanner"}},
PrivateKey: privKey,
},
},
},
},
{
desc: "ok-all-distinct",
cfg: &configpb.LogConfigSet{
Config: []*configpb.LogConfig{
{
Origin: "pref1",
StorageConfig: &configpb.LogConfig_Gcp{Gcp: &configpb.GCPConfig{Bucket: "bucket", SpannerDbPath: "spanner"}},
PrivateKey: privKey,
},
{
Origin: "pref2",
StorageConfig: &configpb.LogConfig_Gcp{Gcp: &configpb.GCPConfig{Bucket: "bucket", SpannerDbPath: "spanner"}},
PrivateKey: privKey,
},
{
Origin: "pref3",
StorageConfig: &configpb.LogConfig_Gcp{Gcp: &configpb.GCPConfig{Bucket: "bucket", SpannerDbPath: "spanner"}},
PrivateKey: privKey,
},
},
},
},
} {
t.Run(tc.desc, func(t *testing.T) {
_, err := ValidateLogConfigSet(tc.cfg)
if len(tc.wantErr) == 0 && err != nil {
t.Fatalf("ValidateLogConfigSet()=%v, want nil", err)
}
if len(tc.wantErr) > 0 && (err == nil || !strings.Contains(err.Error(), tc.wantErr)) {
t.Errorf("ValidateLogConfigSet()=%v, want err containing %q", err, tc.wantErr)
}
})
}
}
Loading

0 comments on commit acab2b3

Please sign in to comment.