Files
reseed-tools/cmd/keygen.go
2014-12-14 23:12:14 -06:00

50 lines
1003 B
Go

package cmd
import (
"fmt"
"github.com/codegangsta/cli"
)
func NewKeygenCommand() cli.Command {
return cli.Command{
Name: "keygen",
Usage: "Generate keys for reseed su3 signing and TLS serving.",
Action: keygenAction,
Flags: []cli.Flag{
cli.StringFlag{
Name: "signer",
Usage: "Generate a private key and certificate for the given su3 signing ID (ex. something@mail.i2p)",
},
cli.StringFlag{
Name: "tlsHost",
Usage: "Generate a self-signed TLS certificate and private key for the given host",
},
},
}
}
func keygenAction(c *cli.Context) {
signerId := c.String("signer")
tlsHost := c.String("tlsHost")
if signerId == "" && tlsHost == "" {
fmt.Println("You must specify either --tlsHost or --signer")
return
}
if signerId != "" {
if err := createSigningCertificate(signerId); nil != err {
fmt.Println(err)
return
}
}
if tlsHost != "" {
if err := createTLSCertificate(tlsHost); nil != err {
fmt.Println(err)
return
}
}
}