From fa2b9a836cbe90337351b6e9a8223edeb09003b9 Mon Sep 17 00:00:00 2001 From: fatedier Date: Wed, 25 Oct 2017 02:49:56 +0800 Subject: [PATCH] fix xtcp encryption --- client/proxy.go | 19 ++++++++++++------- client/vistor.go | 1 + conf/frpc_full.ini | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/client/proxy.go b/client/proxy.go index c8c155c..c2d7bf6 100644 --- a/client/proxy.go +++ b/client/proxy.go @@ -115,7 +115,8 @@ func (pxy *TcpProxy) Close() { } func (pxy *TcpProxy) InWorkConn(conn frpNet.Conn) { - HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn) + HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn, + []byte(config.ClientCommonCfg.PrivilegeToken)) } // HTTP @@ -143,7 +144,8 @@ func (pxy *HttpProxy) Close() { } func (pxy *HttpProxy) InWorkConn(conn frpNet.Conn) { - HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn) + HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn, + []byte(config.ClientCommonCfg.PrivilegeToken)) } // HTTPS @@ -171,7 +173,8 @@ func (pxy *HttpsProxy) Close() { } func (pxy *HttpsProxy) InWorkConn(conn frpNet.Conn) { - HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn) + HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn, + []byte(config.ClientCommonCfg.PrivilegeToken)) } // STCP @@ -199,7 +202,8 @@ func (pxy *StcpProxy) Close() { } func (pxy *StcpProxy) InWorkConn(conn frpNet.Conn) { - HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn) + HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, conn, + []byte(config.ClientCommonCfg.PrivilegeToken)) } // XTCP @@ -291,7 +295,8 @@ func (pxy *XtcpProxy) InWorkConn(conn frpNet.Conn) { return } - HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, frpNet.WrapConn(kcpConn)) + HandleTcpWorkConnection(&pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, + frpNet.WrapConn(kcpConn), []byte(pxy.cfg.Sk)) } // UDP @@ -401,7 +406,7 @@ func (pxy *UdpProxy) InWorkConn(conn frpNet.Conn) { // Common handler for tcp work connections. func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin.Plugin, - baseInfo *config.BaseProxyConf, workConn frpNet.Conn) { + baseInfo *config.BaseProxyConf, workConn frpNet.Conn, encKey []byte) { var ( remote io.ReadWriteCloser @@ -409,7 +414,7 @@ func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin. ) remote = workConn if baseInfo.UseEncryption { - remote, err = frpIo.WithEncryption(remote, []byte(config.ClientCommonCfg.PrivilegeToken)) + remote, err = frpIo.WithEncryption(remote, encKey) if err != nil { workConn.Error("create encryption stream error: %v", err) return diff --git a/client/vistor.go b/client/vistor.go index 03171a8..a2ac9d4 100644 --- a/client/vistor.go +++ b/client/vistor.go @@ -295,6 +295,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) { } frpIo.Join(userConn, remote) + sv.Debug("join connections closed") } func (sv *XtcpVistor) sendDetectMsg(addr string, port int64, laddr *net.UDPAddr, content []byte) (err error) { diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index e8e0864..44a89df 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -157,3 +157,5 @@ server_name = p2p_tcp sk = abcdefg bind_addr = 127.0.0.1 bind_port = 9001 +use_encryption = false +use_compression = false