go-http-peering/cmd/keygen/main.go

64 lines
1.5 KiB
Go
Raw Permalink Normal View History

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
verifyTokenCmd = false
2019-02-22 17:35:49 +01:00
debug = false
keyFile string
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",
)
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")
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()
case verifyTokenCmd:
verifyToken()
2019-02-22 17:35:49 +01:00
default:
flag.Usage()
}
}