2019-02-22 17:35:49 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
"github.com/pborman/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// nolint:gochecknoglobals
|
|
|
|
var (
|
|
|
|
createKeyCmd = false
|
|
|
|
getPublicKeyCmd = false
|
|
|
|
createTokenCmd = false
|
2024-01-04 16:21:40 +01:00
|
|
|
verifyTokenCmd = false
|
2019-02-22 17:35:49 +01:00
|
|
|
debug = false
|
|
|
|
keyFile string
|
2024-01-04 16:21:40 +01:00
|
|
|
tokenFile string
|
2019-02-22 17:35:49 +01:00
|
|
|
tokenIssuer string
|
|
|
|
tokenPeerID = uuid.New()
|
|
|
|
keySize = 2048
|
|
|
|
)
|
|
|
|
|
|
|
|
// nolint:gochecknoinits
|
|
|
|
func init() {
|
|
|
|
flag.BoolVar(
|
|
|
|
&createKeyCmd, "create-key", createKeyCmd,
|
|
|
|
"Create a new encrypted PEM private key to sign authentication tokens",
|
|
|
|
)
|
|
|
|
flag.BoolVar(
|
|
|
|
&createTokenCmd, "create-token", createTokenCmd,
|
|
|
|
"Create a new signed authentication token",
|
|
|
|
)
|
2024-01-04 16:21:40 +01:00
|
|
|
flag.BoolVar(
|
|
|
|
&verifyTokenCmd, "verify-token", verifyTokenCmd,
|
|
|
|
"Verify a token generated with the given key",
|
|
|
|
)
|
2019-02-22 17:35:49 +01:00
|
|
|
flag.BoolVar(
|
|
|
|
&getPublicKeyCmd, "get-public-key", getPublicKeyCmd,
|
|
|
|
"Get the PEM encoded public key associated with the private key",
|
|
|
|
)
|
|
|
|
flag.BoolVar(&debug, "debug", debug, "Debug mode")
|
|
|
|
flag.StringVar(&keyFile, "key", keyFile, "Path to the encrypted PEM encoded key")
|
2024-01-04 16:21:40 +01:00
|
|
|
flag.StringVar(&tokenFile, "token", tokenFile, "Path to the token to verify")
|
2019-02-22 17:35:49 +01:00
|
|
|
flag.StringVar(&tokenIssuer, "token-issuer", tokenIssuer, "Token issuer")
|
|
|
|
flag.StringVar(&tokenPeerID, "token-peer-id", tokenPeerID, "Token peer ID")
|
|
|
|
flag.IntVar(&keySize, "key-size", keySize, "Size of the private key")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
switch {
|
|
|
|
case createKeyCmd:
|
|
|
|
createKey()
|
|
|
|
case getPublicKeyCmd:
|
|
|
|
getPublicKey()
|
|
|
|
case createTokenCmd:
|
|
|
|
createToken()
|
2024-01-04 16:21:40 +01:00
|
|
|
case verifyTokenCmd:
|
|
|
|
verifyToken()
|
2019-02-22 17:35:49 +01:00
|
|
|
default:
|
|
|
|
flag.Usage()
|
|
|
|
}
|
|
|
|
}
|