mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-05 03:16:03 +03:00
85a1c33709
* Add GetInboundUser in proto * Add get user logic for all existing inbounds * Add inbounduser command * Add option to get all users * Fix shadowsocks2022 config * Fix init users in shadowsocks2022 * Fix copy * Add inbound user count command This api costs much less than get inbound user, could be useful in some case * Update from latest main
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package trojan
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
)
|
|
|
|
// MemoryAccount is an account type converted from Account.
|
|
type MemoryAccount struct {
|
|
Password string
|
|
Key []byte
|
|
}
|
|
|
|
// AsAccount implements protocol.AsAccount.
|
|
func (a *Account) AsAccount() (protocol.Account, error) {
|
|
password := a.GetPassword()
|
|
key := hexSha224(password)
|
|
return &MemoryAccount{
|
|
Password: password,
|
|
Key: key,
|
|
}, nil
|
|
}
|
|
|
|
// Equals implements protocol.Account.Equals().
|
|
func (a *MemoryAccount) Equals(another protocol.Account) bool {
|
|
if account, ok := another.(*MemoryAccount); ok {
|
|
return a.Password == account.Password
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (a *MemoryAccount) ToProto() proto.Message {
|
|
return &Account{
|
|
Password: a.Password,
|
|
}
|
|
}
|
|
|
|
func hexSha224(password string) []byte {
|
|
buf := make([]byte, 56)
|
|
hash := sha256.New224()
|
|
common.Must2(hash.Write([]byte(password)))
|
|
hex.Encode(buf, hash.Sum(nil))
|
|
return buf
|
|
}
|
|
|
|
func hexString(data []byte) string {
|
|
str := ""
|
|
for _, v := range data {
|
|
str += fmt.Sprintf("%02x", v)
|
|
}
|
|
return str
|
|
}
|