all: now messages between frps and frpc can be encryped when use_encryption set true

This commit is contained in:
fatedier
2016-03-31 18:48:18 +08:00
parent 52f99bbc00
commit 80fc76da52
11 changed files with 73 additions and 44 deletions

View File

@@ -24,10 +24,11 @@ import (
)
type ProxyClient struct {
Name string
Passwd string
LocalIp string
LocalPort int64
Name string
Passwd string
LocalIp string
LocalPort int64
UseEncryption bool
}
func (p *ProxyClient) GetLocalConn() (c *conn.Conn, err error) {
@@ -81,8 +82,11 @@ func (p *ProxyClient) StartTunnel(serverAddr string, serverPort int64) (err erro
// l means local, r means remote
log.Debug("Join two connections, (l[%s] r[%s]) (l[%s] r[%s])", localConn.GetLocalAddr(), localConn.GetRemoteAddr(),
remoteConn.GetLocalAddr(), remoteConn.GetRemoteAddr())
// go conn.Join(localConn, remoteConn)
go conn.JoinMore(localConn, remoteConn, p.Passwd)
if p.UseEncryption {
go conn.JoinMore(localConn, remoteConn, p.Passwd)
} else {
go conn.Join(localConn, remoteConn)
}
return nil
}

View File

@@ -73,19 +73,23 @@ func LoadConf(confFile string) (err error) {
for name, section := range conf {
if name != "common" {
proxyClient := &ProxyClient{}
// name
proxyClient.Name = name
// passwd
proxyClient.Passwd, ok = section["passwd"]
if !ok {
return fmt.Errorf("Parse ini file error: proxy [%s] no passwd found", proxyClient.Name)
}
// local_ip
proxyClient.LocalIp, ok = section["local_ip"]
if !ok {
// use 127.0.0.1 as default
proxyClient.LocalIp = "127.0.0.1"
}
// local_port
portStr, ok := section["local_port"]
if ok {
proxyClient.LocalPort, err = strconv.ParseInt(portStr, 10, 64)
@@ -96,6 +100,13 @@ func LoadConf(confFile string) (err error) {
return fmt.Errorf("Parse ini file error: proxy [%s] local_port not found", proxyClient.Name)
}
// use_encryption
proxyClient.UseEncryption = false
useEncryptionStr, ok := section["use_encryption"]
if ok && useEncryptionStr == "true" {
proxyClient.UseEncryption = true
}
ProxyClients[proxyClient.Name] = proxyClient
}
}

View File

@@ -21,9 +21,10 @@ type GeneralRes struct {
// messages between control connection of frpc and frps
type ControlReq struct {
Type int64 `json:"type"`
ProxyName string `json:"proxy_name,omitempty"`
Passwd string `json:"passwd, omitempty"`
Type int64 `json:"type"`
ProxyName string `json:"proxy_name,omitempty"`
Passwd string `json:"passwd, omitempty"`
UseEncryption bool `json:"use_encryption, omitempty"`
}
type ControlRes struct {

View File

@@ -25,11 +25,12 @@ import (
)
type ProxyServer struct {
Name string
Passwd string
BindAddr string
ListenPort int64
Status int64
Name string
Passwd string
UseEncryption bool
BindAddr string
ListenPort int64
Status int64
listener *conn.Listener // accept new connection from remote users
ctlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
@@ -132,8 +133,12 @@ func (p *ProxyServer) Start() (err error) {
// l means local, r means remote
log.Debug("Join two connections, (l[%s] r[%s]) (l[%s] r[%s])", workConn.GetLocalAddr(), workConn.GetRemoteAddr(),
userConn.GetLocalAddr(), userConn.GetRemoteAddr())
// go conn.Join(workConn, userConn)
go conn.JoinMore(userConn, workConn, p.Passwd)
if p.UseEncryption {
go conn.JoinMore(userConn, workConn, p.Passwd)
} else {
go conn.Join(userConn, workConn)
}
}
}()