Documentation
¶
Overview ¶
Package proxy provides support for a variety of protocols to proxy network data.
Package socks provides a SOCKS version 5 client implementation.
SOCKS protocol version 5 is defined in RFC 1928. Username/Password authentication for SOCKS version 5 is defined in RFC 1929.
Package sockstest provides utilities for SOCKS testing.
Index ¶
- Constants
- Variables
- func Dial(ctx context.Context, network, address string) (net.Conn, error)
- func MarshalAuthReply(ver int, m AuthMethod) ([]byte, error)
- func MarshalCmdReply(ver int, reply Reply, a *Addr) ([]byte, error)
- func NoAuthRequired(rw io.ReadWriter, b []byte) error
- func NoProxyRequired(rw io.ReadWriter, b []byte) error
- func RegisterDialerType(scheme string, f func(*url.URL, Dialer) (Dialer, error))
- type Addr
- type Auth
- type AuthMethod
- type AuthRequest
- type CmdRequest
- type Command
- type Conn
- type ContextDialer
- type Dialer
- type PerHost
- func (p *PerHost) AddFromString(s string)
- func (p *PerHost) AddHost(host string)
- func (p *PerHost) AddIP(ip net.IP)
- func (p *PerHost) AddNetwork(net *net.IPNet)
- func (p *PerHost) AddZone(zone string)
- func (p *PerHost) Dial(network, addr string) (c net.Conn, err error)
- func (p *PerHost) DialContext(ctx context.Context, network, addr string) (c net.Conn, err error)
- type Reply
- type Server
- type SocksDialer
- type UsernamePassword
Constants ¶
const ( Version5 = 0x05 AddrTypeIPv4 = 0x01 AddrTypeFQDN = 0x03 AddrTypeIPv6 = 0x04 CmdConnect Command = 0x01 // establishes an active-open forward proxy connection AuthMethodNotRequired AuthMethod = 0x00 // no authentication required AuthMethodUsernamePassword AuthMethod = 0x02 // use username/password AuthMethodNoAcceptableMethods AuthMethod = 0xff // no acceptable authentication methods StatusSucceeded Reply = 0x00 )
Wire protocol constants.
Variables ¶
var Direct = direct{}
Direct implements Dialer by making network connections directly using net.Dial or net.DialContext.
Functions ¶
func Dial ¶
Dial works like DialContext on net.Dialer but using a dialer returned by FromEnvironment.
The passed ctx is only used for returning the Conn, not the lifetime of the Conn.
Custom dialers (registered via RegisterDialerType) that do not implement ContextDialer can leak a goroutine for as long as it takes the underlying Dialer implementation to timeout.
A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.
func MarshalAuthReply ¶
func MarshalAuthReply(ver int, m AuthMethod) ([]byte, error)
MarshalAuthReply returns an authentication reply in wire format.
func MarshalCmdReply ¶
MarshalCmdReply returns a command reply in wire format.
func NoAuthRequired ¶
func NoAuthRequired(rw io.ReadWriter, b []byte) error
NoAuthRequired handles a no-authentication-required signaling.
func NoProxyRequired ¶
func NoProxyRequired(rw io.ReadWriter, b []byte) error
NoProxyRequired handles a command signaling without constructing a proxy connection to the final destination.
Types ¶
type Auth ¶
type Auth struct {
User, Password string
}
Auth contains authentication parameters that specific Dialers may require.
type AuthRequest ¶
type AuthRequest struct {
Version int
Methods []AuthMethod
}
An AuthRequest represents an authentication request.
func ParseAuthRequest ¶
func ParseAuthRequest(b []byte) (*AuthRequest, error)
ParseAuthRequest parses an authentication request.
type CmdRequest ¶
A CmdRequest represents a command request.
func ParseCmdRequest ¶
func ParseCmdRequest(b []byte) (*CmdRequest, error)
ParseCmdRequest parses a command request.
type ContextDialer ¶
type ContextDialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
A ContextDialer dials using a context.
type Dialer ¶
type Dialer interface {
// Dial connects to the given address via the proxy.
Dial(network, addr string) (c net.Conn, err error)
}
A Dialer is a means to establish a connection. Custom dialers should also implement ContextDialer.
func FromEnvironment ¶
func FromEnvironment() Dialer
FromEnvironment returns the dialer specified by the proxy-related variables in the environment and makes underlying connections directly.
func FromEnvironmentUsing ¶
FromEnvironmentUsing returns the dialer specify by the proxy-related variables in the environment and makes underlying connections using the provided forwarding Dialer (for instance, a *net.Dialer with desired configuration).
type PerHost ¶
type PerHost struct {
// contains filtered or unexported fields
}
A PerHost directs connections to a default Dialer unless the host name requested matches one of a number of exceptions.
func NewPerHost ¶
NewPerHost returns a PerHost Dialer that directs connections to either defaultDialer or bypass, depending on whether the connection matches one of the configured rules.
func (*PerHost) AddFromString ¶
AddFromString parses a string that contains comma-separated values specifying hosts that should use the bypass proxy. Each value is either an IP address, a CIDR range, a zone (*.example.com) or a host name (localhost). A best effort is made to parse the string and errors are ignored.
func (*PerHost) AddIP ¶
AddIP specifies an IP address that will use the bypass proxy. Note that this will only take effect if a literal IP address is dialed. A connection to a named host will never match an IP.
func (*PerHost) AddNetwork ¶
AddNetwork specifies an IP range that will use the bypass proxy. Note that this will only take effect if a literal IP address is dialed. A connection to a named host will never match.
func (*PerHost) AddZone ¶
AddZone specifies a DNS suffix that will use the bypass proxy. A zone of "example.com" matches "example.com" and all of its subdomains.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server represents a server for handshake testing.
func NewServer ¶
NewServer returns a new server.
The provided authFunc and cmdFunc must parse requests and return appropriate replies to clients.
func (*Server) TargetAddr ¶
TargetAddr returns a fake final destination address.
The returned address is only valid for testing with Server.
type SocksDialer ¶
type SocksDialer struct {
ProxyNetwork string // network between a proxy server and a client
ProxyAddress string // proxy server address
// ProxyDial specifies the optional dial function for
// establishing the transport connection.
ProxyDial func(context.Context, string, string) (net.Conn, error)
// AuthMethods specifies the list of request authentication
// methods.
// If empty, SOCKS client requests only AuthMethodNotRequired.
AuthMethods []AuthMethod
// Authenticate specifies the optional authentication
// function. It must be non-nil when AuthMethods is not empty.
// It must return an error when the authentication is failed.
Authenticate func(context.Context, io.ReadWriter, AuthMethod) error
// contains filtered or unexported fields
}
A SocksDialer holds SOCKS-specific options.
func FromURL ¶
func FromURL(u *url.URL, forward Dialer) (*SocksDialer, error)
FromURL returns a Dialer given a URL specification and an underlying Dialer for it to make network requests.
func NewSocksDialer ¶
func NewSocksDialer(network, address string) *SocksDialer
NewSocksDialer returns a new Dialer that dials through the provided proxy server's network and address.
func SOCKS5 ¶
func SOCKS5(network, address string, auth *Auth, forward Dialer) (*SocksDialer, error)
SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given address with an optional username and password. See RFC 1928 and RFC 1929.
func (*SocksDialer) Dial
deprecated
func (d *SocksDialer) Dial(network, address string) (net.Conn, error)
Dial connects to the provided address on the provided network.
Unlike DialContext, it returns a raw transport connection instead of a forward proxy connection.
Deprecated: Use DialContext or DialWithConn instead.
func (*SocksDialer) DialContext ¶
DialContext connects to the provided address on the provided network.
The returned error value may be a net.OpError. When the Op field of net.OpError contains "socks", the Source field contains a proxy server address and the Addr field contains a command target address.
See func Dial of the net package of standard library for a description of the network and address parameters.
func (*SocksDialer) DialWithConn ¶
func (d *SocksDialer) DialWithConn(ctx context.Context, c net.Conn, network, address string) (net.Addr, error)
DialWithConn initiates a connection from SOCKS server to the target network and address using the connection c that is already connected to the SOCKS server.
It returns the connection's local address assigned by the SOCKS server.
type UsernamePassword ¶
UsernamePassword are the credentials for the username/password authentication method.
func (*UsernamePassword) Authenticate ¶
func (up *UsernamePassword) Authenticate(ctx context.Context, rw io.ReadWriter, auth AuthMethod) error
Authenticate authenticates a pair of username and password with the proxy server.