Skip to content

Commit

Permalink
don't create enc key if enc key dir is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
makew0rld committed Jul 3, 2024
1 parent 9017c92 commit 3c421b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"

"github.com/starlinglab/integrity-v2/aa"
"github.com/starlinglab/integrity-v2/config"
"github.com/starlinglab/integrity-v2/util"
)

Expand Down Expand Up @@ -51,6 +52,9 @@ func Run(args []string) error {
return fmt.Errorf("error reading key: %w", err)
}
} else if isEncrypted {
if config.GetConfig().Dirs.EncKeys == "" {
return fmt.Errorf("enc_keys path is not configured, are you on the server?")
}
var err error
_, encKey, _, err = util.GenerateEncKey(cid, attr)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions util/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const (
// and stores it in a file. If the key already exists, it is read from the file.
func GenerateEncKey(cid, attr string) (encKeyPath string, encKeyBytes []byte, isNew bool, err error) {
conf := config.GetConfig()

if conf.Dirs.EncKeys == "" {
return "", nil, false, fmt.Errorf("enc_keys path is not configured")
}

encKeyPath = filepath.Join(conf.Dirs.EncKeys, fmt.Sprintf("%s_%s.key", cid, attr))
f, err := os.OpenFile(encKeyPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
Expand Down

0 comments on commit 3c421b8

Please sign in to comment.