mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-26 17:03:02 +00:00
Support for VLESS & VMess UUID v5 mapping standard
https://github.com/XTLS/Xray-core/issues/158
This commit is contained in:
parent
96adf3fbca
commit
40271c09a0
@ -3,6 +3,7 @@ package uuid // import "github.com/xtls/xray-core/common/uuid"
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
@ -67,9 +68,19 @@ func ParseString(str string) (UUID, error) {
|
|||||||
var uuid UUID
|
var uuid UUID
|
||||||
|
|
||||||
text := []byte(str)
|
text := []byte(str)
|
||||||
if len(text) < 32 {
|
if l := len(text); l < 32 || l > 36 {
|
||||||
|
if l == 0 || l > 30 {
|
||||||
return uuid, errors.New("invalid UUID: ", str)
|
return uuid, errors.New("invalid UUID: ", str)
|
||||||
}
|
}
|
||||||
|
h := sha1.New()
|
||||||
|
h.Write(uuid[:])
|
||||||
|
h.Write(text)
|
||||||
|
u := h.Sum(nil)[:16]
|
||||||
|
u[6] = (u[6] & 0x0f) | (5 << 4)
|
||||||
|
u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
|
||||||
|
copy(uuid[:], u)
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
|
|
||||||
b := uuid.Bytes()
|
b := uuid.Bytes()
|
||||||
|
|
||||||
|
@ -35,9 +35,10 @@ func TestParseString(t *testing.T) {
|
|||||||
t.Fatal(r)
|
t.Fatal(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ParseString("2418d087")
|
u0, _ := ParseString("example")
|
||||||
if err == nil {
|
u5, _ := ParseString("feb54431-301b-52bb-a6dd-e1e93e81bb9e")
|
||||||
t.Fatal("Expect error but nil")
|
if r := cmp.Diff(u0, u5); r != "" {
|
||||||
|
t.Fatal(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ParseString("2418d087-648k-4990-86e8-19dca1d006d3")
|
_, err = ParseString("2418d087-648k-4990-86e8-19dca1d006d3")
|
||||||
|
Loading…
Reference in New Issue
Block a user