Skip to content

Commit 48c65a2

Browse files
macronutnekohasekai
authored andcommitted
Add more spoof method
Signed-off-by: macronut <4027187+macronut@users.noreply.github.com>
1 parent 772ab58 commit 48c65a2

22 files changed

Lines changed: 362 additions & 1023 deletions

adapter/inbound.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/netip"
77
"time"
88

9+
"github.com/sagernet/sing-box/common/tlsspoof"
910
C "github.com/sagernet/sing-box/constant"
1011
"github.com/sagernet/sing-box/log"
1112
"github.com/sagernet/sing-box/option"
@@ -75,6 +76,8 @@ type InboundContext struct {
7576
TLSFragment bool
7677
TLSFragmentFallbackDelay time.Duration
7778
TLSRecordFragment bool
79+
TLSSpoof string
80+
TLSSpoofMethod tlsspoof.Method
7881

7982
NetworkStrategy *C.NetworkStrategy
8083
NetworkType []C.InterfaceType

common/tls/client.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,20 @@ import (
2222
var errMissingServerName = E.New("missing server_name or insecure=true")
2323

2424
func parseTLSSpoofOptions(serverName string, options option.OutboundTLSOptions) (string, tlsspoof.Method, error) {
25-
if options.Spoof == "" {
26-
if options.SpoofMethod != "" {
27-
return "", 0, E.New("`spoof_method` requires `spoof`")
28-
}
29-
return "", 0, nil
25+
spoof, method, err := tlsspoof.ParseOptions(options.Spoof, options.SpoofMethod)
26+
if err != nil {
27+
return "", 0, err
3028
}
31-
if !tlsspoof.PlatformSupported {
32-
return "", 0, E.New("`spoof` is not supported on this platform")
29+
if spoof == "" {
30+
return "", 0, nil
3331
}
3432
if options.DisableSNI || serverName == "" || M.ParseAddr(serverName).IsValid() {
3533
return "", 0, E.New("`spoof` requires TLS ClientHello with SNI")
3634
}
37-
if strings.EqualFold(options.Spoof, serverName) {
35+
if strings.EqualFold(spoof, serverName) {
3836
return "", 0, E.New("`spoof` must differ from `server_name`")
3937
}
40-
method, err := tlsspoof.ParseMethod(options.SpoofMethod)
41-
if err != nil {
42-
return "", 0, err
43-
}
44-
return options.Spoof, method, nil
38+
return spoof, method, nil
4539
}
4640

4741
func applyTLSSpoof(conn net.Conn, spoof string, method tlsspoof.Method) (net.Conn, error) {

common/tls/client_test.go

Lines changed: 0 additions & 154 deletions
This file was deleted.

common/tlsspoof/client_hello_test.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)