logic fix
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-09 21:34:47 +11:00
parent b4355ee913
commit 203a564b04

View File

@@ -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