Skip to content

Commit

Permalink
Add tls2raw client plugin (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
koho authored Aug 20, 2024
1 parent d98ec50 commit 7ac8f62
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pkg/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ type BaseProxyConf struct {
}

type PluginParams struct {
PluginLocalAddr string `ini:"plugin_local_addr,omitempty" http2https:"true" http2http:"true" https2https:"true" https2http:"true"`
PluginCrtPath string `ini:"plugin_crt_path,omitempty" https2https:"true" https2http:"true"`
PluginKeyPath string `ini:"plugin_key_path,omitempty" https2https:"true" https2http:"true"`
PluginLocalAddr string `ini:"plugin_local_addr,omitempty" http2https:"true" http2http:"true" https2https:"true" https2http:"true" tls2raw:"true"`
PluginCrtPath string `ini:"plugin_crt_path,omitempty" https2https:"true" https2http:"true" tls2raw:"true"`
PluginKeyPath string `ini:"plugin_key_path,omitempty" https2https:"true" https2http:"true" tls2raw:"true"`
PluginHostHeaderRewrite string `ini:"plugin_host_header_rewrite,omitempty" http2https:"true" http2http:"true" https2https:"true" https2http:"true"`
PluginHttpUser string `ini:"plugin_http_user,omitempty" http_proxy:"true" static_file:"true"`
PluginHttpPasswd string `ini:"plugin_http_passwd,omitempty" http_proxy:"true" static_file:"true"`
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func clientProxyBaseFromV1(c *v1.ProxyBaseConfig, out *Proxy) {
out.PluginHttpPasswd = v.HTTPPassword
case *v1.UnixDomainSocketPluginOptions:
out.PluginUnixPath = v.UnixPath
case *v1.TLS2RawPluginOptions:
out.PluginLocalAddr = v.LocalAddr
out.PluginCrtPath = v.CrtPath
out.PluginKeyPath = v.KeyPath
}
}

Expand Down Expand Up @@ -576,6 +580,13 @@ func clientProxyBaseToV1(c *BaseProxyConf) (v1.ProxyBaseConfig, error) {
Type: c.Plugin,
UnixPath: c.PluginUnixPath,
}
case consts.PluginTLS2Raw:
r.ProxyBackend.Plugin.ClientPluginOptions = &v1.TLS2RawPluginOptions{
Type: c.Plugin,
LocalAddr: c.PluginLocalAddr,
CrtPath: c.PluginCrtPath,
KeyPath: c.PluginKeyPath,
}
}
return r, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/consts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const (
PluginHttp2Https = "http2https"
PluginHttp2Http = "http2http"
PluginUnixDomain = "unix_domain_socket"
PluginTLS2Raw = "tls2raw"
)

var PluginTypes = []string{
PluginHttp2Http, PluginHttp2Https, PluginHttps2Http, PluginHttps2Https,
PluginHttpProxy, PluginSocks5, PluginStaticFile, PluginUnixDomain,
PluginHttpProxy, PluginSocks5, PluginStaticFile, PluginUnixDomain, PluginTLS2Raw,
}

// Auth methods
Expand Down
23 changes: 17 additions & 6 deletions ui/editproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type proxyViewModel struct {
PluginStaticVisible bool
PluginHTTPFwdVisible bool
PluginCertVisible bool
PluginAddrVisible bool
HealthCheckEnable bool
HealthCheckVisible bool
HealthCheckURLVisible bool
Expand Down Expand Up @@ -321,7 +322,7 @@ func (pd *EditProxyDialog) advancedProxyPage() TabPage {
CheckBox{Name: "keepTunnel", Visible: xtcpVisitor, Text: i18n.Sprintf("Keep Tunnel"), Checked: Bind("KeepTunnelOpen")},
CheckBox{Text: i18n.Sprintf("Encryption"), Checked: Bind("UseEncryption")},
CheckBox{Text: i18n.Sprintf("Compression"), Checked: Bind("UseCompression")},
CheckBox{Text: "HTTP/2", Visible: Bind("vm.PluginCertVisible"), Checked: Bind("PluginEnableHTTP2")},
CheckBox{Text: "HTTP/2", Visible: Bind("vm.PluginHTTPFwdVisible && vm.PluginCertVisible"), Checked: Bind("PluginEnableHTTP2")},
},
},
Label{Visible: xtcpVisitor, Text: i18n.SprintfColon("Fallback")},
Expand Down Expand Up @@ -398,15 +399,20 @@ func (pd *EditProxyDialog) pluginProxyPage() TabPage {
LineEdit{Visible: Bind("vm.PluginAuthVisible"), Text: Bind("PluginUser")},
Label{Visible: Bind("vm.PluginAuthVisible"), Text: i18n.SprintfColon("Password")},
LineEdit{Visible: Bind("vm.PluginAuthVisible"), Text: Bind("PluginPasswd"), PasswordMode: true},
Label{Visible: Bind("vm.PluginHTTPFwdVisible"), Text: i18n.SprintfColon("Local Address")},
Label{Visible: Bind("vm.PluginAddrVisible"), Text: i18n.SprintfColon("Local Address")},
Composite{
Visible: Bind("vm.PluginHTTPFwdVisible"),
Visible: Bind("vm.PluginAddrVisible"),
Layout: HBox{MarginsZero: true},
Children: []Widget{
LineEdit{Text: Bind("PluginLocalAddr")},
ToolButton{Text: "H", ToolTipText: i18n.Sprintf("Request headers"), OnClicked: func() {
NewAttributeDialog(i18n.Sprintf("Request headers"), &pd.binder.PluginHeaders).Run(pd.Form())
}},
ToolButton{
Visible: Bind("vm.PluginHTTPFwdVisible"),
Text: "H",
ToolTipText: i18n.Sprintf("Request headers"),
OnClicked: func() {
NewAttributeDialog(i18n.Sprintf("Request headers"), &pd.binder.PluginHeaders).Run(pd.Form())
},
},
},
},
Label{Visible: Bind("vm.PluginCertVisible"), Text: i18n.SprintfColon("Certificate")},
Expand Down Expand Up @@ -597,10 +603,15 @@ func (pd *EditProxyDialog) switchType() {
pd.viewModel.PluginStaticVisible = true
pd.viewModel.PluginHTTPAuthVisible = true
case consts.PluginHttps2Http, consts.PluginHttps2Https:
pd.viewModel.PluginAddrVisible = true
pd.viewModel.PluginHTTPFwdVisible = true
pd.viewModel.PluginCertVisible = true
case consts.PluginHttp2Https, consts.PluginHttp2Http:
pd.viewModel.PluginAddrVisible = true
pd.viewModel.PluginHTTPFwdVisible = true
case consts.PluginTLS2Raw:
pd.viewModel.PluginAddrVisible = true
pd.viewModel.PluginCertVisible = true
}
}
}
Expand Down

0 comments on commit 7ac8f62

Please sign in to comment.