doodle/cmd/doodle-admin/command/sign.go
Noah Petherbridge 0449737607 License Key Registration with ECDSA JWT Tokens
* New command-line tool: doodle-admin for signing license keys for
  users. Includes functions to initialize a keypair, sign license keys
  and validate existing keys.
* The Main Menu screen shows a blue "Register Game" button in the bottom
  right corner of the screen, for unregistered users only.
* In Edit Mode, there is a "Help -> Register" menu item that opens the
  License Window.
* The License UI Window lets the user select the license.key file to
  register the game with. If registered, a copy of the key is placed in
  Doodle's profile directory and the licensee name/email is shown in the
  License UI window.
* Unregistered games will show the word "(shareware)" next to the title
  screen version number and Edit Mode status bar.
* No restrictions are yet placed on free versions of the game.
2021-06-16 21:56:30 -07:00

74 lines
1.6 KiB
Go

package command
import (
"fmt"
"io/ioutil"
"git.kirsle.net/apps/doodle/pkg/license"
"git.kirsle.net/apps/doodle/pkg/log"
"github.com/urfave/cli/v2"
)
// Sign a license key for Sketchy Maze.
var Sign *cli.Command
func init() {
Sign = &cli.Command{
Name: "sign",
Usage: "sign a license key for the paid version of Sketchy Maze.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Private key .pem file for signing",
Required: true,
},
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "User name for certificate",
Required: true,
},
&cli.StringFlag{
Name: "email",
Aliases: []string{"e"},
Usage: "User email address",
Required: true,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output file, default outputs to console",
},
},
Action: func(c *cli.Context) error {
key, err := license.AdminLoadPrivateKey(c.String("key"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
reg := license.Registration{
Name: c.String("name"),
Email: c.String("email"),
}
result, err := license.AdminSignRegistration(key, reg)
if err != nil {
return cli.Exit(err.Error(), 1)
}
// Writing to an output file?
if output := c.String("output"); output != "" {
log.Info("Write to: %s", output)
if err := ioutil.WriteFile(output, []byte(result), 0644); err != nil {
return cli.Exit(err, 1)
}
} else {
fmt.Println(result)
}
return nil
},
}
}