@@ -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"
@@ -31,9 +33,9 @@ func init() {
31
33
shadowsocksPassword16 = base64 .StdEncoding .EncodeToString (passwordBytes [:16 ])
32
34
}
33
35
34
- func testInboundShadowSocks (t * testing.T , inboundOptions inbound.ShadowSocksOption , outboundOptions outbound.ShadowSocksOption ) {
36
+ func testInboundShadowSocks (t * testing.T , inboundOptions inbound.ShadowSocksOption , outboundOptions outbound.ShadowSocksOption , cipherList [] string ) {
35
37
t .Parallel ()
36
- for _ , cipher := range shadowsocksCipherList {
38
+ for _ , cipher := range cipherList {
37
39
cipher := cipher
38
40
t .Run (cipher , func (t * testing.T ) {
39
41
inboundOptions , outboundOptions := inboundOptions , outboundOptions // don't modify outside options value
@@ -94,5 +96,53 @@ func testInboundShadowSocks0(t *testing.T, inboundOptions inbound.ShadowSocksOpt
94
96
func TestInboundShadowSocks_Basic (t * testing.T ) {
95
97
inboundOptions := inbound.ShadowSocksOption {}
96
98
outboundOptions := outbound.ShadowSocksOption {}
97
- testInboundShadowSocks (t , inboundOptions , outboundOptions )
99
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , shadowsocksCipherList )
100
+ }
101
+
102
+ func TestInboundShadowSocks_ShadowTlsv1 (t * testing.T ) {
103
+ inboundOptions := inbound.ShadowSocksOption {
104
+ ShadowTLS : inbound.ShadowTLS {
105
+ Enable : true ,
106
+ Version : 1 ,
107
+ Handshake : inbound.ShadowTLSHandshakeOptions {Dest : net .JoinHostPort (realityDest , "443" )},
108
+ },
109
+ }
110
+ outboundOptions := outbound.ShadowSocksOption {
111
+ Plugin : shadowtls .Mode ,
112
+ PluginOpts : map [string ]any {"host" : realityDest , "fingerprint" : tlsFingerprint , "version" : 1 },
113
+ }
114
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , []string {shadowsocks .MethodNone })
115
+ }
116
+
117
+ func TestInboundShadowSocks_ShadowTlsv2 (t * testing.T ) {
118
+ inboundOptions := inbound.ShadowSocksOption {
119
+ ShadowTLS : inbound.ShadowTLS {
120
+ Enable : true ,
121
+ Version : 2 ,
122
+ Password : shadowsocksPassword16 ,
123
+ Handshake : inbound.ShadowTLSHandshakeOptions {Dest : net .JoinHostPort (realityDest , "443" )},
124
+ },
125
+ }
126
+ outboundOptions := outbound.ShadowSocksOption {
127
+ Plugin : shadowtls .Mode ,
128
+ PluginOpts : map [string ]any {"host" : realityDest , "password" : shadowsocksPassword16 , "fingerprint" : tlsFingerprint , "version" : 2 },
129
+ }
130
+ 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
131
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , []string {shadowsocks .MethodNone })
132
+ }
133
+
134
+ func TestInboundShadowSocks_ShadowTlsv3 (t * testing.T ) {
135
+ inboundOptions := inbound.ShadowSocksOption {
136
+ ShadowTLS : inbound.ShadowTLS {
137
+ Enable : true ,
138
+ Version : 3 ,
139
+ Users : []inbound.ShadowTLSUser {{Name : "test" , Password : shadowsocksPassword16 }},
140
+ Handshake : inbound.ShadowTLSHandshakeOptions {Dest : net .JoinHostPort (realityDest , "443" )},
141
+ },
142
+ }
143
+ outboundOptions := outbound.ShadowSocksOption {
144
+ Plugin : shadowtls .Mode ,
145
+ PluginOpts : map [string ]any {"host" : realityDest , "password" : shadowsocksPassword16 , "fingerprint" : tlsFingerprint , "version" : 3 },
146
+ }
147
+ testInboundShadowSocks (t , inboundOptions , outboundOptions , []string {shadowsocks .MethodNone })
98
148
}
0 commit comments