node: add JWT secret log line #25095 (#1036)

This commit is contained in:
JukLee0ira 2025-05-16 12:03:11 +08:00 committed by GitHub
parent c145287e87
commit 47dae16a40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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"
@ -360,10 +361,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))