From 157918859f9ac9cdee9a2fb5c20a38e1bf1b19b9 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Tue, 12 Jan 2021 11:31:02 +0000 Subject: [PATCH] Add pre-checking conversion for VLESS & VMess UUID https://github.com/XTLS/Xray-core/issues/158 --- infra/conf/vless.go | 13 +++++++++++++ infra/conf/vmess.go | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/infra/conf/vless.go b/infra/conf/vless.go index 88ff1c1b..22e5645f 100644 --- a/infra/conf/vless.go +++ b/infra/conf/vless.go @@ -11,6 +11,7 @@ import ( "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/serial" + "github.com/xtls/xray-core/common/uuid" "github.com/xtls/xray-core/proxy/vless" "github.com/xtls/xray-core/proxy/vless/inbound" "github.com/xtls/xray-core/proxy/vless/outbound" @@ -45,6 +46,12 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) { return nil, newError(`VLESS clients: invalid user`).Base(err) } + u, err := uuid.ParseString(account.Id) + if err != nil { + return nil, err + } + account.Id = u.String() + switch account.Flow { case "", "xtls-rprx-origin", "xtls-rprx-direct": case "xtls-rprx-splice": @@ -167,6 +174,12 @@ func (c *VLessOutboundConfig) Build() (proto.Message, error) { return nil, newError(`VLESS users: invalid user`).Base(err) } + u, err := uuid.ParseString(account.Id) + if err != nil { + return nil, err + } + account.Id = u.String() + switch account.Flow { case "", "xtls-rprx-origin", "xtls-rprx-origin-udp443", "xtls-rprx-direct", "xtls-rprx-direct-udp443": case "xtls-rprx-splice", "xtls-rprx-splice-udp443": diff --git a/infra/conf/vmess.go b/infra/conf/vmess.go index 56639f1a..a5cac2bf 100644 --- a/infra/conf/vmess.go +++ b/infra/conf/vmess.go @@ -8,6 +8,7 @@ import ( "github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/serial" + "github.com/xtls/xray-core/common/uuid" "github.com/xtls/xray-core/proxy/vmess" "github.com/xtls/xray-core/proxy/vmess/inbound" "github.com/xtls/xray-core/proxy/vmess/outbound" @@ -105,6 +106,13 @@ func (c *VMessInboundConfig) Build() (proto.Message, error) { if err := json.Unmarshal(rawData, account); err != nil { return nil, newError("invalid VMess user").Base(err) } + + u, err := uuid.ParseString(account.ID) + if err != nil { + return nil, err + } + account.ID = u.String() + user.Account = serial.ToTypedMessage(account.Build()) config.User[idx] = user } @@ -149,6 +157,13 @@ func (c *VMessOutboundConfig) Build() (proto.Message, error) { if err := json.Unmarshal(rawUser, account); err != nil { return nil, newError("invalid VMess user").Base(err) } + + u, err := uuid.ParseString(account.ID) + if err != nil { + return nil, err + } + account.ID = u.String() + user.Account = serial.ToTypedMessage(account.Build()) spec.User = append(spec.User, user) }