Skip to content

Commit

Permalink
Use auto generated certificates if plugin_key_path and plugin_crt_pat…
Browse files Browse the repository at this point in the history
…h are empty for plugin https2https and https2http. (fatedier#2968)
  • Loading branch information
fatedier authored Jun 5, 2022
1 parent 0711295 commit 5b8b145
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 11 additions & 7 deletions pkg/plugin/client/https2http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http/httputil"
"strings"

"github.com/fatedier/frp/pkg/transport"
frpNet "github.com/fatedier/frp/pkg/util/net"
)

Expand Down Expand Up @@ -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 == "" {
return nil, fmt.Errorf("plugin_local_addr is required")
}
Expand Down Expand Up @@ -96,7 +91,16 @@ func NewHTTPS2HTTPPlugin(params map[string]string) (Plugin, error) {
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 {
return nil, fmt.Errorf("gen TLS config error: %v", err)
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/plugin/client/https2https.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http/httputil"
"strings"

"github.com/fatedier/frp/pkg/transport"
frpNet "github.com/fatedier/frp/pkg/util/net"
)

Expand Down Expand Up @@ -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 == "" {
return nil, fmt.Errorf("plugin_local_addr is required")
}
Expand Down Expand Up @@ -101,7 +96,16 @@ func NewHTTPS2HTTPSPlugin(params map[string]string) (Plugin, error) {
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 {
return nil, fmt.Errorf("gen TLS config error: %v", err)
}
Expand All @@ -127,7 +131,7 @@ func (p *HTTPS2HTTPSPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, e
}

func (p *HTTPS2HTTPSPlugin) Name() string {
return PluginHTTPS2HTTP
return PluginHTTPS2HTTPS
}

func (p *HTTPS2HTTPSPlugin) Close() error {
Expand Down

0 comments on commit 5b8b145

Please sign in to comment.