try to fix ss parser

This commit is contained in:
2024-11-06 18:38:59 +08:00
parent c402431bb3
commit b36bfa84a6
69 changed files with 31 additions and 27 deletions

0
parser/error.go Normal file → Executable file
View File

0
parser/hysteria.go Normal file → Executable file
View File

0
parser/hysteria2.go Normal file → Executable file
View File

0
parser/parsers_map.go Normal file → Executable file
View File

0
parser/port.go Normal file → Executable file
View File

57
parser/shadowsocks.go Normal file → Executable file
View 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
View File

0
parser/vless.go Normal file → Executable file
View File

0
parser/vmess.go Normal file → Executable file
View File