From b0b65cb3fa0144a51ec57056e12099b6de603558 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 30 Nov 2017 20:59:12 +0100 Subject: [PATCH] chacha20 confermance test --- testing/scenarios/shadowsocks_test.go | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/testing/scenarios/shadowsocks_test.go b/testing/scenarios/shadowsocks_test.go index 50235837..ae3f611c 100644 --- a/testing/scenarios/shadowsocks_test.go +++ b/testing/scenarios/shadowsocks_test.go @@ -773,3 +773,82 @@ func TestShadowsocksChacha20Poly1305UDPConformance(t *testing.T) { CloseAllServers(servers) } + +func TestShadowsocksChacha20Conformance(t *testing.T) { + assert := With(t) + + tcpServer := tcp.Server{ + MsgProcessor: xor, + } + dest, err := tcpServer.Start() + assert(err, IsNil) + defer tcpServer.Close() + + account := serial.ToTypedMessage(&shadowsocks.Account{ + Password: "ss-password", + CipherType: shadowsocks.CipherType_CHACHA20_IETF, + Ota: shadowsocks.Account_Disabled, + }) + + serverPort := pickPort() + serverConfig := &core.Config{ + App: []*serial.TypedMessage{ + serial.ToTypedMessage(&log.Config{ + ErrorLogLevel: log.LogLevel_Debug, + ErrorLogType: log.LogType_Console, + }), + }, + Inbound: []*proxyman.InboundHandlerConfig{ + { + ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ + PortRange: net.SinglePortRange(serverPort), + Listen: net.NewIPOrDomain(net.LocalHostIP), + }), + ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{ + User: &protocol.User{ + Account: account, + Level: 1, + }, + }), + }, + }, + Outbound: []*proxyman.OutboundHandlerConfig{ + { + ProxySettings: serial.ToTypedMessage(&freedom.Config{}), + }, + }, + } + + servers, err := InitializeServerConfigs(serverConfig) + assert(err, IsNil) + + var wg sync.WaitGroup + wg.Add(10) + for i := 0; i < 10; i++ { + go func() { + cipher, err := ss.PickCipher("CHACHA20-IETF", nil, "ss-password") + assert(err, IsNil) + conn, err := ss.Dial("tcp", fmt.Sprintf(":%d", serverPort), cipher) + assert(err, IsNil) + _, err = conn.Write([]byte{1, 127, 0, 0, 1}) + assert(err, IsNil) + _, err = conn.Write(serial.Uint16ToBytes(dest.Port.Value(), nil)) + assert(err, IsNil) + + payload := make([]byte, 10240*1024) + rand.Read(payload) + + nBytes, err := conn.Write([]byte(payload)) + assert(err, IsNil) + assert(nBytes, Equals, len(payload)) + + response := readFrom(conn, time.Second*30, 10240*1024) + assert(response, Equals, xor([]byte(payload))) + assert(conn.Close(), IsNil) + wg.Done() + }() + } + wg.Wait() + + CloseAllServers(servers) +}