go-socks5 icon indicating copy to clipboard operation
go-socks5 copied to clipboard

User/Pass authentication not working, can you give example code?

Open dxjones opened this issue 5 years ago • 4 comments

When trying to use the socks5 proxy (with Chrome on a Mac), it fails with this error message:

[ERR] socks: Failed to authenticate: No supported authentication mechanism

I had set the System Preferences on the Mac to use the SOCKS Proxy, and I provided the user and password. The proxy was clearly being contacted, but the authentication step was failing.

Here is the code that attempts to configure socks5 to use the UserPassAuthenticator.

package main

import socks5 "github.com/armon/go-socks5"

func main() {
	cred := socks5.StaticCredentials{"user": "pass"}
	conf := &socks5.Config{Credentials: cred}
	server, err := socks5.New(conf)
	if err != nil {
		panic(err)
	}
	err = server.ListenAndServe("tcp", "127.0.0.1:8000")
	if err != nil {
		panic(err)
	}
}

Can anyone give a simple example showing how UserPassAuthenticator can be used with Chrome/Safari browsers on a Mac?

dxjones avatar Jan 13 '19 20:01 dxjones

Chrome does not support authentication with socks5.

https://bugs.chromium.org/p/chromium/issues/detail?id=256785

OneOfOne avatar Jan 15 '19 23:01 OneOfOne

on mac os socks proxy

auth.go:122 method == NoAuth == uint8(0)

[ERR] socks: Failed to authenticate: No supported authentication mechanism

514366607 avatar Jun 29 '20 07:06 514366607

by safari

514366607 avatar Jun 29 '20 07:06 514366607

If people are still struggling to get it working then here is the solution

func main() {
	cred := socks5.StaticCredentials{
		"user": "pass",
	}
	conf := &socks5.Config{
		AuthMethods: []socks5.Authenticator{socks5.UserPassAuthenticator{Credentials: cred}},
	}
	server, err := socks5.New(conf)
	if err != nil {
		panic(err)
	}
	err = server.ListenAndServe("tcp", "127.0.0.1:8000")
	if err != nil {
		panic(err)
	}
}

packet-sent avatar Feb 18 '22 13:02 packet-sent