socks5

package
v0.0.0-...-6a9102d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2022 License: MIT, MIT Imports: 13 Imported by: 0

README

socks5

Package socks5 implements a "SOCKS Protocol Version 5" server.

This server supports a subset of RFC 1928:

  • auth methods: "NO AUTHENTICATION REQUIRED", "USERNAME/PASSWORD"
  • commands: "CONNECT"
  • address types: "IP V4 address", "DOMAINNAME", "IP V6 address" (but tested "DOMAINNAME" only)

INSTALL

go get -u github.com/oov/socks5

USAGE

package main

import (
	"github.com/oov/socks5"
	"log"
)

func main() {
	srv := socks5.New()
	srv.AuthUsernamePasswordCallback = func(c *socks5.Conn, username, password []byte) error {
		user := string(username)
		if user != "guest" {
			return socks5.ErrAuthenticationFailed
		}

		log.Printf("Welcome %v!", user)
		c.Data = user
		return nil
	}
	srv.HandleConnectFunc(func(c *socks5.Conn, host string) (newHost string, err error) {
		if host == "example.com:80" {
			return host, socks5.ErrConnectionNotAllowedByRuleset
		}
		if user, ok := c.Data.(string); ok {
			log.Printf("%v connecting to %v", user, host)
		}
		return host, nil
	})
	srv.HandleCloseFunc(func(c *socks5.Conn) {
		if user, ok := c.Data.(string); ok {
			log.Printf("Goodbye %v!", user)
		}
	})

	srv.ListenAndServe(":12345")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthenticationFailed          = errors.New("authentication failed")
	ErrConnectionNotAllowedByRuleset = errors.New("connection not allowed by ruleset")
	ErrAddressTypeNotSupported       = errors.New("address type not supported")
)

Functions

This section is empty.

Types

type CloseHandler

type CloseHandler interface {
	HandleClose(c *Conn)
}

type Conn

type Conn struct {
	Data interface{}
	// contains filtered or unexported fields
}

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() string

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() string

type ConnectHandler

type ConnectHandler interface {
	HandleConnect(c *Conn, host string) (newHost string, err error)
}

type FuncCloseHandler

type FuncCloseHandler func(c *Conn)

func (FuncCloseHandler) HandleClose

func (f FuncCloseHandler) HandleClose(c *Conn)

type FuncConnectHandler

type FuncConnectHandler func(c *Conn, host string) (newHost string, err error)

func (FuncConnectHandler) HandleConnect

func (f FuncConnectHandler) HandleConnect(c *Conn, host string) (newHost string, err error)

type Server

type Server struct {
	Logger                               *log.Logger
	AuthNoAuthenticationRequiredCallback func(conn *Conn) error
	AuthUsernamePasswordCallback         func(conn *Conn, username, password []byte) error
	// contains filtered or unexported fields
}

func New

func New() *Server

func (*Server) HandleClose

func (srv *Server) HandleClose(h CloseHandler)

func (*Server) HandleCloseFunc

func (srv *Server) HandleCloseFunc(h func(c *Conn))

func (*Server) HandleConnect

func (srv *Server) HandleConnect(h ConnectHandler)

func (*Server) HandleConnectFunc

func (srv *Server) HandleConnectFunc(h func(c *Conn, host string) (newHost string, err error))

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(addr string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL