@@ -3,12 +3,14 @@ package inbound_test
3
3
import (
4
4
"crypto/rand"
5
5
"encoding/base64"
6
+ "net"
6
7
"net/netip"
7
8
"strings"
8
9
"testing"
9
10
10
11
"github.com/metacubex/mihomo/adapter/outbound"
11
12
"github.com/metacubex/mihomo/listener/inbound"
13
+ shadowtls "github.com/metacubex/mihomo/transport/sing-shadowtls"
12
14
13
15
shadowsocks "github.com/metacubex/sing-shadowsocks"
14
16
"github.com/metacubex/sing-shadowsocks/shadowaead"
@@ -18,22 +20,25 @@ import (
18
20
)
19
21
20
22
var shadowsocksCipherList = []string {shadowsocks .MethodNone }
23
+ var shadowsocksCipherListShort = []string {shadowsocks .MethodNone }
21
24
var shadowsocksPassword32 string
22
25
var shadowsocksPassword16 string
23
26
24
27
func init () {
25
28
shadowsocksCipherList = append (shadowsocksCipherList , shadowaead .List ... )
26
29
shadowsocksCipherList = append (shadowsocksCipherList , shadowaead_2022 .List ... )
27
30
shadowsocksCipherList = append (shadowsocksCipherList , shadowstream .List ... )
31
+ shadowsocksCipherListShort = append (shadowsocksCipherListShort , shadowaead .List [0 ])
32
+ shadowsocksCipherListShort = append (shadowsocksCipherListShort , shadowaead_2022 .List [0 ])
28
33
passwordBytes := make ([]byte , 32 )
29
34
rand .Read (passwordBytes )
30
35
shadowsocksPassword32 = base64 .StdEncoding .EncodeToString (passwordBytes )
31
36
shadowsocksPassword16 = base64 .StdEncoding .EncodeToString (passwordBytes [:16 ])
32
37
}
33
38
34
- func testInboundShadowSocks (t * testing.T , inboundOptions inbound.ShadowSocksOption , outboundOptions outbound.ShadowSocksOption ) {
39
+ func testInboundShadowSocks (t * testing.T , inboundOptions inbound.ShadowSocksOption , outboundOptions outbound.ShadowSocksOption , cipherList [] string ) {
35
40
t .Parallel ()
36
- for _ , cipher := range shadowsocksCipherList {
41
+ for _ , cipher := range cipherList {
37
42
cipher := cipher
38
43
t .Run (cipher , func (t * testing.T ) {
39
44
inboundOptions , outboundOptions := inboundOptions , outboundOptions // don't modify outside options value
@@ -94,5 +99,53 @@ func testInboundShadowSocks0(t *testing.T, inboundOptions inbound.ShadowSocksOpt
94
99
func TestInboundShadowSocks_Basic (t * testing.T ) {
95
100
inboundOptions := inbound.ShadowSocksOption {}
96
101
outboundOptions := outbound.ShadowSocksOption {}
97
- testInboundShadowSocks (t , inboundOptions , outboundOptions )
102
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , shadowsocksCipherList )
103
+ }
104
+
105
+ func TestInboundShadowSocks_ShadowTlsv1 (t * testing.T ) {
106
+ inboundOptions := inbound.ShadowSocksOption {
107
+ ShadowTLS : inbound.ShadowTLS {
108
+ Enable : true ,
109
+ Version : 1 ,
110
+ Handshake : inbound.ShadowTLSHandshakeOptions {Dest : net .JoinHostPort (realityDest , "443" )},
111
+ },
112
+ }
113
+ outboundOptions := outbound.ShadowSocksOption {
114
+ Plugin : shadowtls .Mode ,
115
+ PluginOpts : map [string ]any {"host" : realityDest , "fingerprint" : tlsFingerprint , "version" : 1 },
116
+ }
117
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , shadowsocksCipherListShort )
118
+ }
119
+
120
+ func TestInboundShadowSocks_ShadowTlsv2 (t * testing.T ) {
121
+ inboundOptions := inbound.ShadowSocksOption {
122
+ ShadowTLS : inbound.ShadowTLS {
123
+ Enable : true ,
124
+ Version : 2 ,
125
+ Password : shadowsocksPassword16 ,
126
+ Handshake : inbound.ShadowTLSHandshakeOptions {Dest : net .JoinHostPort (realityDest , "443" )},
127
+ },
128
+ }
129
+ outboundOptions := outbound.ShadowSocksOption {
130
+ Plugin : shadowtls .Mode ,
131
+ PluginOpts : map [string ]any {"host" : realityDest , "password" : shadowsocksPassword16 , "fingerprint" : tlsFingerprint , "version" : 2 },
132
+ }
133
+ outboundOptions .PluginOpts ["alpn" ] = []string {"http/1.1" } // shadowtls v2 work confuse with http/2 server, so we set alpn to http/1.1 to pass the test
134
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , shadowsocksCipherListShort )
135
+ }
136
+
137
+ func TestInboundShadowSocks_ShadowTlsv3 (t * testing.T ) {
138
+ inboundOptions := inbound.ShadowSocksOption {
139
+ ShadowTLS : inbound.ShadowTLS {
140
+ Enable : true ,
141
+ Version : 3 ,
142
+ Users : []inbound.ShadowTLSUser {{Name : "test" , Password : shadowsocksPassword16 }},
143
+ Handshake : inbound.ShadowTLSHandshakeOptions {Dest : net .JoinHostPort (realityDest , "443" )},
144
+ },
145
+ }
146
+ outboundOptions := outbound.ShadowSocksOption {
147
+ Plugin : shadowtls .Mode ,
148
+ PluginOpts : map [string ]any {"host" : realityDest , "password" : shadowsocksPassword16 , "fingerprint" : tlsFingerprint , "version" : 3 },
149
+ }
150
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , shadowsocksCipherListShort )
98
151
}
0 commit comments