From 3c421b887ec4226d3458bb307054730fd2a987f5 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 3 Jul 2024 13:59:08 -0400 Subject: [PATCH] don't create enc key if enc key dir is not set --- get/get.go | 4 ++++ util/key.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/get/get.go b/get/get.go index 077182b..b4acb9a 100644 --- a/get/get.go +++ b/get/get.go @@ -8,6 +8,7 @@ import ( "reflect" "github.com/starlinglab/integrity-v2/aa" + "github.com/starlinglab/integrity-v2/config" "github.com/starlinglab/integrity-v2/util" ) @@ -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 { diff --git a/util/key.go b/util/key.go index 2b35bd2..4747430 100644 --- a/util/key.go +++ b/util/key.go @@ -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 {