From 0777cc8892080c218632b308abf8a09a77f03fa0 Mon Sep 17 00:00:00 2001 From: Senis John Date: Fri, 16 Dec 2022 20:43:38 +0800 Subject: [PATCH] update: add ss plugin support ss2022 The error message will have more details --- api/newV2board/v2board.go | 2 +- service/controller/userbuilder.go | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/api/newV2board/v2board.go b/api/newV2board/v2board.go index edd14c8..ab9610f 100644 --- a/api/newV2board/v2board.go +++ b/api/newV2board/v2board.go @@ -217,7 +217,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) { if c.SpeedLimit > 0 { u.SpeedLimit = uint64(c.SpeedLimit * 1000000 / 8) } else { - u.SpeedLimit = uint64(user.Get("speed_limit").MustUint64() * 1000000 / 8) + u.SpeedLimit = user.Get("speed_limit").MustUint64() * 1000000 / 8 } u.DeviceLimit = c.DeviceLimit // todo waiting v2board send configuration diff --git a/service/controller/userbuilder.go b/service/controller/userbuilder.go index 9529941..2969bf0 100644 --- a/service/controller/userbuilder.go +++ b/service/controller/userbuilder.go @@ -78,18 +78,18 @@ func (c *Controller) buildSSUser(userInfo *[]api.UserInfo, method string) (users users = make([]*protocol.User, len(*userInfo)) for i, user := range *userInfo { - // // shadowsocks2022 Key = "openssl rand -base64 32" and multi users needn't cipher method + // shadowsocks2022 Key = "openssl rand -base64 32" and multi users needn't cipher method if C.Contains(shadowaead_2022.List, strings.ToLower(method)) { e := c.buildUserTag(&user) if len(user.Passwd) < 16 { - newError("shadowsocks2022 key's length must be greater than 16").AtError().WriteToLog() - return + newError(fmt.Errorf("[UID: %d] shadowsocks2022 key's length must be greater than 16", user.UID)).AtError().WriteToLog() + continue } userKey := user.Passwd[:16] if strings.Contains(method, "256") { if len(user.Passwd) < 32 { - newError("shadowsocks2022 key's length must be greater than 32").AtError().WriteToLog() - return + newError(fmt.Errorf("[UID: %d] shadowsocks2022 key's length must be greater than 32", user.UID)).AtError().WriteToLog() + continue } userKey = user.Passwd[:32] } @@ -123,11 +123,23 @@ func (c *Controller) buildSSPluginUser(userInfo *[]api.UserInfo) (users []*proto // shadowsocks2022 Key = openssl rand -base64 32 and multi users needn't cipher method if C.Contains(shadowaead_2022.List, strings.ToLower(user.Method)) { e := c.buildUserTag(&user) + if len(user.Passwd) < 16 { + newError(fmt.Errorf("[UID: %d] shadowsocks2022 key's length must be greater than 16", user.UID)).AtError().WriteToLog() + continue + } + userKey := user.Passwd[:16] + if strings.Contains(user.Method, "256") { + if len(user.Passwd) < 32 { + newError(fmt.Errorf("[UID: %d] shadowsocks2022 key's length must be greater than 32", user.UID)).AtError().WriteToLog() + continue + } + userKey = user.Passwd[:32] + } users[i] = &protocol.User{ Level: 0, Email: e, Account: serial.ToTypedMessage(&shadowsocks_2022.User{ - Key: base64.StdEncoding.EncodeToString([]byte(user.Passwd)), + Key: base64.StdEncoding.EncodeToString([]byte(userKey)), Email: e, Level: 0, }),