mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
fix shadow, add obfs key
This commit is contained in:
+65
-25
@@ -3,9 +3,9 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"testing"
|
||||
@@ -97,7 +97,7 @@ func getTLSConfig() conf.TLSConfig {
|
||||
VerifyHostname: true,
|
||||
ReuseSession: true,
|
||||
SessionTicket: true,
|
||||
FallbackAddress: common.NewAddress("127.0.0.1", 80, "tcp"),
|
||||
FallbackAddress: common.NewAddress("127.0.0.1", 10080, "tcp"),
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -139,12 +139,15 @@ func getBasicClientConfig() *conf.GlobalConfig {
|
||||
|
||||
func addWsConfig(config *conf.GlobalConfig) *conf.GlobalConfig {
|
||||
config.Websocket = conf.WebsocketConfig{
|
||||
Enabled: true,
|
||||
HostName: "127.0.0.1",
|
||||
Path: "/websocket",
|
||||
Obfuscation: false,
|
||||
DoubleTLS: true,
|
||||
Enabled: true,
|
||||
HostName: "127.0.0.1",
|
||||
Path: "/websocket",
|
||||
ObfuscationPassword: "123456789",
|
||||
DoubleTLS: true,
|
||||
}
|
||||
hash := md5.New()
|
||||
hash.Write([]byte(config.Websocket.ObfuscationPassword))
|
||||
config.Websocket.ObfuscationKey = hash.Sum(nil)
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -326,13 +329,60 @@ func BenchmarkWebsocket(b *testing.B) {
|
||||
SingleThreadSpeedTestClientServer(b, clientConfig, serverConfig)
|
||||
}
|
||||
|
||||
func TestHTTPProxy(t *testing.T) {
|
||||
func BenchmarkMuxWebsocket(b *testing.B) {
|
||||
clientConfig := addMuxConfig(addWsConfig(getBasicClientConfig()))
|
||||
serverConfig := addWsConfig(getBasicServerConfig())
|
||||
SingleThreadSpeedTestClientServer(b, clientConfig, serverConfig)
|
||||
}
|
||||
|
||||
func TestWebsocketShadow(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go RunHelloHTTPServer(ctx)
|
||||
serverConfig := addWsConfig(getBasicServerConfig())
|
||||
go RunServer(ctx, serverConfig)
|
||||
time.Sleep(time.Second)
|
||||
|
||||
//test http
|
||||
httpClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
resp, err := httpClient.Get("https://127.0.0.1:4445")
|
||||
common.Must(err)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
common.Must(err)
|
||||
if string(body) != "HelloWorld" {
|
||||
t.Fatal("http shadow")
|
||||
}
|
||||
|
||||
//test websocket
|
||||
conn, err := tls.Dial("tcp", "127.0.0.1:4445", &tls.Config{InsecureSkipVerify: true})
|
||||
common.Must(err)
|
||||
wsConfig, err := websocket.NewConfig("wss://127.0.0.1/websocket", "https://127.0.0.1")
|
||||
common.Must(err)
|
||||
wsClient, err := websocket.NewClient(wsConfig, conn)
|
||||
common.Must(err)
|
||||
buf := [100]byte{}
|
||||
common.Must2(wsClient.Write([]byte("I'm GFW1231231231231212391273871283719823791237912398721933123")))
|
||||
n, err := wsClient.Read(buf[:])
|
||||
common.Must(err)
|
||||
if string(buf[:n]) != "HelloWorld" {
|
||||
t.Fatal("ws shadow")
|
||||
}
|
||||
conn.Close()
|
||||
cancel()
|
||||
}
|
||||
|
||||
func TestShadow(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go RunHelloHTTPServer(ctx)
|
||||
serverConfig := getBasicServerConfig()
|
||||
go RunServer(ctx, serverConfig)
|
||||
time.Sleep(time.Second)
|
||||
|
||||
//test http
|
||||
httpClient := &http.Client{
|
||||
//some config
|
||||
@@ -347,26 +397,16 @@ func TestHTTPProxy(t *testing.T) {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
common.Must(err)
|
||||
if string(body) != "HelloWorld" {
|
||||
t.Fatal("server http proxy failed")
|
||||
t.Fatal("http shadow")
|
||||
}
|
||||
|
||||
//test websocket
|
||||
conn, err := tls.Dial("tcp", "127.0.0.1:4445", &tls.Config{InsecureSkipVerify: true})
|
||||
common.Must(err)
|
||||
wsConfig, err := websocket.NewConfig("wss://127.0.0.1/websocket", "https://127.0.0.1")
|
||||
common.Must(err)
|
||||
wsClient, err := websocket.NewClient(wsConfig, conn)
|
||||
common.Must(err)
|
||||
buf := [100]byte{}
|
||||
common.Must2(wsClient.Write([]byte("I'm GFW1231231231231212391273871283719823791237912398721933123")))
|
||||
common.Must2(wsClient.Read(buf[:]))
|
||||
fmt.Println(buf)
|
||||
common.Must(err)
|
||||
conn.Close()
|
||||
|
||||
//fallback
|
||||
resp, err = http.Get("http://127.0.0.1:4445")
|
||||
common.Must(err)
|
||||
resp.Body.Read(buf[:])
|
||||
fmt.Println(buf)
|
||||
body, err = ioutil.ReadAll(resp.Body)
|
||||
common.Must(err)
|
||||
if string(body) != "HelloWorld" {
|
||||
t.Fatal("http shadow")
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user