mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
mv builder to xray
This commit is contained in:
65
core/xray/ss.go
Normal file
65
core/xray/ss.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package xray
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
"github.com/Yuzuki616/V2bX/common/format"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/serial"
|
||||
"github.com/xtls/xray-core/proxy/shadowsocks"
|
||||
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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: format.UserTag(tag, userInfo.Uuid),
|
||||
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: format.UserTag(tag, userInfo.Uuid),
|
||||
Account: serial.ToTypedMessage(ssAccount),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user