Skip to content

Commit

Permalink
new feature multi user auth with socks5
Browse files Browse the repository at this point in the history
  • Loading branch information
arugal committed Sep 12, 2019
1 parent 5e55b76 commit a05995f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ loop:
tl.Password = t.Password
tl.LocalPath = t.LocalPath
tl.StripPre = t.StripPre
tl.MultiUser = t.MultiUser
if !client.HasTunnel(tl) {
if err := file.GetDb().NewTask(tl); err != nil {
logs.Notice("Add task error ", err.Error())
Expand Down
5 changes: 2 additions & 3 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,14 @@ func dealTunnel(s string) *file.Tunnel {
case "strip_pre":
t.StripPre = item[1]
case "multi_user":
// TODO add test with multi user config file
t.Client.Cnf.MultiUser = true
t.MultiUser = new(file.MultiUser)
if b, err := common.ReadAllFromFile(item[1]); err != nil {
panic(err)
} else {
if content, err := common.ParseStr(string(b)); err != nil {
panic(err)
} else {
t.Client.Cnf.MultiUserMap = dealMultiUser(content)
t.MultiUser.UserMap = dealMultiUser(content)
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions lib/file/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ func (s *Flow) Add(in, out int64) {
}

type Config struct {
U string
P string
Compress bool
Crypt bool
MultiUser bool // enable multi user authentication.
MultiUserMap map[string]string // multi user and pwd
U string
P string
Compress bool
Crypt bool
}

type Client struct {
Expand Down Expand Up @@ -142,6 +140,7 @@ type Tunnel struct {
LocalPath string
StripPre string
Target *Target
MultiUser *MultiUser
Health
sync.RWMutex
}
Expand Down Expand Up @@ -186,6 +185,10 @@ type Target struct {
sync.RWMutex
}

type MultiUser struct {
UserMap map[string]string // multi user and pwd
}

func (s *Target) GetRandomTarget() (string, error) {
if s.TargetArr == nil {
s.TargetArr = strings.Split(s.TargetStr, "\n")
Expand Down
6 changes: 3 additions & 3 deletions server/proxy/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *Sock5ModeServer) handleConn(c net.Conn) {
c.Close()
return
}
if (s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "") || (s.task.Client.Cnf.MultiUser && len(s.task.Client.Cnf.MultiUserMap) > 0) {
if (s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "") || (s.task.MultiUser != nil && len(s.task.MultiUser.UserMap) > 0) {
buf[1] = UserPassAuth
c.Write(buf)
if err := s.Auth(c); err != nil {
Expand Down Expand Up @@ -238,11 +238,11 @@ func (s *Sock5ModeServer) Auth(c net.Conn) error {
}

var U, P string
if s.task.Client.Cnf.MultiUser {
if s.task.MultiUser != nil {
// enable multi user auth
U = string(user)
var ok bool
P, ok = s.task.Client.Cnf.MultiUserMap[U]
P, ok = s.task.MultiUser.UserMap[U]
if !ok {
return errors.New("验证不通过")
}
Expand Down

0 comments on commit a05995f

Please sign in to comment.