Use auto generated certificates if plugin_key_path and plugin_crt_path are empty for plugin https2https and https2http. (#2968)

This commit is contained in:
fatedier 2022-06-05 17:15:28 +08:00 committed by GitHub
parent 0711295b0a
commit 5b8b145577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 15 deletions

View File

@ -23,6 +23,7 @@ import (
"net/http/httputil" "net/http/httputil"
"strings" "strings"
"github.com/fatedier/frp/pkg/transport"
frpNet "github.com/fatedier/frp/pkg/util/net" frpNet "github.com/fatedier/frp/pkg/util/net"
) )
@ -58,12 +59,6 @@ func NewHTTPS2HTTPPlugin(params map[string]string) (Plugin, error) {
} }
} }
if crtPath == "" {
return nil, fmt.Errorf("plugin_crt_path is required")
}
if keyPath == "" {
return nil, fmt.Errorf("plugin_key_path is required")
}
if localAddr == "" { if localAddr == "" {
return nil, fmt.Errorf("plugin_local_addr is required") return nil, fmt.Errorf("plugin_local_addr is required")
} }
@ -96,7 +91,16 @@ func NewHTTPS2HTTPPlugin(params map[string]string) (Plugin, error) {
Handler: rp, Handler: rp,
} }
tlsConfig, err := p.genTLSConfig() var (
tlsConfig *tls.Config
err error
)
if crtPath != "" || keyPath != "" {
tlsConfig, err = p.genTLSConfig()
} else {
tlsConfig, err = transport.NewServerTLSConfig("", "", "")
tlsConfig.InsecureSkipVerify = true
}
if err != nil { if err != nil {
return nil, fmt.Errorf("gen TLS config error: %v", err) return nil, fmt.Errorf("gen TLS config error: %v", err)
} }

View File

@ -23,6 +23,7 @@ import (
"net/http/httputil" "net/http/httputil"
"strings" "strings"
"github.com/fatedier/frp/pkg/transport"
frpNet "github.com/fatedier/frp/pkg/util/net" frpNet "github.com/fatedier/frp/pkg/util/net"
) )
@ -58,12 +59,6 @@ func NewHTTPS2HTTPSPlugin(params map[string]string) (Plugin, error) {
} }
} }
if crtPath == "" {
return nil, fmt.Errorf("plugin_crt_path is required")
}
if keyPath == "" {
return nil, fmt.Errorf("plugin_key_path is required")
}
if localAddr == "" { if localAddr == "" {
return nil, fmt.Errorf("plugin_local_addr is required") return nil, fmt.Errorf("plugin_local_addr is required")
} }
@ -101,7 +96,16 @@ func NewHTTPS2HTTPSPlugin(params map[string]string) (Plugin, error) {
Handler: rp, Handler: rp,
} }
tlsConfig, err := p.genTLSConfig() var (
tlsConfig *tls.Config
err error
)
if crtPath != "" || keyPath != "" {
tlsConfig, err = p.genTLSConfig()
} else {
tlsConfig, err = transport.NewServerTLSConfig("", "", "")
tlsConfig.InsecureSkipVerify = true
}
if err != nil { if err != nil {
return nil, fmt.Errorf("gen TLS config error: %v", err) return nil, fmt.Errorf("gen TLS config error: %v", err)
} }
@ -127,7 +131,7 @@ func (p *HTTPS2HTTPSPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, e
} }
func (p *HTTPS2HTTPSPlugin) Name() string { func (p *HTTPS2HTTPSPlugin) Name() string {
return PluginHTTPS2HTTP return PluginHTTPS2HTTPS
} }
func (p *HTTPS2HTTPSPlugin) Close() error { func (p *HTTPS2HTTPSPlugin) Close() error {