mirror of
https://github.com/nitezs/sub2sing-box.git
synced 2025-04-03 03:23:44 +08:00
try to fix ss parser
This commit is contained in:
parent
c402431bb3
commit
b36bfa84a6
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
0
.github/workflows/docker.yml
vendored
Normal file → Executable file
0
.github/workflows/docker.yml
vendored
Normal file → Executable file
0
.github/workflows/release.yml
vendored
Normal file → Executable file
0
.github/workflows/release.yml
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.goreleaser.yaml
Normal file → Executable file
0
.goreleaser.yaml
Normal file → Executable file
0
.vscode/tasks.json
vendored
Normal file → Executable file
0
.vscode/tasks.json
vendored
Normal file → Executable file
0
Dockerfile
Normal file → Executable file
0
Dockerfile
Normal file → Executable file
0
api/handler/convert.go
Normal file → Executable file
0
api/handler/convert.go
Normal file → Executable file
0
api/server.go
Normal file → Executable file
0
api/server.go
Normal file → Executable file
0
api/static/index.html
Normal file → Executable file
0
api/static/index.html
Normal file → Executable file
0
cmd/convert.go
Normal file → Executable file
0
cmd/convert.go
Normal file → Executable file
0
cmd/root.go
Normal file → Executable file
0
cmd/root.go
Normal file → Executable file
0
cmd/server.go
Normal file → Executable file
0
cmd/server.go
Normal file → Executable file
0
cmd/version.go
Normal file → Executable file
0
cmd/version.go
Normal file → Executable file
0
common/convert.go
Normal file → Executable file
0
common/convert.go
Normal file → Executable file
0
constant/placeholder.go
Normal file → Executable file
0
constant/placeholder.go
Normal file → Executable file
0
constant/prefix.go
Normal file → Executable file
0
constant/prefix.go
Normal file → Executable file
0
constant/proxy.go
Normal file → Executable file
0
constant/proxy.go
Normal file → Executable file
0
constant/version.go
Normal file → Executable file
0
constant/version.go
Normal file → Executable file
0
docker-compose.yaml
Normal file → Executable file
0
docker-compose.yaml
Normal file → Executable file
0
model/convert.go
Normal file → Executable file
0
model/convert.go
Normal file → Executable file
0
model/country_code_map.go
Normal file → Executable file
0
model/country_code_map.go
Normal file → Executable file
0
model/option.go
Normal file → Executable file
0
model/option.go
Normal file → Executable file
0
model/outbound.go
Normal file → Executable file
0
model/outbound.go
Normal file → Executable file
0
model/sort.go
Normal file → Executable file
0
model/sort.go
Normal file → Executable file
0
model/vmess.go
Normal file → Executable file
0
model/vmess.go
Normal file → Executable file
0
parser/error.go
Normal file → Executable file
0
parser/error.go
Normal file → Executable file
0
parser/hysteria.go
Normal file → Executable file
0
parser/hysteria.go
Normal file → Executable file
0
parser/hysteria2.go
Normal file → Executable file
0
parser/hysteria2.go
Normal file → Executable file
0
parser/parsers_map.go
Normal file → Executable file
0
parser/parsers_map.go
Normal file → Executable file
0
parser/port.go
Normal file → Executable file
0
parser/port.go
Normal file → Executable file
57
parser/shadowsocks.go
Normal file → Executable file
57
parser/shadowsocks.go
Normal file → Executable file
@ -15,7 +15,6 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, constant.ShadowsocksPrefix) {
|
||||
return model.Outbound{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
|
||||
}
|
||||
needDecode := true
|
||||
if !strings.Contains(proxy, "@") {
|
||||
s := strings.SplitN(proxy, "#", 2)
|
||||
d, err := util.DecodeBase64(strings.TrimPrefix(s[0], "ss://"))
|
||||
@ -31,7 +30,6 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
||||
} else {
|
||||
proxy = "ss://" + d
|
||||
}
|
||||
needDecode = false
|
||||
}
|
||||
link, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
@ -67,37 +65,28 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
||||
}
|
||||
}
|
||||
|
||||
method := ""
|
||||
password := ""
|
||||
if needDecode {
|
||||
user, err := util.DecodeBase64(link.User.Username())
|
||||
method := link.User.Username()
|
||||
password, _ := link.User.Password()
|
||||
|
||||
if password == "" {
|
||||
user, err := util.DecodeBase64(method)
|
||||
if err == nil {
|
||||
methodAndPass := strings.SplitN(user, ":", 2)
|
||||
if len(methodAndPass) == 2 {
|
||||
method = methodAndPass[0]
|
||||
password = methodAndPass[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
if isLikelyBase64(password) {
|
||||
password, err = util.DecodeBase64(password)
|
||||
if err != nil {
|
||||
return model.Outbound{}, &ParseError{
|
||||
Type: ErrInvalidStruct,
|
||||
Message: "missing method and password",
|
||||
Message: "password decode error",
|
||||
Raw: proxy,
|
||||
}
|
||||
}
|
||||
if user == "" {
|
||||
return model.Outbound{}, &ParseError{
|
||||
Type: ErrInvalidStruct,
|
||||
Message: "missing method and password",
|
||||
Raw: proxy,
|
||||
}
|
||||
}
|
||||
methodAndPass := strings.SplitN(user, ":", 2)
|
||||
if len(methodAndPass) != 2 {
|
||||
return model.Outbound{}, &ParseError{
|
||||
Type: ErrInvalidStruct,
|
||||
Message: "missing method and password",
|
||||
Raw: proxy,
|
||||
}
|
||||
}
|
||||
method = methodAndPass[0]
|
||||
password = methodAndPass[1]
|
||||
} else {
|
||||
method = link.User.Username()
|
||||
password, _ = link.User.Password()
|
||||
}
|
||||
|
||||
query := link.Query()
|
||||
@ -136,3 +125,17 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func isLikelyBase64(s string) bool {
|
||||
if len(s)%4 == 0 && strings.HasSuffix(s, "=") && !strings.Contains(strings.TrimSuffix(s, "="), "=") {
|
||||
s = strings.TrimSuffix(s, "=")
|
||||
chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
for _, c := range s {
|
||||
if !strings.ContainsRune(chars, c) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
0
parser/trojan.go
Normal file → Executable file
0
parser/trojan.go
Normal file → Executable file
0
parser/vless.go
Normal file → Executable file
0
parser/vless.go
Normal file → Executable file
0
parser/vmess.go
Normal file → Executable file
0
parser/vmess.go
Normal file → Executable file
0
templates/android/dns.json
Normal file → Executable file
0
templates/android/dns.json
Normal file → Executable file
0
templates/android/experimental.json
Normal file → Executable file
0
templates/android/experimental.json
Normal file → Executable file
0
templates/android/inbounds.json
Normal file → Executable file
0
templates/android/inbounds.json
Normal file → Executable file
0
templates/android/log.json
Normal file → Executable file
0
templates/android/log.json
Normal file → Executable file
0
templates/android/ntp.json
Normal file → Executable file
0
templates/android/ntp.json
Normal file → Executable file
0
templates/android/outbounds.json
Normal file → Executable file
0
templates/android/outbounds.json
Normal file → Executable file
0
templates/android/route.json
Normal file → Executable file
0
templates/android/route.json
Normal file → Executable file
0
templates/android/route_rule_set.json
Normal file → Executable file
0
templates/android/route_rule_set.json
Normal file → Executable file
0
templates/example-android.json
Normal file → Executable file
0
templates/example-android.json
Normal file → Executable file
0
templates/example-linux.json
Normal file → Executable file
0
templates/example-linux.json
Normal file → Executable file
0
templates/example-windows.json
Normal file → Executable file
0
templates/example-windows.json
Normal file → Executable file
0
templates/linux/dns.json
Normal file → Executable file
0
templates/linux/dns.json
Normal file → Executable file
0
templates/linux/experimental.json
Normal file → Executable file
0
templates/linux/experimental.json
Normal file → Executable file
0
templates/linux/inbounds.json
Normal file → Executable file
0
templates/linux/inbounds.json
Normal file → Executable file
0
templates/linux/log.json
Normal file → Executable file
0
templates/linux/log.json
Normal file → Executable file
0
templates/linux/ntp.json
Normal file → Executable file
0
templates/linux/ntp.json
Normal file → Executable file
0
templates/linux/outbounds.json
Normal file → Executable file
0
templates/linux/outbounds.json
Normal file → Executable file
0
templates/linux/route.json
Normal file → Executable file
0
templates/linux/route.json
Normal file → Executable file
0
templates/linux/route_rule_set.json
Normal file → Executable file
0
templates/linux/route_rule_set.json
Normal file → Executable file
0
templates/windows/dns.json
Normal file → Executable file
0
templates/windows/dns.json
Normal file → Executable file
0
templates/windows/experimental.json
Normal file → Executable file
0
templates/windows/experimental.json
Normal file → Executable file
0
templates/windows/inbounds.json
Normal file → Executable file
0
templates/windows/inbounds.json
Normal file → Executable file
0
templates/windows/log.json
Normal file → Executable file
0
templates/windows/log.json
Normal file → Executable file
0
templates/windows/ntp.json
Normal file → Executable file
0
templates/windows/ntp.json
Normal file → Executable file
0
templates/windows/outbounds.json
Normal file → Executable file
0
templates/windows/outbounds.json
Normal file → Executable file
0
templates/windows/route.json
Normal file → Executable file
0
templates/windows/route.json
Normal file → Executable file
0
templates/windows/route_rule_set.json
Normal file → Executable file
0
templates/windows/route_rule_set.json
Normal file → Executable file
0
util/base64.go
Normal file → Executable file
0
util/base64.go
Normal file → Executable file
0
util/fetch.go
Normal file → Executable file
0
util/fetch.go
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user