things-go / go-socks5

socks5 server in pure Golang with much custom optional. Full TCP/UDP and IPv4/IPv6 support.
MIT License
393 stars 68 forks source link

feat: ordered authentication methods #3

Closed PeerXu closed 3 years ago

PeerXu commented 3 years ago

Thanks to share the great SOCKS5 library for golang, help me to implement a custom SOCKS5 server easily.

Problem:

In my situation, I need to try user-password method at first, if not required on client, try no-auth method later.

Solving:

I merge Server.authMethods and Server.authCustomMethods to Server.authMethods.

Then Server check client request methods orderly, with WithAuthMethods().

thinkgos commented 3 years ago

this is armon go-sock5 lib,not my this is the client request method then server try to match your request method,

func (sf *Server) authenticate(conn io.Writer, bufConn io.Reader,userAddr string, methods []byte) (*AuthContext, error) {
    // Select a usable method
    for _, auth := range sf.authMethods {
        for _, method := range methods {
            if auth.GetCode() == method {
                return auth.Authenticate(bufConn, conn, userAddr)
            }
        }
    }

the code just match the method you client request, not for ordered match.

thinkgos commented 3 years ago

@PeerXu see the code again, may a good feature. mathed ordered method