mirror of
https://github.com/bestnite/sub2sing-box.git
synced 2026-05-19 14:37:32 +00:00
try to fix ss parser
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
* text=auto eol=lf
|
||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+30
-27
@@ -15,7 +15,6 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
|||||||
if !strings.HasPrefix(proxy, constant.ShadowsocksPrefix) {
|
if !strings.HasPrefix(proxy, constant.ShadowsocksPrefix) {
|
||||||
return model.Outbound{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
|
return model.Outbound{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
|
||||||
}
|
}
|
||||||
needDecode := true
|
|
||||||
if !strings.Contains(proxy, "@") {
|
if !strings.Contains(proxy, "@") {
|
||||||
s := strings.SplitN(proxy, "#", 2)
|
s := strings.SplitN(proxy, "#", 2)
|
||||||
d, err := util.DecodeBase64(strings.TrimPrefix(s[0], "ss://"))
|
d, err := util.DecodeBase64(strings.TrimPrefix(s[0], "ss://"))
|
||||||
@@ -31,7 +30,6 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
|||||||
} else {
|
} else {
|
||||||
proxy = "ss://" + d
|
proxy = "ss://" + d
|
||||||
}
|
}
|
||||||
needDecode = false
|
|
||||||
}
|
}
|
||||||
link, err := url.Parse(proxy)
|
link, err := url.Parse(proxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -67,37 +65,28 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
method := ""
|
method := link.User.Username()
|
||||||
password := ""
|
password, _ := link.User.Password()
|
||||||
if needDecode {
|
|
||||||
user, err := util.DecodeBase64(link.User.Username())
|
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 {
|
if err != nil {
|
||||||
return model.Outbound{}, &ParseError{
|
return model.Outbound{}, &ParseError{
|
||||||
Type: ErrInvalidStruct,
|
Type: ErrInvalidStruct,
|
||||||
Message: "missing method and password",
|
Message: "password decode error",
|
||||||
Raw: proxy,
|
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()
|
query := link.Query()
|
||||||
@@ -136,3 +125,17 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
|||||||
}
|
}
|
||||||
return result, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user