github.com/sagernet/sing-box@v1.9.0-rc.20/cmd/sing-box/cmd_generate_ech.go (about) 1 package main 2 3 import ( 4 "os" 5 6 "github.com/sagernet/sing-box/common/tls" 7 "github.com/sagernet/sing-box/log" 8 9 "github.com/spf13/cobra" 10 ) 11 12 var pqSignatureSchemesEnabled bool 13 14 var commandGenerateECHKeyPair = &cobra.Command{ 15 Use: "ech-keypair <plain_server_name>", 16 Short: "Generate TLS ECH key pair", 17 Args: cobra.ExactArgs(1), 18 Run: func(cmd *cobra.Command, args []string) { 19 err := generateECHKeyPair(args[0]) 20 if err != nil { 21 log.Fatal(err) 22 } 23 }, 24 } 25 26 func init() { 27 commandGenerateECHKeyPair.Flags().BoolVar(&pqSignatureSchemesEnabled, "pq-signature-schemes-enabled", false, "Enable PQ signature schemes") 28 commandGenerate.AddCommand(commandGenerateECHKeyPair) 29 } 30 31 func generateECHKeyPair(serverName string) error { 32 configPem, keyPem, err := tls.ECHKeygenDefault(serverName, pqSignatureSchemesEnabled) 33 if err != nil { 34 return err 35 } 36 os.Stdout.WriteString(configPem) 37 os.Stdout.WriteString(keyPem) 38 return nil 39 }