proxy

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package proxy contains all proxies used by Xray.

To implement an inbound or outbound proxy, one needs to do the following: 1. Implement the interface(s) below. 2. Register a config creator through common.RegisterConfig.

Index

Constants

View Source
const (
	TlsHandshakeTypeClientHello byte = 0x01
	TlsHandshakeTypeServerHello byte = 0x02

	CommandPaddingContinue byte = 0x00
	CommandPaddingEnd      byte = 0x01
	CommandPaddingDirect   byte = 0x02
)

Variables

View Source
var (
	Tls13SupportedVersions   = []byte{0x00, 0x2b, 0x00, 0x02, 0x03, 0x04}
	TlsClientHandShakeStart  = []byte{0x16, 0x03}
	TlsServerHandShakeStart  = []byte{0x16, 0x03, 0x03}
	TlsApplicationDataStart  = []byte{0x17, 0x03, 0x03}
	TlsChangeCipherSpecStart = []byte{0x14, 0x03, 0x03}

	Tls13CipherSuiteDic = map[uint16]string{
		0x1301: "TLS_AES_128_GCM_SHA256",
		0x1302: "TLS_AES_256_GCM_SHA384",
		0x1303: "TLS_CHACHA20_POLY1305_SHA256",
		0x1304: "TLS_AES_128_CCM_SHA256",
		0x1305: "TLS_AES_128_CCM_8_SHA256",
	}
)

Functions

func CopyRawConnIfExist

func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net.Conn, writer buf.Writer, timer *signal.ActivityTimer, inTimer *signal.ActivityTimer) error

CopyRawConnIfExist use the most efficient copy method. - If caller don't want to turn on splice, do not pass in both reader conn and writer conn - writer are from *transport.Link

func ReshapeMultiBuffer

func ReshapeMultiBuffer(ctx context.Context, buffer buf.MultiBuffer) buf.MultiBuffer

ReshapeMultiBuffer prepare multi buffer for padding structure (max 21 bytes)

func UnwrapRawConn

func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter)

UnwrapRawConn support unwrap stats, tls, utls, reality and proxyproto conn and get raw tcp conn from it

func XtlsFilterTls

func XtlsFilterTls(buffer buf.MultiBuffer, trafficState *TrafficState, ctx context.Context)

XtlsFilterTls filter and recognize tls 1.3 and other info

func XtlsPadding

func XtlsPadding(b *buf.Buffer, command byte, userUUID *[]byte, longPadding bool, ctx context.Context) *buf.Buffer

XtlsPadding add padding to eliminate length signature during tls handshake

func XtlsUnpadding

func XtlsUnpadding(b *buf.Buffer, s *TrafficState, ctx context.Context) *buf.Buffer

XtlsUnpadding remove padding and parse command

Types

type GetInbound

type GetInbound interface {
	GetInbound() Inbound
}

type GetOutbound

type GetOutbound interface {
	GetOutbound() Outbound
}

type Inbound

type Inbound interface {
	// Network returns a list of networks that this inbound supports. Connections with not-supported networks will not be passed into Process().
	Network() []net.Network

	// Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound.
	Process(context.Context, net.Network, stat.Connection, routing.Dispatcher) error
}

An Inbound processes inbound connections.

type Outbound

type Outbound interface {
	// Process processes the given connection. The given dialer may be used to dial a system outbound connection.
	Process(context.Context, *transport.Link, internet.Dialer) error
}

An Outbound process outbound connections.

type TrafficState

type TrafficState struct {
	UserUUID               []byte
	NumberOfPacketToFilter int
	EnableXtls             bool
	IsTLS12orAbove         bool
	IsTLS                  bool
	Cipher                 uint16
	RemainingServerHello   int32

	// reader link state
	WithinPaddingBuffers     bool
	ReaderSwitchToDirectCopy bool
	RemainingCommand         int32
	RemainingContent         int32
	RemainingPadding         int32
	CurrentCommand           int

	// write link state
	IsPadding                bool
	WriterSwitchToDirectCopy bool

	// temporary cache the buffers
	CacheBuffer []buf.MultiBuffer
}

TrafficState is used to track uplink and downlink of one connection It is used by XTLS to determine if switch to raw copy mode, It is used by Vision to calculate padding

func NewTrafficState

func NewTrafficState(userUUID []byte) *TrafficState

type UserManager

type UserManager interface {
	// AddUser adds a new user.
	AddUser(context.Context, *protocol.MemoryUser) error

	// RemoveUser removes a user by email.
	RemoveUser(context.Context, string) error
}

UserManager is the interface for Inbounds and Outbounds that can manage their users.

type VisionReader

type VisionReader struct {
	buf.Reader
	// contains filtered or unexported fields
}

VisionReader is used to read xtls vision protocol Note Vision probably only make sense as the inner most layer of reader, since it need assess traffic state from origin proxy traffic

func NewVisionReader

func NewVisionReader(reader buf.Reader, state *TrafficState, context context.Context) *VisionReader

func (*VisionReader) ReadMultiBuffer

func (w *VisionReader) ReadMultiBuffer() (buf.MultiBuffer, error)

type VisionWriter

type VisionWriter struct {
	buf.Writer
	// contains filtered or unexported fields
}

VisionWriter is used to write xtls vision protocol Note Vision probably only make sense as the inner most layer of writer, since it need assess traffic state from origin proxy traffic

func NewVisionWriter

func NewVisionWriter(writer buf.Writer, state *TrafficState, context context.Context) *VisionWriter

func (*VisionWriter) WriteMultiBuffer

func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error

Directories

Path Synopsis
Package blackhole is an outbound handler that blocks all connections.
Package blackhole is an outbound handler that blocks all connections.
Package shadowsocks provides compatible functionality to Shadowsocks.
Package shadowsocks provides compatible functionality to Shadowsocks.
Package socks provides implements of Socks protocol 4, 4a and 5.
Package socks provides implements of Socks protocol 4, 4a and 5.
Package vless contains the implementation of VLess protocol and transportation.
Package vless contains the implementation of VLess protocol and transportation.
Package vmess contains the implementation of VMess protocol and transportation.
Package vmess contains the implementation of VMess protocol and transportation.

Jump to

Keyboard shortcuts

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