mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 18:08:14 -05:00
Merge pull request #61 from cubemaze/fix_ss2022
fix: ss2022 keyLength match
This commit is contained in:
commit
301169182d
@ -77,6 +77,47 @@ func BuildTrojanUser(tag string, userInfo *panel.UserInfo) (user *protocol.User)
|
||||
Account: serial.ToTypedMessage(trojanAccount),
|
||||
}
|
||||
}
|
||||
func BuildSSUsers(tag string, userInfo []panel.UserInfo, cypher string, serverKey string) (users []*protocol.User) {
|
||||
users = make([]*protocol.User, len(userInfo))
|
||||
for i := range userInfo {
|
||||
users[i] = BuildSSUser(tag, &userInfo[i], cypher, serverKey)
|
||||
}
|
||||
return users
|
||||
}
|
||||
|
||||
func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey string) (user *protocol.User) {
|
||||
if serverKey == "" {
|
||||
ssAccount := &shadowsocks.Account{
|
||||
Password: userInfo.Uuid,
|
||||
CipherType: getCipherFromString(cypher),
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: tag,
|
||||
Account: serial.ToTypedMessage(ssAccount),
|
||||
}
|
||||
} else {
|
||||
var keyLength int
|
||||
switch cypher {
|
||||
case "2022-blake3-aes-128-gcm":
|
||||
keyLength = 16
|
||||
case "2022-blake3-aes-256-gcm":
|
||||
keyLength = 32
|
||||
}
|
||||
ssAccount := &shadowsocks_2022.User{
|
||||
Key: base64.StdEncoding.EncodeToString([]byte(userInfo.Uuid[:keyLength])),
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: tag,
|
||||
Account: serial.ToTypedMessage(ssAccount),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BuildUserTag(tag string, user *panel.UserInfo) string {
|
||||
return fmt.Sprintf("%s|%s|%d", tag, user.Uuid, user.Id)
|
||||
}
|
||||
|
||||
func getCipherFromString(c string) shadowsocks.CipherType {
|
||||
switch strings.ToLower(c) {
|
||||
@ -92,38 +133,3 @@ func getCipherFromString(c string) shadowsocks.CipherType {
|
||||
return shadowsocks.CipherType_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
func BuildSSUsers(tag string, userInfo []panel.UserInfo, cypher shadowsocks.CipherType, serverKey string) (users []*protocol.User) {
|
||||
users = make([]*protocol.User, len(userInfo))
|
||||
for i := range userInfo {
|
||||
users[i] = BuildSSUser(tag, &userInfo[i], cypher, serverKey)
|
||||
}
|
||||
return users
|
||||
}
|
||||
|
||||
func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher shadowsocks.CipherType, serverKey string) (user *protocol.User) {
|
||||
if serverKey == "" {
|
||||
ssAccount := &shadowsocks.Account{
|
||||
Password: userInfo.Uuid,
|
||||
CipherType: cypher,
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: tag,
|
||||
Account: serial.ToTypedMessage(ssAccount),
|
||||
}
|
||||
} else {
|
||||
ssAccount := &shadowsocks_2022.User{
|
||||
Key: base64.StdEncoding.EncodeToString([]byte(userInfo.Uuid[:32])),
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: tag,
|
||||
Account: serial.ToTypedMessage(ssAccount),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BuildUserTag(tag string, user *panel.UserInfo) string {
|
||||
return fmt.Sprintf("%s|%s|%d", tag, user.Uuid, user.Id)
|
||||
}
|
||||
|
19
core/user.go
19
core/user.go
@ -8,8 +8,6 @@ import (
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/proxy"
|
||||
"github.com/xtls/xray-core/proxy/shadowsocks"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *Core) GetUserManager(tag string) (proxy.UserManager, error) {
|
||||
@ -86,7 +84,7 @@ func (c *Core) AddUsers(p *AddUsersParams) (added int, err error) {
|
||||
case "shadowsocks":
|
||||
users = builder.BuildSSUsers(p.Tag,
|
||||
p.UserInfo,
|
||||
getCipherFromString(p.NodeInfo.Cipher),
|
||||
p.NodeInfo.Cipher,
|
||||
p.NodeInfo.ServerKey)
|
||||
default:
|
||||
return 0, fmt.Errorf("unsupported node type: %s", p.NodeInfo.NodeType)
|
||||
@ -107,18 +105,3 @@ func (c *Core) AddUsers(p *AddUsersParams) (added int, err error) {
|
||||
}
|
||||
return len(users), nil
|
||||
}
|
||||
|
||||
func getCipherFromString(c string) shadowsocks.CipherType {
|
||||
switch strings.ToLower(c) {
|
||||
case "aes-128-gcm", "aead_aes_128_gcm":
|
||||
return shadowsocks.CipherType_AES_128_GCM
|
||||
case "aes-256-gcm", "aead_aes_256_gcm":
|
||||
return shadowsocks.CipherType_AES_256_GCM
|
||||
case "chacha20-poly1305", "aead_chacha20_poly1305", "chacha20-ietf-poly1305":
|
||||
return shadowsocks.CipherType_CHACHA20_POLY1305
|
||||
case "none", "plain":
|
||||
return shadowsocks.CipherType_NONE
|
||||
default:
|
||||
return shadowsocks.CipherType_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user