Skip to content

Commit

Permalink
setup: infer the key type from the key hierarchy
Browse files Browse the repository at this point in the history
Signed-off-by: Morten Linderud <[email protected]>
  • Loading branch information
Foxboron committed Jul 30, 2024
1 parent 7ddcbea commit 98466dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ type KeyHierarchy struct {
state *config.State
}

func (k *KeyHierarchy) GetConfig(keydir string) *config.Keys {
return &config.Keys{
PK: &config.KeyConfig{
Privkey: filepath.Join(keydir, "PK/PK.key"),
Pubkey: filepath.Join(keydir, "PK/PK.pem"),
Type: string(k.PK.Type()),
},
KEK: &config.KeyConfig{
Privkey: filepath.Join(keydir, "KEK/KEK.key"),
Pubkey: filepath.Join(keydir, "KEK/KEK.pem"),
Type: string(k.KEK.Type()),
},
Db: &config.KeyConfig{
Privkey: filepath.Join(keydir, "db/db.key"),
Pubkey: filepath.Join(keydir, "db/db.pem"),
Type: string(k.Db.Type()),
},
}
}

func NewKeyHierarchy(state *config.State) *KeyHierarchy {
return &KeyHierarchy{
state: state,
Expand Down
7 changes: 7 additions & 0 deletions cmd/sbctl/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"

"github.com/foxboron/sbctl"
"github.com/foxboron/sbctl/backend"
"github.com/foxboron/sbctl/config"
"github.com/foxboron/sbctl/logging"
"github.com/foxboron/sbctl/lsm"
Expand Down Expand Up @@ -47,6 +48,12 @@ func PrintConfig(state *config.State) error {
if err != nil {
return err
}
} else {
kh, err := backend.GetKeyHierarchy(state.Fs, state)
if err != nil {
return err
}
state.Config.Keys = kh.GetConfig(state.Config.Keydir)
}

// Setup the files
Expand Down

0 comments on commit 98466dc

Please sign in to comment.