vless,vmess: support string to uuid mapping standard

This commit is contained in:
nadoo committed 2021-08-08 00:05:47 +08:00
1 parent 926b364400
commit aae2fc8256
5 files changed
+33 -10

No files matched your search

+12 -1
View File
@@ -3,6 +3,7 @@ package vmess
import (
"bytes"
"crypto/md5"
"crypto/sha1"
"encoding/binary"
"encoding/hex"
"errors"
@@ -53,8 +54,17 @@ func (u *User) GenAlterIDUsers(alterID int) []*User {
}
// StrToUUID converts string to uuid.
// s fomat: "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
func StrToUUID(s string) (uuid [16]byte, err error) {
if len(s) >= 1 && len(s) <= 30 {
h := sha1.New()
h.Write(uuid[:])
h.Write([]byte(s))
u := h.Sum(nil)[:16]
u[6] = (u[6] & 0x0f) | (5 << 4)
u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
copy(uuid[:], u)
return
}
b := []byte(strings.Replace(s, "-", "", -1))
if len(b) != 32 {
return uuid, errors.New("invalid UUID: " + s)
@@ -63,6 +73,7 @@ func StrToUUID(s string) (uuid [16]byte, err error) {
return
}
// GetKey returns the key of AES-128-CFB encrypter.
// Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))
func GetKey(uuid [16]byte) []byte {