From 591023a1f04831999863e0f9deafb2c6e234c71d Mon Sep 17 00:00:00 2001 From: Tank Date: Tue, 12 May 2020 14:33:34 +0800 Subject: [PATCH] fix: add frpc tls_enable flag and frps tls_only flag (#1798) --- cmd/frpc/sub/http.go | 1 + cmd/frpc/sub/https.go | 1 + cmd/frpc/sub/root.go | 3 +++ cmd/frpc/sub/stcp.go | 1 + cmd/frpc/sub/sudp.go | 1 + cmd/frpc/sub/tcp.go | 1 + cmd/frpc/sub/tcpmux.go | 1 + cmd/frpc/sub/udp.go | 1 + cmd/frpc/sub/xtcp.go | 1 + cmd/frps/root.go | 3 +++ 10 files changed, 14 insertions(+) diff --git a/cmd/frpc/sub/http.go b/cmd/frpc/sub/http.go index 081102c..55aa2e9 100644 --- a/cmd/frpc/sub/http.go +++ b/cmd/frpc/sub/http.go @@ -46,6 +46,7 @@ func init() { httpCmd.PersistentFlags().StringVarP(&hostHeaderRewrite, "host_header_rewrite", "", "", "host header rewrite") httpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") httpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + httpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(httpCmd) } diff --git a/cmd/frpc/sub/https.go b/cmd/frpc/sub/https.go index 7d5fbe8..039054b 100644 --- a/cmd/frpc/sub/https.go +++ b/cmd/frpc/sub/https.go @@ -42,6 +42,7 @@ func init() { httpsCmd.PersistentFlags().StringVarP(&subDomain, "sd", "", "", "sub domain") httpsCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") httpsCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + httpsCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(httpsCmd) } diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 8f47986..14c53b8 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -71,6 +71,8 @@ var ( bindAddr string bindPort int + tlsEnable bool + kcpDoneCh chan struct{} ) @@ -172,6 +174,7 @@ func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) { // Only token authentication is supported in cmd mode cfg.AuthClientConfig = auth.GetDefaultAuthClientConf() cfg.Token = token + cfg.TLSEnable = tlsEnable return } diff --git a/cmd/frpc/sub/stcp.go b/cmd/frpc/sub/stcp.go index 1a04fbf..e51d21f 100644 --- a/cmd/frpc/sub/stcp.go +++ b/cmd/frpc/sub/stcp.go @@ -44,6 +44,7 @@ func init() { stcpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") stcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") stcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + stcpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(stcpCmd) } diff --git a/cmd/frpc/sub/sudp.go b/cmd/frpc/sub/sudp.go index e3e91ab..63da237 100644 --- a/cmd/frpc/sub/sudp.go +++ b/cmd/frpc/sub/sudp.go @@ -44,6 +44,7 @@ func init() { sudpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") sudpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") sudpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + sudpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(sudpCmd) } diff --git a/cmd/frpc/sub/tcp.go b/cmd/frpc/sub/tcp.go index c2ccd2b..f98945a 100644 --- a/cmd/frpc/sub/tcp.go +++ b/cmd/frpc/sub/tcp.go @@ -40,6 +40,7 @@ func init() { tcpCmd.PersistentFlags().IntVarP(&remotePort, "remote_port", "r", 0, "remote port") tcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") tcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + tcpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(tcpCmd) } diff --git a/cmd/frpc/sub/tcpmux.go b/cmd/frpc/sub/tcpmux.go index d67d498..2e1b5f4 100644 --- a/cmd/frpc/sub/tcpmux.go +++ b/cmd/frpc/sub/tcpmux.go @@ -43,6 +43,7 @@ func init() { tcpMuxCmd.PersistentFlags().StringVarP(&multiplexer, "mux", "", "", "multiplexer") tcpMuxCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") tcpMuxCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + tcpMuxCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(tcpMuxCmd) } diff --git a/cmd/frpc/sub/udp.go b/cmd/frpc/sub/udp.go index 0d73c76..40bd9ae 100644 --- a/cmd/frpc/sub/udp.go +++ b/cmd/frpc/sub/udp.go @@ -40,6 +40,7 @@ func init() { udpCmd.PersistentFlags().IntVarP(&remotePort, "remote_port", "r", 0, "remote port") udpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") udpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + udpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(udpCmd) } diff --git a/cmd/frpc/sub/xtcp.go b/cmd/frpc/sub/xtcp.go index 558294d..e0960a1 100644 --- a/cmd/frpc/sub/xtcp.go +++ b/cmd/frpc/sub/xtcp.go @@ -44,6 +44,7 @@ func init() { xtcpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") xtcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") xtcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") + xtcpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(xtcpCmd) } diff --git a/cmd/frps/root.go b/cmd/frps/root.go index 5f50d52..56a406e 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -60,6 +60,7 @@ var ( allowPorts string maxPoolCount int64 maxPortsPerClient int64 + tlsOnly bool ) func init() { @@ -87,6 +88,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&subDomainHost, "subdomain_host", "", "", "subdomain host") rootCmd.PersistentFlags().StringVarP(&allowPorts, "allow_ports", "", "", "allow ports") rootCmd.PersistentFlags().Int64VarP(&maxPortsPerClient, "max_ports_per_client", "", 0, "max ports per client") + rootCmd.PersistentFlags().BoolVarP(&tlsOnly, "tls_only", "", false, "frps tls only") } var rootCmd = &cobra.Command{ @@ -173,6 +175,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) { cfg.LogLevel = logLevel cfg.LogMaxDays = logMaxDays cfg.SubDomainHost = subDomainHost + cfg.TlsOnly = tlsOnly // Only token authentication is supported in cmd mode cfg.AuthServerConfig = auth.GetDefaultAuthServerConf()