fix: bug in padding

This commit is contained in:
Hiddify
2024-01-29 14:21:42 +01:00
parent 19f984f78a
commit c1fe4171cc
6 changed files with 28 additions and 19 deletions

View File

@@ -80,6 +80,8 @@ func build(path string, optionsPath string) error {
return err return err
} }
fmt.Println("result successfully written to ", outputPath) fmt.Println("result successfully written to ", outputPath)
libbox.Setup(outputPath, workingDir, workingDir, true)
instance, err := NewService(*patchedOptions)
} else { } else {
os.Stdout.WriteString(config) os.Stdout.WriteString(config)
} }

View File

@@ -54,16 +54,16 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
ClashAPI: &option.ClashAPIOptions{ ClashAPI: &option.ClashAPIOptions{
ExternalController: fmt.Sprintf("%s:%d", "127.0.0.1", configOpt.ClashApiPort), ExternalController: fmt.Sprintf("%s:%d", "127.0.0.1", configOpt.ClashApiPort),
}, },
CacheFile: &option.CacheFileOptions{ // CacheFile: &option.CacheFileOptions{
Enabled: true, // Enabled: true,
Path: "clash.db", // Path: "clash.db",
}, // },
} }
} }
options.Log = &option.LogOptions{ options.Log = &option.LogOptions{
Level: configOpt.LogLevel, Level: configOpt.LogLevel,
Output: "box.log", // Output: "box.log",
Disabled: false, Disabled: false,
Timestamp: true, Timestamp: true,
DisableColor: true, DisableColor: true,

View File

@@ -98,7 +98,7 @@ func DefaultConfigOptions() *ConfigOptions {
FragmentSleep: "50-200", FragmentSleep: "50-200",
EnableMixedSNICase: false, EnableMixedSNICase: false,
EnablePadding: false, EnablePadding: false,
PaddingSize: "100-200", PaddingSize: "1200-1500",
}, },
} }
} }

View File

@@ -27,6 +27,7 @@ func patchOutboundMux(base option.Outbound, configOpt ConfigOptions, obj outboun
} }
func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap { func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap {
if base.Type == C.TypeSelector || base.Type == C.TypeURLTest || base.Type == C.TypeBlock || base.Type == C.TypeDNS { if base.Type == C.TypeSelector || base.Type == C.TypeURLTest || base.Type == C.TypeBlock || base.Type == C.TypeDNS {
return obj return obj
} }
@@ -54,25 +55,31 @@ func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj o
if tls == nil || !tls.Enabled || transport == nil { if tls == nil || !tls.Enabled || transport == nil {
return obj return obj
} }
if transport.Type != C.V2RayTransportTypeWebsocket && transport.Type != C.V2RayTransportTypeGRPC { if transport.Type != C.V2RayTransportTypeWebsocket && transport.Type != C.V2RayTransportTypeGRPC {
return obj return obj
} }
if tls, ok := obj["tls"].(map[string]interface{}); ok { if outtls, ok := obj["tls"].(map[string]interface{}); ok {
tlsTricks := option.TLSTricksOptions{ tlsTricks := tls.TLSTricks
MixedCaseSNI: configOpt.TLSTricks.EnableMixedSNICase, tlsTricks.MixedCaseSNI = tlsTricks.MixedCaseSNI || configOpt.TLSTricks.EnableMixedSNICase
}
if configOpt.TLSTricks.EnablePadding { if configOpt.TLSTricks.EnablePadding {
tlsTricks.PaddingMode = "random" tlsTricks.PaddingMode = "random"
tlsTricks.PaddingSize = configOpt.TLSTricks.PaddingSize tlsTricks.PaddingSize = configOpt.TLSTricks.PaddingSize
fmt.Printf("--------------------%+v----%+v", tlsTricks.PaddingSize, configOpt)
outtls["utls"] = map[string]interface{}{
"enabled": true,
"fingerprint": "custom",
}
} }
if tlsTricks.MixedCaseSNI || tlsTricks.PaddingMode != "" { outtls["tls_tricks"] = tlsTricks
tls["tls_tricks"] = tlsTricks // if tlsTricks.MixedCaseSNI || tlsTricks.PaddingMode != "" {
// } else { // // } else {
// tls["tls_tricks"] = nil // // tls["tls_tricks"] = nil
} // }
fmt.Printf("-------%+v------------- ", tlsTricks)
} }
return obj return obj
} }

2
go.mod
View File

@@ -102,6 +102,6 @@ require (
lukechampine.com/blake3 v1.2.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect
) )
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240126132136-307f29d4ab05 replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240127031116-46118867804b
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1

4
go.sum
View File

@@ -49,8 +49,8 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240126132136-307f29d4ab05 h1:Lu1VgoEDqQRMsEENwDVs+SMK16hLTie6DI+P8txZLMM= github.com/hiddify/hiddify-sing-box v1.7.9-0.20240127031116-46118867804b h1:5w6woa/tQkXB9kpuIINZTck6pt8u0/4T+RqNOX0e+aI=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240126132136-307f29d4ab05/go.mod h1:B74zKdMcH3ZEmCi2OUqJTvEXCNtNQjivUEQ20y/5XQM= github.com/hiddify/hiddify-sing-box v1.7.9-0.20240127031116-46118867804b/go.mod h1:B74zKdMcH3ZEmCi2OUqJTvEXCNtNQjivUEQ20y/5XQM=
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102 h1:4vKmPE8AyvsBYuZmjGkPnsju8ZzVxEjC9I96uqxX5+o= github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102 h1:4vKmPE8AyvsBYuZmjGkPnsju8ZzVxEjC9I96uqxX5+o=
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA= github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8= github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=