fix xtcp encryption

This commit is contained in:
fatedier 2017-10-25 02:49:56 +08:00
parent 9e0fd0c4ef
commit fa2b9a836c
3 changed files with 15 additions and 7 deletions

View File

@ -115,7 +115,8 @@ func (pxy *TcpProxy) Close() {
} }
func (pxy *TcpProxy) InWorkConn(conn frpNet.Conn) { 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 // HTTP
@ -143,7 +144,8 @@ func (pxy *HttpProxy) Close() {
} }
func (pxy *HttpProxy) InWorkConn(conn frpNet.Conn) { 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 // HTTPS
@ -171,7 +173,8 @@ func (pxy *HttpsProxy) Close() {
} }
func (pxy *HttpsProxy) InWorkConn(conn frpNet.Conn) { 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 // STCP
@ -199,7 +202,8 @@ func (pxy *StcpProxy) Close() {
} }
func (pxy *StcpProxy) InWorkConn(conn frpNet.Conn) { 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 // XTCP
@ -291,7 +295,8 @@ func (pxy *XtcpProxy) InWorkConn(conn frpNet.Conn) {
return 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 // UDP
@ -401,7 +406,7 @@ func (pxy *UdpProxy) InWorkConn(conn frpNet.Conn) {
// Common handler for tcp work connections. // Common handler for tcp work connections.
func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin.Plugin, func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin.Plugin,
baseInfo *config.BaseProxyConf, workConn frpNet.Conn) { baseInfo *config.BaseProxyConf, workConn frpNet.Conn, encKey []byte) {
var ( var (
remote io.ReadWriteCloser remote io.ReadWriteCloser
@ -409,7 +414,7 @@ func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin.
) )
remote = workConn remote = workConn
if baseInfo.UseEncryption { if baseInfo.UseEncryption {
remote, err = frpIo.WithEncryption(remote, []byte(config.ClientCommonCfg.PrivilegeToken)) remote, err = frpIo.WithEncryption(remote, encKey)
if err != nil { if err != nil {
workConn.Error("create encryption stream error: %v", err) workConn.Error("create encryption stream error: %v", err)
return return

View File

@ -295,6 +295,7 @@ func (sv *XtcpVistor) handleConn(userConn frpNet.Conn) {
} }
frpIo.Join(userConn, remote) frpIo.Join(userConn, remote)
sv.Debug("join connections closed")
} }
func (sv *XtcpVistor) sendDetectMsg(addr string, port int64, laddr *net.UDPAddr, content []byte) (err error) { func (sv *XtcpVistor) sendDetectMsg(addr string, port int64, laddr *net.UDPAddr, content []byte) (err error) {

View File

@ -157,3 +157,5 @@ server_name = p2p_tcp
sk = abcdefg sk = abcdefg
bind_addr = 127.0.0.1 bind_addr = 127.0.0.1
bind_port = 9001 bind_port = 9001
use_encryption = false
use_compression = false