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

+11 -1
View File
@@ -1,6 +1,7 @@
package vless
import (
"crypto/sha1"
"encoding/hex"
"errors"
"net/url"
@@ -62,8 +63,17 @@ func NewVLess(s string, d proxy.Dialer, p proxy.Proxy) (*VLess, error) {
}
// 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)