diff --git a/cmd/gost/main.go b/cmd/gost/main.go index 4165556..7169efa 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -79,7 +79,13 @@ func initChain() (*gost.Chain, error) { if err != nil { return nil, err } - + users, err := parseUsers(node.Values.Get("secrets")) + if err != nil { + return nil, err + } + if node.User == nil && len(users) > 0 { + node.User = users[0] + } serverName, _, _ := net.SplitHostPort(node.Addr) if serverName == "" { serverName = "localhost" // default server name diff --git a/cmd/gost/secrets.txt b/cmd/gost/secrets.txt index a2a94f7..4b5f9d4 100644 --- a/cmd/gost/secrets.txt +++ b/cmd/gost/secrets.txt @@ -1,6 +1,8 @@ # username password -test\admin 123456 -$test 123456 +$test.admin$ $123456$ +@test.admin@ @123456@ +test.admin# #123456# +test.admin\admin 123456 test001 123456 test002 12345678 \ No newline at end of file diff --git a/http.go b/http.go index a17f696..bd01534 100644 --- a/http.go +++ b/http.go @@ -36,12 +36,10 @@ func (c *httpConnector) Connect(conn net.Conn, addr string) (net.Conn, error) { req.Header.Set("Proxy-Connection", "keep-alive") if c.User != nil { - s := c.User.String() - if _, set := c.User.Password(); !set { - s += ":" - } + u := c.User.Username() + p, _ := c.User.Password() req.Header.Set("Proxy-Authorization", - "Basic "+base64.StdEncoding.EncodeToString([]byte(s))) + "Basic "+base64.StdEncoding.EncodeToString([]byte(u+":"+p))) } if err := req.Write(conn); err != nil { diff --git a/http2.go b/http2.go index d63b443..340d471 100644 --- a/http2.go +++ b/http2.go @@ -48,8 +48,10 @@ func (c *http2Connector) Connect(conn net.Conn, addr string) (net.Conn, error) { } req.Header.Set("Gost-Target", addr) if c.User != nil { + u := c.User.Username() + p, _ := c.User.Password() req.Header.Set("Proxy-Authorization", - "Basic "+base64.StdEncoding.EncodeToString([]byte(c.User.String()))) + "Basic "+base64.StdEncoding.EncodeToString([]byte(u+":"+p))) } if Debug { dump, _ := httputil.DumpRequest(req, false)