2020-11-25 13:01:53 +02:00
|
|
|
package scenarios
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/x509"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-12-04 03:36:16 +02:00
|
|
|
"github.com/xtls/xray-core/app/proxyman"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
|
|
"github.com/xtls/xray-core/common/protocol/tls/cert"
|
|
|
|
"github.com/xtls/xray-core/common/serial"
|
|
|
|
"github.com/xtls/xray-core/common/uuid"
|
|
|
|
core "github.com/xtls/xray-core/core"
|
|
|
|
"github.com/xtls/xray-core/proxy/dokodemo"
|
|
|
|
"github.com/xtls/xray-core/proxy/freedom"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess/inbound"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
|
|
|
"github.com/xtls/xray-core/testing/servers/tcp"
|
|
|
|
"github.com/xtls/xray-core/testing/servers/udp"
|
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
2021-03-14 17:02:07 +02:00
|
|
|
"github.com/xtls/xray-core/transport/internet/grpc"
|
2020-12-04 03:36:16 +02:00
|
|
|
"github.com/xtls/xray-core/transport/internet/http"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/tls"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/websocket"
|
2022-05-18 10:29:01 +03:00
|
|
|
"golang.org/x/sync/errgroup"
|
2020-11-25 13:01:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleTLSConnection(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
2021-12-15 02:28:47 +02:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2020-11-25 13:01:53 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoIssuingCertificate(t *testing.T) {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Not supported on Windows yet.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtime.GOARCH == "arm64" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
caCert, err := cert.Generate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageDigitalSignature|x509.KeyUsageKeyEncipherment|x509.KeyUsageCertSign))
|
|
|
|
common.Must(err)
|
|
|
|
certPEM, keyPEM := caCert.ToPEM()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
ServerName: "example.com",
|
|
|
|
Certificate: []*tls.Certificate{{
|
|
|
|
Certificate: certPEM,
|
|
|
|
Usage: tls.Certificate_AUTHORITY_VERIFY,
|
|
|
|
}},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2021-12-15 02:28:47 +02:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2020-11-25 13:01:53 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTLSOverKCP(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := udp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
2024-09-23 18:28:19 +03:00
|
|
|
ProtocolName: "mkcp",
|
2020-11-25 13:01:53 +02:00
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{
|
2024-09-23 18:28:19 +03:00
|
|
|
ProtocolName: "mkcp",
|
2020-11-25 13:01:53 +02:00
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
2021-12-15 02:28:47 +02:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2020-11-25 13:01:53 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTLSOverWebSocket(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
2024-09-23 18:28:19 +03:00
|
|
|
ProtocolName: "websocket",
|
2020-11-25 13:01:53 +02:00
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{
|
2024-11-09 13:16:11 +02:00
|
|
|
ProtocolName: "websocket",
|
2020-11-25 13:01:53 +02:00
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
2024-09-23 18:28:19 +03:00
|
|
|
ProtocolName: "websocket",
|
|
|
|
Settings: serial.ToTypedMessage(&websocket.Config{}),
|
2020-11-25 13:01:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
var errg errgroup.Group
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
|
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTP2(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
2024-11-09 13:16:11 +02:00
|
|
|
ProtocolName: "http",
|
2020-11-25 13:01:53 +02:00
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
2024-09-23 18:28:19 +03:00
|
|
|
ProtocolName: "http",
|
2024-11-09 13:16:11 +02:00
|
|
|
Settings: serial.ToTypedMessage(&http.Config{
|
2020-11-25 13:01:53 +02:00
|
|
|
Host: []string{"example.com"},
|
|
|
|
Path: "/testpath",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{
|
2024-11-09 13:16:11 +02:00
|
|
|
ProtocolName: "http",
|
2020-11-25 13:01:53 +02:00
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
2024-09-23 18:28:19 +03:00
|
|
|
ProtocolName: "http",
|
2024-11-09 13:16:11 +02:00
|
|
|
Settings: serial.ToTypedMessage(&http.Config{
|
2020-11-25 13:01:53 +02:00
|
|
|
Host: []string{"example.com"},
|
|
|
|
Path: "/testpath",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
var errg errgroup.Group
|
|
|
|
for i := 0; i < 10; i++ {
|
2021-03-02 16:46:50 +02:00
|
|
|
errg.Go(testTCPConn(clientPort, 1024*1024, time.Second*40))
|
2020-11-25 13:01:53 +02:00
|
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2021-03-14 17:02:07 +02:00
|
|
|
|
|
|
|
func TestGRPC(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2021-03-14 17:02:07 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉"}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2021-03-14 17:02:07 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2021-03-14 17:02:07 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉"}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
var errg errgroup.Group
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
errg.Go(testTCPConn(clientPort, 1024*10240, time.Second*40))
|
|
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGRPCMultiMode(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2021-03-14 17:02:07 +02:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉"}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2021-03-14 17:02:07 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2021-03-14 17:02:07 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
ProtocolName: "grpc",
|
|
|
|
Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉", MultiMode: true}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
var errg errgroup.Group
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
errg.Go(testTCPConn(clientPort, 1024*10240, time.Second*40))
|
|
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2021-10-22 07:04:06 +03: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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2021-10-22 07:04:06 +03:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
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{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2021-10-22 07:04:06 +03:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2021-10-22 07:04:06 +03:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
PinnedPeerCertificateChainSha256: [][]byte{certHash},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
2021-12-15 02:28:47 +02:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
2021-10-22 07:04:06 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2023-01-27 06:19:49 +02:00
|
|
|
|
|
|
|
func TestSimpleTLSConnectionPinnedWrongCert(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})
|
|
|
|
certHash[1] += 1
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
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{
|
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2023-01-27 06:19:49 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
AllowInsecure: true,
|
|
|
|
PinnedPeerCertificateChainSha256: [][]byte{certHash},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUTLSConnectionPinned(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{
|
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
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{
|
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2023-01-27 06:19:49 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Fingerprint: "random",
|
|
|
|
AllowInsecure: true,
|
|
|
|
PinnedPeerCertificateChainSha256: [][]byte{certHash},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUTLSConnectionPinnedWrongCert(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})
|
|
|
|
certHash[1] += 1
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
SecurityType: serial.GetMessageType(&tls.Config{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
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{
|
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2024-11-09 13:16:11 +02:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2023-01-27 06:19:49 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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{}),
|
|
|
|
SecuritySettings: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&tls.Config{
|
|
|
|
Fingerprint: "random",
|
|
|
|
AllowInsecure: true,
|
|
|
|
PinnedPeerCertificateChainSha256: [][]byte{certHash},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*20)(); err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|