From 1d3f45dc82356739857cced2f0daf1d1b9c535a9 Mon Sep 17 00:00:00 2001 From: Omid The Great Date: Sun, 28 Jan 2024 19:08:51 +0330 Subject: [PATCH] Add certification generator to cli --- cmd/cmd_gen_cert.go | 20 ++++++++++++++++++++ cmd/main.go | 1 + 2 files changed, 21 insertions(+) create mode 100644 cmd/cmd_gen_cert.go diff --git a/cmd/cmd_gen_cert.go b/cmd/cmd_gen_cert.go new file mode 100644 index 0000000..a441825 --- /dev/null +++ b/cmd/cmd_gen_cert.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/hiddify/libcore/utils" + "github.com/spf13/cobra" + "os" +) + +var commandGenerateCertification = &cobra.Command{ + Use: "gen-cert", + Short: "Generate certification for web server", + Run: func(cmd *cobra.Command, args []string) { + err := os.MkdirAll("cert", 600) + if err != nil { + panic("Error: " + err.Error()) + } + utils.GenerateCertificate("cert/server-cert.pem", "cert/server-key.pem", true) + utils.GenerateCertificate("cert/client-cert.pem", "cert/client-key.pem", false) + }, +} diff --git a/cmd/main.go b/cmd/main.go index b067212..779d241 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -23,6 +23,7 @@ var mainCommand = &cobra.Command{ func init() { mainCommand.AddCommand(commandService) + mainCommand.AddCommand(commandGenerateCertification) commandService.AddCommand(commandServiceStart) commandService.AddCommand(commandServiceStop)