Handle gets the methods from the SOCKS5 client and authenticates with the first supported method
(bufConn io.Reader, conn io.Writer)
| 45 | |
| 46 | // Handle gets the methods from the SOCKS5 client and authenticates with the first supported method |
| 47 | func (h *StandardAuthHandler) Handle(bufConn io.Reader, conn io.Writer) error { |
| 48 | methods, err := readMethods(bufConn) |
| 49 | if err != nil { |
| 50 | return fmt.Errorf("Failed to read auth methods: %v", err) |
| 51 | } |
| 52 | |
| 53 | // first supported method is used |
| 54 | for _, method := range methods { |
| 55 | authenticator := h.authenticators[method] |
| 56 | if authenticator != nil { |
| 57 | return authenticator.Handle(bufConn, conn) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // failed to authenticate. No supported authentication type found |
| 62 | conn.Write([]byte{socks5Version, noAcceptable}) |
| 63 | return fmt.Errorf("unknown authentication type") |
| 64 | } |
| 65 | |
| 66 | // readMethods is used to read the number and type of methods |
| 67 | func readMethods(r io.Reader) ([]byte, error) { |
nothing calls this directly
no test coverage detected