fix(keygen): correctly load token for validation
Some checks failed
Cadoles/go-http-peering/pipeline/head There was a failure building this commit

This commit is contained in:
2024-01-05 11:12:27 +01:00
parent db06098fdd
commit b28a87cc5d
4 changed files with 65 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"syscall"
"forge.cadoles.com/Cadoles/go-http-peering/crypto"
@ -63,17 +64,17 @@ func loadPrivateKey() (*rsa.PrivateKey, error) {
return privateKey, nil
}
func loadToken() ([]byte, error) {
func loadToken() (string, error) {
if tokenFile == "" {
return nil, errors.New("you must specify a token file to load")
return "", errors.New("you must specify a token file to load")
}
token, err := os.ReadFile(tokenFile)
if err != nil {
return nil, errors.WithStack(err)
return "", errors.WithStack(err)
}
return token, nil
return strings.TrimSpace(string(token)), nil
}
func handleError(err error) {

View File

@ -24,7 +24,7 @@ func verifyToken() {
return &privateKey.PublicKey, nil
}
token, err := jwt.ParseWithClaims(string(rawToken), &peering.ServerTokenClaims{}, fn)
token, err := jwt.ParseWithClaims(rawToken, &peering.ServerTokenClaims{}, fn)
if err != nil {
validationError, ok := err.(*jwt.ValidationError)
if ok {