Skip to content

Commit

Permalink
new: update to singbox 1.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jan 21, 2024
1 parent 2fe80df commit c669aba
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 68 deletions.
5 changes: 1 addition & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"os"
"time"

"github.com/sagernet/sing-box/log"

"github.com/spf13/cobra"
Expand All @@ -30,6 +27,6 @@ func main() {

func preRun(cmd *cobra.Command, args []string) {
if disableColor {
log.SetStdLogger(log.NewFactory(log.Formatter{BaseTime: time.Now(), DisableColors: true}, os.Stderr, nil).Logger())
// log.SetStdLogger(log.NewFactory(log.Formatter{BaseTime: time.Now(), DisableColors: true}, os.Stderr, nil).Logger())
}
}
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/hiddify/ray2sing
go 1.21.1

require (
github.com/sagernet/sing v0.2.20
github.com/sagernet/sing v0.3.0
github.com/sagernet/sing-box v1.7.8
github.com/spf13/cobra v1.8.0
)
Expand All @@ -14,10 +14,11 @@ require (
github.com/miekg/dns v1.1.57 // indirect
github.com/sagernet/sing-dns v0.1.12 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.16.0 // indirect
)

replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240113144724-d348f6fa8ff2
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240121092547-68ac7a67eee1
25 changes: 17 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240113144724-d348f6fa8ff2 h1:A67GgwJYIU0EkoCWpivZ39ElcE8o6US93eMxhFlHTrM=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240113144724-d348f6fa8ff2/go.mod h1:cxAxPGP5EAIL5gkgCpx46fkJ/5SUPB3NMCM0wcZAQig=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240121092547-68ac7a67eee1 h1:bzGnAZ2C8SLkra6RsJuU/eGh00I6kmFEm88Kg77QyZo=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240121092547-68ac7a67eee1/go.mod h1:UjYAsVOhYPgx2Yl53iPjIwHOp7HghictAi16Lmi+CZw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagernet/sing v0.2.20 h1:ckcCB/5xu8G8wElNeH74IF6Soac5xWN+eQUXRuonjPQ=
github.com/sagernet/sing v0.2.20/go.mod h1:Ce5LNojQOgOiWhiD8pPD6E9H7e2KgtOe3Zxx4Ou5u80=
github.com/sagernet/sing v0.3.0 h1:PIDVFZHnQAAYRL1UYqNM+0k5s8f/tb1lUW6UDcQiOc8=
github.com/sagernet/sing v0.3.0/go.mod h1:9pfuAH6mZfgnz/YjP6xu5sxx882rfyjpcrTdUpd6w3g=
github.com/sagernet/sing-dns v0.1.12 h1:1HqZ+ln+Rezx/aJMStaS0d7oPeX2EobSV1NT537kyj4=
github.com/sagernet/sing-dns v0.1.12/go.mod h1:rx/DTOisneQpCgNQ4jbFU/JNEtnz0lYcHXenlVzpjEU=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M=
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 5 additions & 3 deletions ray2sing/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

type ParserFunc func(string) (*option.Outbound, error)

func getTLSOptions(decoded map[string]string) *option.OutboundTLSOptions {
func getTLSOptions(decoded map[string]string) T.OutboundTLSOptionsContainer {
if !(decoded["tls"] == "tls" || decoded["security"] == "tls" || decoded["security"] == "reality") {
return nil
return T.OutboundTLSOptionsContainer{TLS: nil}
}

serverName := decoded["sni"]
Expand Down Expand Up @@ -56,8 +56,10 @@ func getTLSOptions(decoded map[string]string) *option.OutboundTLSOptions {
if alpn, ok := decoded["alpn"]; ok && alpn != "" {
tlsOptions.ALPN = strings.Split(alpn, ",")
}
return T.OutboundTLSOptionsContainer{
TLS: tlsOptions,
}

return tlsOptions
}

func getTricksOptions(decoded map[string]string) *option.TLSTricksOptions {
Expand Down
12 changes: 7 additions & 5 deletions ray2sing/hysteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ func HysteriaSingbox(hysteriaURL string) (*T.Outbound, error) {
Tag: u.Name,
HysteriaOptions: T.HysteriaOutboundOptions{
ServerOptions: u.GetServerOption(),
TLS: &T.OutboundTLSOptions{
Enabled: true,
DisableSNI: isIPOnly(SNI),
ServerName: SNI,
Insecure: u.Params["insecure"] == "1",
OutboundTLSOptionsContainer: T.OutboundTLSOptionsContainer{
TLS: &T.OutboundTLSOptions{
Enabled: true,
DisableSNI: isIPOnly(SNI),
ServerName: SNI,
Insecure: u.Params["insecure"] == "1",
},
},
},
}
Expand Down
14 changes: 8 additions & 6 deletions ray2sing/hysteria2.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ func Hysteria2Singbox(hysteria2Url string) (*T.Outbound, error) {
ServerOptions: u.GetServerOption(),
Obfs: ObfsOpts,
Password: u.Username,
TLS: &T.OutboundTLSOptions{
Enabled: true,
Insecure: decoded["insecure"] == "1",
DisableSNI: isIPOnly(SNI),
ServerName: SNI,
ECH: ECHOpts,
OutboundTLSOptionsContainer: T.OutboundTLSOptionsContainer{
TLS: &T.OutboundTLSOptions{
Enabled: true,
Insecure: decoded["insecure"] == "1",
DisableSNI: isIPOnly(SNI),
ServerName: SNI,
ECH: ECHOpts,
},
},
TurnRelay: turnRelay,
},
Expand Down
12 changes: 6 additions & 6 deletions ray2sing/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func TrojanSingbox(trojanURL string) (*T.Outbound, error) {
Tag: u.Name,
Type: "trojan",
TrojanOptions: T.TrojanOutboundOptions{
DialerOptions: getDialerOptions(decoded),
ServerOptions: u.GetServerOption(),
Password: u.Username,
TLS: getTLSOptions(decoded),
Transport: transportOptions,
Multiplex: getMuxOptions(decoded),
DialerOptions: getDialerOptions(decoded),
ServerOptions: u.GetServerOption(),
Password: u.Username,
OutboundTLSOptionsContainer: getTLSOptions(decoded),
Transport: transportOptions,
Multiplex: getMuxOptions(decoded),
},
}, nil
}
16 changes: 9 additions & 7 deletions ray2sing/tuic.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ func TuicSingbox(tuicUrl string) (*T.Outbound, error) {
UDPRelayMode: decoded["udp_relay_mode"],
ZeroRTTHandshake: false,
Heartbeat: T.Duration(10 * time.Second),
TLS: &T.OutboundTLSOptions{
Enabled: true,
DisableSNI: decoded["sni"] == "",
ServerName: decoded["sni"],
Insecure: decoded["allow_insecure"] == "1",
ALPN: []string{"h3", "spdy/3.1"},
ECH: ECHOpts,
OutboundTLSOptionsContainer: T.OutboundTLSOptionsContainer{
TLS: &T.OutboundTLSOptions{
Enabled: true,
DisableSNI: decoded["sni"] == "",
ServerName: decoded["sni"],
Insecure: decoded["allow_insecure"] == "1",
ALPN: []string{"h3", "spdy/3.1"},
ECH: ECHOpts,
},
},
TurnRelay: turnRelay,
},
Expand Down
20 changes: 10 additions & 10 deletions ray2sing/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func VlessSingbox(vlessURL string) (*T.Outbound, error) {
}

tlsOptions := getTLSOptions(decoded)
if tlsOptions != nil {
if tlsOptions.TLS != nil {
if security := decoded["security"]; security == "reality" {
tlsOptions.Reality = &T.OutboundRealityOptions{
tlsOptions.TLS.Reality = &T.OutboundRealityOptions{
Enabled: true,
PublicKey: decoded["pbk"],
ShortID: decoded["sid"],
Expand All @@ -36,14 +36,14 @@ func VlessSingbox(vlessURL string) (*T.Outbound, error) {
Tag: u.Name,
Type: "vless",
VLESSOptions: T.VLESSOutboundOptions{
DialerOptions: getDialerOptions(decoded),
ServerOptions: u.GetServerOption(),
UUID: u.Username,
PacketEncoding: &packetEncoding,
Flow: decoded["flow"],
TLS: tlsOptions,
Transport: transportOptions,
Multiplex: getMuxOptions(decoded),
DialerOptions: getDialerOptions(decoded),
ServerOptions: u.GetServerOption(),
UUID: u.Username,
PacketEncoding: &packetEncoding,
Flow: decoded["flow"],
OutboundTLSOptionsContainer: tlsOptions,
Transport: transportOptions,
Multiplex: getMuxOptions(decoded),
},
}, nil
}
18 changes: 9 additions & 9 deletions ray2sing/vmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ func VmessSingbox(vmessURL string) (*T.Outbound, error) {
Server: decoded["add"],
ServerPort: port,
},
UUID: decoded["id"],
Security: security,
AlterId: toInt(decoded["aid"]),
GlobalPadding: false,
AuthenticatedLength: true,
PacketEncoding: packetEncoding,
TLS: getTLSOptions(decoded),
Transport: transportOptions,
Multiplex: getMuxOptions(decoded),
UUID: decoded["id"],
Security: security,
AlterId: toInt(decoded["aid"]),
GlobalPadding: false,
AuthenticatedLength: true,
PacketEncoding: packetEncoding,
OutboundTLSOptionsContainer: getTLSOptions(decoded),
Transport: transportOptions,
Multiplex: getMuxOptions(decoded),
},
}, nil
}
1 change: 0 additions & 1 deletion ray2sing_test/trojan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestTrojan(t *testing.T) {
"tls": {
"enabled": true,
"server_name": "aws-ar-buenosaires-1.f1cflineb.com",
"insecure": true,
"utls": {
"enabled": true,
"fingerprint": "chrome"
Expand Down
6 changes: 3 additions & 3 deletions ray2sing_test/vless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ func TestVless(t *testing.T) {
"tls": {
"enabled": true,
"server_name": "vless.229feb8b52a0e7e117ea76f8b591bcb3.workers.dev",
"insecure": true,
"utls": {
"enabled": true,
"fingerprint": "chrome"
}
},
"transport": {
"type": "ws",
"path": "/?ed=2048",
"path": "/",
"headers": {
"Host": "vless.229feb8b52a0e7e117ea76f8b591bcb3.workers.dev"
},
"max_early_data": 2048,
"early_data_header_name": "Sec-WebSocket-Protocol"
},
"packet_encoding": "xudp"
"packet_encoding": ""
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions ray2sing_test/vmess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func TestVmess(t *testing.T) {
"server_port": 8080,
"uuid": "d43ee5e3-1b07-56d7-b2ea-8d22c44fdc66",
"security": "chacha20-poly1305",
"authenticated_length": true,
"packet_encoding": "xudp"
"authenticated_length": true
}
]
}
Expand Down

0 comments on commit c669aba

Please sign in to comment.