Skip to content

Commit

Permalink
Add some more comments around how we identify the proxy protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed May 1, 2024
1 parent aa50580 commit d628bb1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions service/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,27 @@ func (h *tcpHandler) Handle(ctx context.Context, clientConn transport.StreamConn
}

func getProxyRequest(bufConn onet.BufConn) (string, error) {
// We try to identify the used proxy protocols based on the first byte received.
firstByte, err := bufConn.Peek(1)
if err != nil {
return "", fmt.Errorf("reading header failed: %w", err)
}

switch firstByte[0] {

// Shadowsocks address types follow the SOCKS5 address format:
// See https://shadowsocks.org/doc/what-is-shadowsocks.html#addressing.
// Shadowsocks: The first character represents the address type. Note that Shadowsocks address types
// follow the SOCKS5 address format. See https://shadowsocks.org/doc/what-is-shadowsocks.html#addressing.
case socks.AtypIPv4, socks.AtypDomainName, socks.AtypIPv6:
logger.Debug("Proxy protocol detected: Shadowsocks")
return proxy.ParseShadowsocks(bufConn)

// SOCKS5: The first character represents the protocol version (05). See
// https://datatracker.ietf.org/doc/html/rfc1928#autoid-4.
case 0x05:
logger.Debug("Proxy protocol detected: SOCKS5")
return proxy.ParseSocks(bufConn)

// HTTP CONNECT: The first character of the "CONNECT" method ("C").
case 0x43:
logger.Debug("Proxy protocol detected: HTTP CONNECT")
return proxy.ParseHTTP(bufConn)
Expand Down

0 comments on commit d628bb1

Please sign in to comment.