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" "log"
"os" "os"
"path/filepath" "path/filepath"
"smt/utils"
"golang.org/x/crypto/bcrypt" "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 // TODO hash the secret key and store it on disk so we can verify if correct secret key is received
filePath, _ := getHashFilePath() filePath, _ := getHashFilePath()
if filePath != "" { if filePath != "" && utils.FileExists(filePath) {
log.Printf("ReceiveKey detected hash file at '%s'\n", filePath) log.Printf("ReceiveKey detected hash file at '%s'\n", filePath)
// File already exists, compare received key with hash in file // File already exists, compare received key with hash in file
compare, err := compareHashWithPlaintext(key, filePath) compare, err := compareHashWithPlaintext(key, filePath)
@@ -83,9 +84,11 @@ func ReceiveKey(key string) error {
if !compare { if !compare {
return errors.New("secret key is not correct") return errors.New("secret key is not correct")
} }
} else { } else if filePath != "" {
log.Printf("ReceiveKey storing key into file '%s'\n", filePath) log.Printf("ReceiveKey storing key into file '%s'\n", filePath)
storeKeyHash(key, 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 // Store the secret key in memory so that we can access it when encrypting/decrypting