From 4cfed17650a2aa22346a4aee7aacf3ef6d0c667a Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Thu, 27 Jul 2023 11:34:46 +0330 Subject: [PATCH] [api] fix actions for shadowsocks Co-Authored-By: Alireza Ahmadi --- xray/api.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/xray/api.go b/xray/api.go index 99335076..f39361f2 100644 --- a/xray/api.go +++ b/xray/api.go @@ -15,6 +15,7 @@ import ( "github.com/xtls/xray-core/common/serial" "github.com/xtls/xray-core/infra/conf" "github.com/xtls/xray-core/proxy/shadowsocks" + "github.com/xtls/xray-core/proxy/shadowsocks_2022" "github.com/xtls/xray-core/proxy/trojan" "github.com/xtls/xray-core/proxy/vless" "github.com/xtls/xray-core/proxy/vmess" @@ -99,9 +100,31 @@ func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]in Password: user["password"].(string), }) case "shadowsocks": - account = serial.ToTypedMessage(&shadowsocks.Account{ - Password: user["password"].(string), - }) + var ssCipherType shadowsocks.CipherType + switch user["cipher"].(string) { + case "aes-128-gcm": + ssCipherType = shadowsocks.CipherType_AES_128_GCM + case "aes-256-gcm": + ssCipherType = shadowsocks.CipherType_AES_256_GCM + case "chacha20-poly1305": + ssCipherType = shadowsocks.CipherType_CHACHA20_POLY1305 + case "xchacha20-poly1305": + ssCipherType = shadowsocks.CipherType_XCHACHA20_POLY1305 + default: + ssCipherType = shadowsocks.CipherType_NONE + } + + if ssCipherType != shadowsocks.CipherType_NONE { + account = serial.ToTypedMessage(&shadowsocks.Account{ + Password: user["password"].(string), + CipherType: ssCipherType, + }) + } else { + account = serial.ToTypedMessage(&shadowsocks_2022.User{ + Key: user["password"].(string), + Email: user["email"].(string), + }) + } default: return nil }