|
@@ -16,6 +16,7 @@ import (
|
|
|
var (
|
|
var (
|
|
|
ErrorAuthenticationFailed = errors.New("None of the authentication methods is allowed.")
|
|
ErrorAuthenticationFailed = errors.New("None of the authentication methods is allowed.")
|
|
|
ErrorCommandNotSupported = errors.New("Client requested an unsupported command.")
|
|
ErrorCommandNotSupported = errors.New("Client requested an unsupported command.")
|
|
|
|
|
+ ErrorInvalidUser = errors.New("Invalid username or password.")
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// SocksServer is a SOCKS 5 proxy server
|
|
// SocksServer is a SOCKS 5 proxy server
|
|
@@ -84,8 +85,25 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error {
|
|
|
return ErrorAuthenticationFailed
|
|
return ErrorAuthenticationFailed
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- authResponse := socksio.NewAuthenticationResponse(socksio.AuthNotRequired)
|
|
|
|
|
|
|
+ authResponse := socksio.NewAuthenticationResponse(expectedAuthMethod)
|
|
|
socksio.WriteAuthentication(connection, authResponse)
|
|
socksio.WriteAuthentication(connection, authResponse)
|
|
|
|
|
+
|
|
|
|
|
+ if server.config.AuthMethod == JsonAuthMethodUserPass {
|
|
|
|
|
+ upRequest, err := socksio.ReadUserPassRequest(reader)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Error("Failed to read username and password: %v", err)
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ status := byte(0)
|
|
|
|
|
+ if ! upRequest.IsValid(server.config.Username, server.config.Password) {
|
|
|
|
|
+ status = byte(0xFF)
|
|
|
|
|
+ }
|
|
|
|
|
+ upResponse := socksio.NewSocks5UserPassResponse(status)
|
|
|
|
|
+ socksio.WriteUserPassResponse(connection, upResponse)
|
|
|
|
|
+ if status != byte(0) {
|
|
|
|
|
+ return ErrorInvalidUser
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
request, err := socksio.ReadRequest(reader)
|
|
request, err := socksio.ReadRequest(reader)
|
|
|
if err != nil {
|
|
if err != nil {
|