Skip to content

Commit

Permalink
fix(platform): validate socks5 proxy (#2212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Ryu authored Dec 15, 2022
1 parent 966b72e commit 5289a85
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pkg/util/ssh/socks5_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ import (
"tkestack.io/tke/pkg/util/log"
)

const defaultCheckTargetAddr = "ccr.ccs.tencentyun.com:443"

type SOCKS5 struct {
Host string
Port int
User string
Password string
DialTimeOut time.Duration
Host string
Port int
User string
Password string
DialTimeOut time.Duration
CheckTargetAddr string
}

func (sk SOCKS5) ProxyConn(targetAddr string) (net.Conn, func(), error) {
Expand Down Expand Up @@ -71,6 +74,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
targetAddr := sk.CheckTargetAddr
if len(targetAddr) == 0 {
targetAddr = defaultCheckTargetAddr
}
_, closer, err := sk.ProxyConn(targetAddr)
if err != nil {
return fmt.Errorf("tunnel is unavailable: %v", err)
}
defer closer()
return nil
}

0 comments on commit 5289a85

Please sign in to comment.