fix(keygen): correctly load token for validation
Some checks failed
Cadoles/go-http-peering/pipeline/head There was a failure building this commit
Some checks failed
Cadoles/go-http-peering/pipeline/head There was a failure building this commit
This commit is contained in:
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user