node: add info message when JWT secret is loaded (#25095)

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Marius van der Wijden 2022-06-15 14:35:53 +02:00 committed by GitHub
parent d8f963811d
commit d78d302f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ import (
crand "crypto/rand" crand "crypto/rand"
"errors" "errors"
"fmt" "fmt"
"hash/crc32"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -352,10 +353,10 @@ func (n *Node) obtainJWTSecret(cliParam string) ([]byte, error) {
fileName = n.ResolvePath(datadirJWTKey) fileName = n.ResolvePath(datadirJWTKey)
} }
// try reading from file // try reading from file
log.Debug("Reading JWT secret", "path", fileName)
if data, err := os.ReadFile(fileName); err == nil { if data, err := os.ReadFile(fileName); err == nil {
jwtSecret := common.FromHex(strings.TrimSpace(string(data))) jwtSecret := common.FromHex(strings.TrimSpace(string(data)))
if len(jwtSecret) == 32 { if len(jwtSecret) == 32 {
log.Info("Loaded JWT secret file", "path", fileName, "crc32", fmt.Sprintf("%#x", crc32.ChecksumIEEE(jwtSecret)))
return jwtSecret, nil return jwtSecret, nil
} }
log.Error("Invalid JWT secret", "path", fileName, "length", len(jwtSecret)) log.Error("Invalid JWT secret", "path", fileName, "length", len(jwtSecret))