From 952584e0649d78d1458e09bf9320caf4d4fb9798 Mon Sep 17 00:00:00 2001 From: ravenclaw900 <50060110+ravenclaw900@users.noreply.github.com> Date: Fri, 15 Apr 2022 17:11:56 -0500 Subject: [PATCH] Make work with http proxy --- pkg/config/proxy.go | 2 ++ pkg/msg/msg.go | 1 + pkg/util/vhost/http.go | 10 +++++++++- pkg/util/vhost/vhost.go | 1 + server/proxy/http.go | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/config/proxy.go b/pkg/config/proxy.go index f92b58cb..5aff8382 100644 --- a/pkg/config/proxy.go +++ b/pkg/config/proxy.go @@ -754,6 +754,7 @@ func (cfg *HTTPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) { cfg.HostHeaderRewrite = pMsg.HostHeaderRewrite cfg.HTTPUser = pMsg.HTTPUser cfg.HTTPPwd = pMsg.HTTPPwd + cfg.HashedPwd = pMsg.HashedPwd cfg.Headers = pMsg.Headers } @@ -767,6 +768,7 @@ func (cfg *HTTPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) { pMsg.HostHeaderRewrite = cfg.HostHeaderRewrite pMsg.HTTPUser = cfg.HTTPUser pMsg.HTTPPwd = cfg.HTTPPwd + pMsg.HashedPwd = cfg.HashedPwd pMsg.Headers = cfg.Headers } diff --git a/pkg/msg/msg.go b/pkg/msg/msg.go index 6e59b7cf..f427443c 100644 --- a/pkg/msg/msg.go +++ b/pkg/msg/msg.go @@ -102,6 +102,7 @@ type NewProxy struct { Locations []string `json:"locations"` HTTPUser string `json:"http_user"` HTTPPwd string `json:"http_pwd"` + HashedPwd bool `json:"hashed_pwd"` HostHeaderRewrite string `json:"host_header_rewrite"` Headers map[string]string `json:"headers"` diff --git a/pkg/util/vhost/http.go b/pkg/util/vhost/http.go index b7208627..fb5ba336 100644 --- a/pkg/util/vhost/http.go +++ b/pkg/util/vhost/http.go @@ -28,6 +28,7 @@ import ( frpLog "github.com/fatedier/frp/pkg/util/log" "github.com/fatedier/frp/pkg/util/util" + "golang.org/x/crypto/bcrypt" "github.com/fatedier/golib/pool" ) @@ -154,7 +155,14 @@ func (rp *HTTPReverseProxy) CheckAuth(domain, location, user, passwd string) boo if ok { checkUser := vr.payload.(*RouteConfig).Username checkPasswd := vr.payload.(*RouteConfig).Password - if (checkUser != "" || checkPasswd != "") && (checkUser != user || checkPasswd != passwd) { + hashed := vr.payload.(*RouteConfig).Hashed + var correctPwd bool + if hashed { + correctPwd = bcrypt.CompareHashAndPassword([]byte(checkPasswd), []byte(passwd)) == nil + } else { + correctPwd = checkPasswd == passwd + } + if (checkUser != "" || checkPasswd != "") && (checkUser != user || !correctPwd) { return false } } diff --git a/pkg/util/vhost/vhost.go b/pkg/util/vhost/vhost.go index 4239d113..581a9424 100644 --- a/pkg/util/vhost/vhost.go +++ b/pkg/util/vhost/vhost.go @@ -75,6 +75,7 @@ type RouteConfig struct { Headers map[string]string CreateConnFn CreateConnFunc + Hashed bool } // listen for a new domain name, if rewriteHost is not empty and rewriteFunc is not nil diff --git a/server/proxy/http.go b/server/proxy/http.go index 86925281..67601fd0 100644 --- a/server/proxy/http.go +++ b/server/proxy/http.go @@ -43,6 +43,7 @@ func (pxy *HTTPProxy) Run() (remoteAddr string, err error) { Username: pxy.cfg.HTTPUser, Password: pxy.cfg.HTTPPwd, CreateConnFn: pxy.GetRealConn, + Hashed: pxy.cfg.HashedPwd, } locations := pxy.cfg.Locations