From 203a564b0422d7f58000ac11d71a05b1f7681d12 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 9 Jan 2024 21:34:47 +1100 Subject: [PATCH] logic fix --- models/key.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/models/key.go b/models/key.go index 50be628..2b5259b 100644 --- a/models/key.go +++ b/models/key.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "smt/utils" "golang.org/x/crypto/bcrypt" ) @@ -73,7 +74,7 @@ func ReceiveKey(key string) error { // TODO hash the secret key and store it on disk so we can verify if correct secret key is received filePath, _ := getHashFilePath() - if filePath != "" { + if filePath != "" && utils.FileExists(filePath) { log.Printf("ReceiveKey detected hash file at '%s'\n", filePath) // File already exists, compare received key with hash in file compare, err := compareHashWithPlaintext(key, filePath) @@ -83,9 +84,11 @@ func ReceiveKey(key string) error { if !compare { return errors.New("secret key is not correct") } - } else { + } else if filePath != "" { log.Printf("ReceiveKey storing key into file '%s'\n", filePath) storeKeyHash(key, filePath) + } else { + return fmt.Errorf("unable to determine path to key hash file '%s'", hashFileName) } // Store the secret key in memory so that we can access it when encrypting/decrypting