From 927c5337621a74225db6032282e6a831fec376b7 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 10 Jan 2023 21:55:36 +0800 Subject: [PATCH] chore: ss2022 converter method verify --- common/convert/converter.go | 12 +++++++++--- common/convert/util.go | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/common/convert/converter.go b/common/convert/converter.go index 07b10367..89b4d95f 100644 --- a/common/convert/converter.go +++ b/common/convert/converter.go @@ -268,16 +268,22 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { } var ( - cipher = urlSS.User.Username() - password string + cipherRaw = urlSS.User.Username() + cipher string + password string ) if password, found = urlSS.User.Password(); !found { - dcBuf, _ := encRaw.DecodeString(cipher) + dcBuf, _ := enc.DecodeString(cipherRaw) cipher, password, found = strings.Cut(string(dcBuf), ":") if !found { continue } + err := VerifyMethod(cipher, password) + if err != nil { + dcBuf, _ := encRaw.DecodeString(cipherRaw) + cipher, password, found = strings.Cut(string(dcBuf), ":") + } } ss := make(map[string]any, 10) diff --git a/common/convert/util.go b/common/convert/util.go index b3bd6e5b..03a48ecd 100644 --- a/common/convert/util.go +++ b/common/convert/util.go @@ -2,6 +2,7 @@ package convert import ( "encoding/base64" + "github.com/metacubex/sing-shadowsocks/shadowimpl" "math/rand" "net/http" "strings" @@ -314,3 +315,8 @@ func SetUserAgent(header http.Header) { userAgent := RandUserAgent() header.Set("User-Agent", userAgent) } + +func VerifyMethod(cipher, password string) (err error) { + _, err = shadowimpl.FetchMethod(cipher, password) + return +}