peergate.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright © 2021 Ettore Di Giacinto <[email protected]>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program; if not, see <http://www.gnu.org/licenses/>.
  15. package cmd
  16. import (
  17. "fmt"
  18. "github.com/mudler/edgevpn/pkg/trustzone/authprovider/ecdsa"
  19. "github.com/urfave/cli"
  20. )
  21. func Peergate() cli.Command {
  22. return cli.Command{
  23. Name: "peergater",
  24. Usage: "peergater ecdsa-genkey",
  25. Description: `Peergater auth utilities`,
  26. Subcommands: cli.Commands{
  27. {
  28. Name: "ecdsa-genkey",
  29. Flags: []cli.Flag{
  30. &cli.BoolFlag{
  31. Name: "privkey",
  32. },
  33. &cli.BoolFlag{
  34. Name: "pubkey",
  35. },
  36. },
  37. Action: func(c *cli.Context) error {
  38. priv, pub, err := ecdsa.GenerateKeys()
  39. if !c.Bool("privkey") && !c.Bool("pubkey") {
  40. fmt.Printf("Private key: %s\n", string(priv))
  41. fmt.Printf("Public key: %s\n", string(pub))
  42. } else if c.Bool("privkey") {
  43. fmt.Printf(string(priv))
  44. } else if c.Bool("pubkey") {
  45. fmt.Printf(string(pub))
  46. }
  47. return err
  48. },
  49. },
  50. },
  51. }
  52. }