Skip to content

Commit 8ff4351

Browse files
authored
Fix Shadowsocks tests; AEAD drop small UDP packets
https://t.me/projectXray/172063
1 parent 33755d6 commit 8ff4351

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

proxy/shadowsocks/protocol.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ func DecodeUDPPacket(users []*protocol.MemoryUser, payload *buf.Buffer) (*protoc
268268

269269
if len(users) > 1 {
270270
bs := payload.Bytes()
271+
if len(bs) <= 32 {
272+
return nil, nil, newError("len(bs) <= 32")
273+
}
271274

272275
var aeadCipher *AEADCipher
273276
var ivLen int32

proxy/shadowsocks/protocol_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestUDPEncoding(t *testing.T) {
2828
Email: "love@example.com",
2929
Account: toAccount(&Account{
3030
Password: "shadowsocks-password",
31-
CipherType: CipherType_AES_128_CFB,
31+
CipherType: CipherType_AES_128_GCM,
3232
}),
3333
},
3434
}
@@ -65,7 +65,7 @@ func TestTCPRequest(t *testing.T) {
6565
Email: "love@example.com",
6666
Account: toAccount(&Account{
6767
Password: "tcp-password",
68-
CipherType: CipherType_CHACHA20,
68+
CipherType: CipherType_CHACHA20_POLY1305,
6969
}),
7070
},
7171
},
@@ -81,7 +81,7 @@ func TestTCPRequest(t *testing.T) {
8181
Email: "love@example.com",
8282
Account: toAccount(&Account{
8383
Password: "password",
84-
CipherType: CipherType_AES_256_CFB,
84+
CipherType: CipherType_AES_256_GCM,
8585
}),
8686
},
8787
},
@@ -97,7 +97,7 @@ func TestTCPRequest(t *testing.T) {
9797
Email: "love@example.com",
9898
Account: toAccount(&Account{
9999
Password: "password",
100-
CipherType: CipherType_CHACHA20_IETF,
100+
CipherType: CipherType_AES_128_GCM,
101101
}),
102102
},
103103
},
@@ -139,7 +139,7 @@ func TestUDPReaderWriter(t *testing.T) {
139139
user := &protocol.MemoryUser{
140140
Account: toAccount(&Account{
141141
Password: "test-password",
142-
CipherType: CipherType_CHACHA20_IETF,
142+
CipherType: CipherType_CHACHA20_POLY1305,
143143
}),
144144
}
145145
cache := buf.New()

testing/scenarios/shadowsocks_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func TestShadowsocksAES256TCP(t *testing.T) {
5252
Listen: net.NewIPOrDomain(net.LocalHostIP),
5353
}),
5454
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
55-
User: &protocol.User{
55+
Users: []*protocol.User{{
5656
Account: account,
5757
Level: 1,
58-
},
58+
}},
5959
Network: []net.Network{net.Network_TCP},
6060
}),
6161
},
@@ -150,10 +150,10 @@ func TestShadowsocksAES128UDP(t *testing.T) {
150150
Listen: net.NewIPOrDomain(net.LocalHostIP),
151151
}),
152152
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
153-
User: &protocol.User{
153+
Users: []*protocol.User{{
154154
Account: account,
155155
Level: 1,
156-
},
156+
}},
157157
Network: []net.Network{net.Network_UDP},
158158
}),
159159
},
@@ -276,10 +276,10 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
276276
Listen: net.NewIPOrDomain(net.LocalHostIP),
277277
}),
278278
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
279-
User: &protocol.User{
279+
Users: []*protocol.User{{
280280
Account: account,
281281
Level: 1,
282-
},
282+
}},
283283
Network: []net.Network{net.Network_TCP},
284284
}),
285285
},
@@ -369,10 +369,10 @@ func TestShadowsocksChacha20Poly1305TCP(t *testing.T) {
369369
Listen: net.NewIPOrDomain(net.LocalHostIP),
370370
}),
371371
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
372-
User: &protocol.User{
372+
Users: []*protocol.User{{
373373
Account: account,
374374
Level: 1,
375-
},
375+
}},
376376
Network: []net.Network{net.Network_TCP},
377377
}),
378378
},
@@ -461,10 +461,10 @@ func TestShadowsocksAES256GCMTCP(t *testing.T) {
461461
Listen: net.NewIPOrDomain(net.LocalHostIP),
462462
}),
463463
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
464-
User: &protocol.User{
464+
Users: []*protocol.User{{
465465
Account: account,
466466
Level: 1,
467-
},
467+
}},
468468
Network: []net.Network{net.Network_TCP},
469469
}),
470470
},
@@ -560,10 +560,10 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
560560
Listen: net.NewIPOrDomain(net.LocalHostIP),
561561
}),
562562
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
563-
User: &protocol.User{
563+
Users: []*protocol.User{{
564564
Account: account,
565565
Level: 1,
566-
},
566+
}},
567567
Network: []net.Network{net.Network_UDP},
568568
}),
569569
},
@@ -658,10 +658,10 @@ func TestShadowsocksAES128GCMUDPMux(t *testing.T) {
658658
Listen: net.NewIPOrDomain(net.LocalHostIP),
659659
}),
660660
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
661-
User: &protocol.User{
661+
Users: []*protocol.User{{
662662
Account: account,
663663
Level: 1,
664-
},
664+
}},
665665
Network: []net.Network{net.Network_TCP},
666666
}),
667667
},
@@ -757,10 +757,10 @@ func TestShadowsocksNone(t *testing.T) {
757757
Listen: net.NewIPOrDomain(net.LocalHostIP),
758758
}),
759759
ProxySettings: serial.ToTypedMessage(&shadowsocks.ServerConfig{
760-
User: &protocol.User{
760+
Users: []*protocol.User{{
761761
Account: account,
762762
Level: 1,
763-
},
763+
}},
764764
Network: []net.Network{net.Network_TCP},
765765
}),
766766
},

0 commit comments

Comments
 (0)