2016-12-16 15:39:00 -05:00
|
|
|
package scenarios
|
|
|
|
|
|
|
|
import (
|
2018-04-10 06:42:02 -04:00
|
|
|
"crypto/x509"
|
|
|
|
"runtime"
|
2016-12-30 17:12:00 -05:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-01-06 18:12:04 -05:00
|
|
|
"golang.org/x/sync/errgroup"
|
2021-10-28 06:34:19 -04:00
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
2019-01-06 18:12:04 -05:00
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
core "github.com/v2fly/v2ray-core/v5"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/proxyman"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/protocol"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/protocol/tls/cert"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/uuid"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/dokodemo"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/freedom"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/inbound"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/testing/servers/tcp"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/testing/servers/udp"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/transport/internet/http"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/transport/internet/tls"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/transport/internet/websocket"
|
2016-12-16 15:39:00 -05:00
|
|
|
)
|
|
|
|
|
2016-12-30 17:12:00 -05:00
|
|
|
func TestSimpleTLSConnection(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2018-08-16 06:05:33 -04:00
|
|
|
common.Must(err)
|
2017-01-05 05:20:04 -05:00
|
|
|
defer tcpServer.Close()
|
2016-12-30 17:12:00 -05:00
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2016-12-30 17:12:00 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2016-12-30 17:12:00 -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{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2017-01-26 14:46:44 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
2018-04-10 06:42:02 -04:00
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
2016-12-30 17:12:00 -05:00
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2017-01-12 10:10:03 -05:00
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-12 10:10:03 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2017-01-12 10:10:03 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2017-01-12 10:10:03 -05:00
|
|
|
clientConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-12 10:10:03 -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 10:10:03 -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 10:10:03 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-01-12 10:10:03 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
2017-01-12 10:10:03 -05:00
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-01-12 10:10:03 -05:00
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
2016-12-30 17:12:00 -05:00
|
|
|
{
|
2017-01-12 10:10:03 -05:00
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
2016-12-30 17:12:00 -05:00
|
|
|
},
|
|
|
|
},
|
2017-01-12 10:10:03 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2017-01-26 14:46:44 -05:00
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2017-01-26 14:46:44 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
2017-01-12 10:10:03 -05:00
|
|
|
},
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
2017-01-12 10:10:03 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2018-08-16 06:05:33 -04:00
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
2021-11-26 23:57:27 -05:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2019-01-06 18:12:04 -05:00
|
|
|
t.Fatal(err)
|
2018-08-16 06:05:33 -04:00
|
|
|
}
|
2017-01-12 10:10:03 -05:00
|
|
|
}
|
|
|
|
|
2018-04-10 06:42:02 -04:00
|
|
|
func TestAutoIssuingCertificate(t *testing.T) {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Not supported on Windows yet.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-09 10:30:05 -04:00
|
|
|
if runtime.GOARCH == "arm64" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:42:02 -04:00
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
2018-04-10 06:42:02 -04:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
caCert, err := cert.Generate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageDigitalSignature|x509.KeyUsageKeyEncipherment|x509.KeyUsageCertSign))
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
2018-04-10 06:42:02 -04:00
|
|
|
certPEM, keyPEM := caCert.ToPEM()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2018-04-10 06:42:02 -04:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{{
|
|
|
|
Certificate: certPEM,
|
|
|
|
Key: keyPEM,
|
|
|
|
Usage: tls.Certificate_AUTHORITY_ISSUE,
|
|
|
|
}},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2018-04-10 06:42:02 -04:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
2021-02-16 15:31:50 -05:00
|
|
|
ServerName: "v2fly.org",
|
2018-04-10 06:42:02 -04:00
|
|
|
Certificate: []*tls.Certificate{{
|
|
|
|
Certificate: certPEM,
|
|
|
|
Usage: tls.Certificate_AUTHORITY_VERIFY,
|
|
|
|
}},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
2018-04-10 06:42:02 -04:00
|
|
|
|
2018-08-09 17:02:31 -04:00
|
|
|
for i := 0; i < 10; i++ {
|
2021-11-26 23:57:27 -05:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2019-01-11 11:17:59 -05:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2018-08-09 17:02:31 -04:00
|
|
|
}
|
2018-04-10 06:42:02 -04:00
|
|
|
}
|
|
|
|
|
2017-01-12 10:10:03 -05:00
|
|
|
func TestTLSOverKCP(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
2017-01-12 10:10:03 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
2017-11-14 17:45:07 -05:00
|
|
|
serverPort := udp.PickPort()
|
2017-01-12 10:10:03 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-01-12 10:10:03 -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,
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2017-01-26 14:46:44 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
2018-04-10 06:42:02 -04:00
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
2017-01-12 10:10:03 -05:00
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2016-12-30 17:12:00 -05:00
|
|
|
},
|
2016-12-16 15:39:00 -05:00
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2016-12-30 17:12:00 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
2016-12-30 17:12:00 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2016-12-30 17:12:00 -05:00
|
|
|
clientConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2016-12-30 17:12:00 -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),
|
2016-12-30 17:12:00 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2016-12-30 17:12:00 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2016-12-30 17:12:00 -05:00
|
|
|
{
|
2017-01-26 14:46:44 -05:00
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
2016-12-30 17:12:00 -05:00
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2016-12-30 17:12:00 -05:00
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2017-01-26 14:46:44 -05:00
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_MKCP,
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2017-01-26 14:46:44 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
2016-12-30 17:12:00 -05:00
|
|
|
},
|
2017-01-26 14:46:44 -05:00
|
|
|
}),
|
2016-12-30 17:12:00 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
2017-01-04 09:42:06 -05:00
|
|
|
|
2021-11-26 23:57:27 -05:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2019-01-11 11:17:59 -05:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2017-01-04 09:42:06 -05:00
|
|
|
}
|
|
|
|
|
2017-02-08 11:57:21 -05:00
|
|
|
func TestTLSOverWebSocket(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
2017-02-08 11:57:21 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
2018-03-01 05:53:39 -05:00
|
|
|
serverPort := tcp.PickPort()
|
2017-02-08 11:57:21 -05:00
|
|
|
serverConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-02-08 11:57:21 -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-02-08 11:57:21 -05:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_WebSocket,
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2017-02-08 11:57:21 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
2018-04-10 06:42:02 -04:00
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
2017-02-08 11:57:21 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-02-08 11:57:21 -05:00
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2017-02-08 11:57:21 -05:00
|
|
|
clientConfig := &core.Config{
|
2018-01-10 06:22:37 -05:00
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
2017-02-08 11:57:21 -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-02-08 11:57:21 -05:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
2017-02-08 11:57:21 -05:00
|
|
|
Port: uint32(dest.Port),
|
2017-08-29 06:56:57 -04:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
2017-02-08 11:57:21 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 06:22:37 -05:00
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
2017-02-08 11:57:21 -05:00
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 06:56:57 -04:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-02-08 11:57:21 -05:00
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_WebSocket,
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_WebSocket,
|
2017-04-07 15:54:40 -04:00
|
|
|
Settings: serial.ToTypedMessage(&websocket.Config{}),
|
2017-02-08 11:57:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2017-02-08 11:57:21 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-17 18:39:30 -04:00
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2018-11-13 14:55:34 -05:00
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
2017-02-08 11:57:21 -05:00
|
|
|
|
2019-01-11 11:17:59 -05:00
|
|
|
var errg errgroup.Group
|
2018-11-13 14:55:34 -05:00
|
|
|
for i := 0; i < 10; i++ {
|
2019-01-11 11:17:59 -05:00
|
|
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
|
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
|
|
t.Error(err)
|
2018-11-13 14:55:34 -05:00
|
|
|
}
|
2017-02-08 11:57:21 -05:00
|
|
|
}
|
2018-03-01 15:22:53 -05:00
|
|
|
|
|
|
|
func TestHTTP2(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
2018-03-01 15:22:53 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_HTTP,
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_HTTP,
|
|
|
|
Settings: serial.ToTypedMessage(&http.Config{
|
2021-02-16 15:31:50 -05:00
|
|
|
Host: []string{"v2fly.org"},
|
2018-03-01 15:22:53 -05:00
|
|
|
Path: "/testpath",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2018-03-01 15:22:53 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
2018-04-10 06:42:02 -04:00
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
2018-03-01 15:22:53 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_HTTP,
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_HTTP,
|
|
|
|
Settings: serial.ToTypedMessage(&http.Config{
|
2021-02-16 15:31:50 -05:00
|
|
|
Host: []string{"v2fly.org"},
|
2018-03-01 15:22:53 -05:00
|
|
|
Path: "/testpath",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2018-03-01 15:22:53 -05:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2019-01-11 11:17:59 -05:00
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
2018-03-01 15:22:53 -05:00
|
|
|
|
2019-01-11 11:17:59 -05:00
|
|
|
var errg errgroup.Group
|
2018-03-01 15:42:42 -05:00
|
|
|
for i := 0; i < 10; i++ {
|
2021-01-11 04:03:03 -05:00
|
|
|
errg.Go(testTCPConn(clientPort, 7168*1024, time.Second*40))
|
2019-01-11 11:17:59 -05:00
|
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
|
|
t.Error(err)
|
2018-03-01 15:42:42 -05:00
|
|
|
}
|
2018-03-01 15:22:53 -05:00
|
|
|
}
|
2021-04-15 14:49:26 -04:00
|
|
|
|
|
|
|
func TestSimpleTLSConnectionPinned(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
certificateDer := cert.MustGenerate(nil)
|
|
|
|
certificate := tls.ParseCertificate(certificateDer)
|
|
|
|
certHash := tls.GenerateCertChainHash([][]byte{certificateDer.Certificate})
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2021-04-15 14:49:26 -04:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{certificate},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
2021-06-19 09:36:54 -04:00
|
|
|
SecuritySettings: []*anypb.Any{
|
2021-04-15 14:49:26 -04:00
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
PinnedPeerCertificateChainSha256: [][]byte{certHash},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
2021-11-26 23:57:27 -05:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2021-04-15 14:49:26 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|