Skip to content

Commit

Permalink
fix(platform): validate socks5 proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
leonarliu committed Dec 15, 2022
1 parent 966b72e commit f47613b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/util/ssh/socks5_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func (sk SOCKS5) ProxyConn(targetAddr string) (net.Conn, func(), error) {
}

func (sk SOCKS5) CheckTunnel() error {
_, err := proxy.SOCKS5("tcp", net.JoinHostPort(sk.Host, fmt.Sprintf("%d", sk.Port)), nil, proxy.Direct)
return err
tunnelAddr := net.JoinHostPort(sk.Host, fmt.Sprintf("%d", sk.Port))
dialer, err := proxy.SOCKS5("tcp", tunnelAddr, nil, nil)
if err != nil {
return fmt.Errorf("get proxy dialler failed, tunnel is unavailable: %v", err)
}
_, err = dialer.Dial("tcp", "ccr.ccs.tencentyun.com:443")
if err != nil {
return fmt.Errorf("dial tunnel failed, tunnel is unavailable: %v", err)
}
return nil
}

0 comments on commit f47613b

Please sign in to comment.