2017-01-08 16:32:41 -05:00
|
|
|
package scenarios
|
|
|
|
|
|
|
|
import (
|
2018-02-20 18:18:53 -05:00
|
|
|
"context"
|
2017-05-17 18:39:30 -04:00
|
|
|
"io/ioutil"
|
2017-04-24 19:40:34 -04:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2017-01-08 16:32:41 -05:00
|
|
|
"testing"
|
2017-01-27 08:10:36 -05:00
|
|
|
"time"
|
2017-01-08 16:32:41 -05:00
|
|
|
|
2017-01-26 17:05:24 -05:00
|
|
|
xproxy "golang.org/x/net/proxy"
|
2017-01-08 16:32:41 -05:00
|
|
|
"v2ray.com/core"
|
2018-02-20 18:18:53 -05:00
|
|
|
"v2ray.com/core/app/dispatcher"
|
2017-04-24 19:40:34 -04:00
|
|
|
"v2ray.com/core/app/log"
|
2017-01-26 14:46:44 -05:00
|
|
|
"v2ray.com/core/app/proxyman"
|
2018-02-20 18:18:53 -05:00
|
|
|
_ "v2ray.com/core/app/proxyman/inbound"
|
|
|
|
_ "v2ray.com/core/app/proxyman/outbound"
|
2017-01-10 18:09:33 -05:00
|
|
|
"v2ray.com/core/app/router"
|
2017-12-19 16:29:56 -05:00
|
|
|
clog "v2ray.com/core/common/log"
|
2017-08-29 06:56:57 -04:00
|
|
|
"v2ray.com/core/common/net"
|
2017-01-10 08:25:31 -05:00
|
|
|
"v2ray.com/core/common/protocol"
|
2017-01-08 16:32:41 -05:00
|
|
|
"v2ray.com/core/common/serial"
|
2017-01-10 08:25:31 -05:00
|
|
|
"v2ray.com/core/common/uuid"
|
|
|
|
"v2ray.com/core/proxy/blackhole"
|
2017-01-08 16:32:41 -05:00
|
|
|
"v2ray.com/core/proxy/dokodemo"
|
|
|
|
"v2ray.com/core/proxy/freedom"
|
2017-04-24 19:40:34 -04:00
|
|
|
v2http "v2ray.com/core/proxy/http"
|
2017-01-26 17:05:24 -05:00
|
|
|
"v2ray.com/core/proxy/socks"
|
2017-01-10 08:25:31 -05:00
|
|
|
"v2ray.com/core/proxy/vmess"
|
|
|
|
"v2ray.com/core/proxy/vmess/inbound"
|
|
|
|
"v2ray.com/core/proxy/vmess/outbound"
|
2017-01-08 16:32:41 -05:00
|
|
|
"v2ray.com/core/testing/servers/tcp"
|
2017-01-27 08:10:36 -05:00
|
|
|
"v2ray.com/core/testing/servers/udp"
|
2017-01-10 08:25:31 -05:00
|
|
|
"v2ray.com/core/transport/internet"
|
2017-10-26 15:44:22 -04:00
|
|
|
. "v2ray.com/ext/assert"
|
2017-01-08 16:32:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPassiveConnection(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-01-08 16:32:41 -05:00
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
SendFirst: []byte("send first"),
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-08 16:32:41 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2017-01-08 16:32:41 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-08 16:32:41 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
2017-01-08 16:32:41 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-01-08 16:32:41 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-08 16:32:41 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2017-01-08 16:32:41 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-08 16:32:41 -05:00
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
|
|
|
Port: int(serverPort),
|
|
|
|
})
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-08 16:32:41 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err := conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(string(response[:nBytes]), Equals, "send first")
|
2017-01-08 16:32:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
payload := "dokodemo request."
|
|
|
|
{
|
|
|
|
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-08 16:32:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err := conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
2017-01-08 16:32:41 -05:00
|
|
|
}
|
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-08 16:32:41 -05:00
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-01-08 16:32:41 -05:00
|
|
|
}
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
func TestProxy(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
serverUserID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2017-01-10 08:25:31 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
2017-01-10 08:25:31 -05:00
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: serverUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
proxyUserID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
proxyPort := tcp.PickPort()
|
2017-01-10 08:25:31 -05:00
|
|
|
proxyConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(proxyPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
2017-01-10 08:25:31 -05:00
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: proxyUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2017-01-10 08:25:31 -05:00
|
|
|
clientConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
2017-01-10 08:25:31 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
2017-01-10 08:25:31 -05:00
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-10 08:25:31 -05:00
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: serverUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2017-01-26 14:46:44 -05:00
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
ProxySettings: &internet.ProxyConfig{
|
|
|
|
Tag: "proxy",
|
|
|
|
},
|
|
|
|
}),
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
|
|
|
Tag: "proxy",
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
2017-01-12 06:59:57 -05:00
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-12 06:59:57 -05:00
|
|
|
Port: uint32(proxyPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: proxyUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig, proxyConfig, clientConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-12 06:59:57 -05:00
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
|
|
|
Port: int(clientPort),
|
|
|
|
})
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-12 06:59:57 -05:00
|
|
|
|
|
|
|
payload := "dokodemo request."
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-12 06:59:57 -05:00
|
|
|
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err = conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-12 06:59:57 -05:00
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-01-12 06:59:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxyOverKCP(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-01-12 06:59:57 -05:00
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-12 06:59:57 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
serverUserID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2017-01-12 06:59:57 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_MKCP,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
2017-01-12 06:59:57 -05:00
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: serverUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2017-01-12 06:59:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
proxyUserID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
proxyPort := tcp.PickPort()
|
2017-01-12 06:59:57 -05:00
|
|
|
proxyConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(proxyPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
2017-01-12 06:59:57 -05:00
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: proxyUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_MKCP,
|
|
|
|
},
|
|
|
|
}),
|
2017-01-12 06:59:57 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2017-01-12 06:59:57 -05:00
|
|
|
clientConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
2017-01-12 06:59:57 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-01-12 06:59:57 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-12 06:59:57 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
2017-01-12 06:59:57 -05:00
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-12 06:59:57 -05:00
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: serverUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2017-01-26 14:46:44 -05:00
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
ProxySettings: &internet.ProxyConfig{
|
|
|
|
Tag: "proxy",
|
|
|
|
},
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_MKCP,
|
|
|
|
},
|
|
|
|
}),
|
2017-01-12 06:59:57 -05:00
|
|
|
},
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
|
|
|
Tag: "proxy",
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
2017-01-10 08:25:31 -05:00
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-10 08:25:31 -05:00
|
|
|
Port: uint32(proxyPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: proxyUserID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig, proxyConfig, clientConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
|
|
|
Port: int(clientPort),
|
|
|
|
})
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
payload := "dokodemo request."
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err = conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-01-10 08:25:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlackhole(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
2017-01-10 18:09:33 -05:00
|
|
|
tcpServer2 := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest2, err := tcpServer2.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 18:09:33 -05:00
|
|
|
defer tcpServer2.Close()
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverPort2 := tcp.PickPort()
|
2017-01-10 08:25:31 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
2017-01-10 08:25:31 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
2017-01-10 18:09:33 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(serverPort2),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest2.Address),
|
2017-01-10 18:09:33 -05:00
|
|
|
Port: uint32(dest2.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-01-10 18:09:33 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-10 08:25:31 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
Tag: "direct",
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2017-01-10 18:09:33 -05:00
|
|
|
},
|
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
Tag: "blocked",
|
|
|
|
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
2017-01-10 08:25:31 -05:00
|
|
|
},
|
|
|
|
},
|
2017-01-10 18:09:33 -05:00
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&router.Config{
|
|
|
|
Rule: []*router.RoutingRule{
|
|
|
|
{
|
2018-11-07 19:01:53 -05:00
|
|
|
TargetTag: &router.RoutingRule_Tag{
|
|
|
|
Tag: "blocked",
|
|
|
|
},
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(dest2.Port),
|
2017-01-10 18:09:33 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
2017-01-10 08:25:31 -05:00
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
2017-01-10 18:09:33 -05:00
|
|
|
Port: int(serverPort2),
|
2017-01-10 08:25:31 -05:00
|
|
|
})
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
|
|
|
payload := "dokodemo request."
|
|
|
|
{
|
|
|
|
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-10 08:25:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
_, err := conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNotNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
}
|
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-10 08:25:31 -05:00
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-01-10 08:25:31 -05:00
|
|
|
}
|
2017-01-26 17:05:24 -05:00
|
|
|
|
|
|
|
func TestForward(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-01-26 17:05:24 -05:00
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-26 17:05:24 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2017-01-26 17:05:24 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-26 17:05:24 -05:00
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 17:05:24 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
|
|
|
AuthType: socks.AuthType_NO_AUTH,
|
|
|
|
Accounts: map[string]string{
|
|
|
|
"Test Account": "Test Password",
|
|
|
|
},
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 17:05:24 -05:00
|
|
|
UdpEnabled: false,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-26 17:05:24 -05:00
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
|
|
|
DestinationOverride: &freedom.DestinationOverride{
|
|
|
|
Server: &protocol.ServerEndpoint{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-26 17:05:24 -05:00
|
|
|
Port: uint32(dest.Port),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-26 17:05:24 -05:00
|
|
|
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-26 17:05:24 -05:00
|
|
|
conn, err := noAuthDialer.Dial("tcp", "google.com:80")
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-26 17:05:24 -05:00
|
|
|
|
|
|
|
payload := "test payload"
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-26 17:05:24 -05:00
|
|
|
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err = conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-26 17:05:24 -05:00
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-01-26 17:05:24 -05:00
|
|
|
}
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
func TestUDPConnection(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
udpServer := udp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := udpServer.Start()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-27 08:10:36 -05:00
|
|
|
defer udpServer.Close()
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2017-01-27 08:10:36 -05:00
|
|
|
clientConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-27 08:10:36 -05:00
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-27 08:10:36 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
2017-01-27 08:10:36 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_UDP},
|
2017-01-27 08:10:36 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-27 08:10:36 -05:00
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(clientConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
|
|
|
Port: int(clientPort),
|
|
|
|
})
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
payload := "dokodemo request."
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err = conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
2017-01-27 08:10:36 -05:00
|
|
|
}
|
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-27 08:10:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(20 * time.Second)
|
|
|
|
|
|
|
|
{
|
|
|
|
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
|
|
|
Port: int(clientPort),
|
|
|
|
})
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
payload := "dokodemo request."
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
2017-01-27 08:10:36 -05:00
|
|
|
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err = conn.Read(response)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
|
|
|
assert(conn.Close(), IsNil)
|
2017-01-27 08:10:36 -05:00
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-01-27 08:10:36 -05:00
|
|
|
}
|
2017-04-24 19:40:34 -04:00
|
|
|
|
|
|
|
func TestDomainSniffing(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-04-24 19:40:34 -04:00
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
sniffingPort := tcp.PickPort()
|
|
|
|
httpPort := tcp.PickPort()
|
2017-04-24 19:40:34 -04:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-04-24 19:40:34 -04:00
|
|
|
{
|
|
|
|
Tag: "snif",
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(sniffingPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-04-24 19:40:34 -04:00
|
|
|
DomainOverride: []proxyman.KnownProtocols{
|
|
|
|
proxyman.KnownProtocols_TLS,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-04-24 19:40:34 -04:00
|
|
|
Port: 443,
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-04-24 19:40:34 -04:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tag: "http",
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 06:56:57 -04:00
|
|
|
PortRange: net.SinglePortRange(httpPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-04-24 19:40:34 -04:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&v2http.ServerConfig{}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-04-24 19:40:34 -04:00
|
|
|
{
|
|
|
|
Tag: "redir",
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
|
|
|
DestinationOverride: &freedom.DestinationOverride{
|
|
|
|
Server: &protocol.ServerEndpoint{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-04-24 19:40:34 -04:00
|
|
|
Port: uint32(sniffingPort),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tag: "direct",
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&router.Config{
|
|
|
|
Rule: []*router.RoutingRule{
|
|
|
|
{
|
2018-11-07 19:01:53 -05:00
|
|
|
TargetTag: &router.RoutingRule_Tag{
|
|
|
|
Tag: "direct",
|
|
|
|
},
|
2017-04-24 19:40:34 -04:00
|
|
|
InboundTag: []string{"snif"},
|
|
|
|
}, {
|
2018-11-07 19:01:53 -05:00
|
|
|
TargetTag: &router.RoutingRule_Tag{
|
|
|
|
Tag: "redir",
|
|
|
|
},
|
2017-04-24 19:40:34 -04:00
|
|
|
InboundTag: []string{"http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
serial.ToTypedMessage(&log.Config{
|
2017-12-19 16:29:56 -05:00
|
|
|
ErrorLogLevel: clog.Severity_Debug,
|
2017-04-24 19:40:34 -04:00
|
|
|
ErrorLogType: log.LogType_Console,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2017-04-24 19:40:34 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
transport := &http.Transport{
|
|
|
|
Proxy: func(req *http.Request) (*url.URL, error) {
|
|
|
|
return url.Parse("http://127.0.0.1:" + httpPort.String())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: transport,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := client.Get("https://www.github.com/")
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(resp.StatusCode, Equals, 200)
|
2017-04-25 07:34:00 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(resp.Write(ioutil.Discard), IsNil)
|
2017-04-24 19:40:34 -04:00
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
CloseAllServers(servers)
|
2017-04-24 19:40:34 -04:00
|
|
|
}
|
2018-02-20 18:18:53 -05:00
|
|
|
|
|
|
|
func TestDialV2Ray(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
assert(err, IsNil)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2018-02-20 18:18:53 -05:00
|
|
|
serverConfig := &core.Config{
|
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&log.Config{
|
|
|
|
ErrorLogLevel: clog.Severity_Debug,
|
|
|
|
ErrorLogType: log.LogType_Console,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
AlterId: 64,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&dispatcher.Config{}),
|
|
|
|
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
|
|
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
|
|
|
},
|
|
|
|
Inbound: []*core.InboundHandlerConfig{},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
AlterId: 64,
|
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
|
|
|
Type: protocol.SecurityType_AES128_GCM,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig)
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
client, err := core.New(clientConfig)
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
conn, err := core.Dial(context.Background(), client, dest)
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
payload := "commander request."
|
|
|
|
nBytes, err := conn.Write([]byte(payload))
|
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, len(payload))
|
|
|
|
|
|
|
|
response := make([]byte, 1024)
|
|
|
|
nBytes, err = conn.Read(response)
|
|
|
|
assert(err, IsNil)
|
|
|
|
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
|
|
|
assert(conn.Close(), IsNil)
|
|
|
|
|
|
|
|
CloseAllServers(servers)
|
|
|
|
}
|