diff --git a/gui/src/components/modalServer.vue b/gui/src/components/modalServer.vue index b7d78f75..eb45a69b 100644 --- a/gui/src/components/modalServer.vue +++ b/gui/src/components/modalServer.vue @@ -757,7 +757,7 @@ export default { ps: decodeURIComponent(u.hash), add: u.host, port: u.port, - id: u.username, + id: decodeURIComponent(u.username), net: u.params.type || "tcp", type: u.params.headerType || "none", host: u.params.sni || u.params.host || "", diff --git a/service/common/crypto.go b/service/common/crypto.go index e504175e..bfbac7bf 100644 --- a/service/common/crypto.go +++ b/service/common/crypto.go @@ -3,9 +3,11 @@ package common import ( "crypto/hmac" "crypto/md5" + "crypto/sha1" "crypto/sha256" "crypto/sha512" "encoding/base64" + "encoding/hex" "fmt" "io" "strings" @@ -51,4 +53,26 @@ func Base64URLDecode(s string) (string, error) { return saver, err } return string(raw), err -} \ No newline at end of file +} + +// StringToUUID5 is from https://github.com/XTLS/Xray-core/issues/158 +func StringToUUID5(str string) string { + var Nil [16]byte + h := sha1.New() + h.Write(Nil[:]) + h.Write([]byte(str)) + u := h.Sum(nil)[:16] + u[6] = (u[6] & 0x0f) | (5 << 4) + u[8] = u[8]&(0xff>>2) | (0x02 << 6) + buf := make([]byte, 36) + hex.Encode(buf[0:8], u[0:4]) + buf[8] = '-' + hex.Encode(buf[9:13], u[4:6]) + buf[13] = '-' + hex.Encode(buf[14:18], u[6:8]) + buf[18] = '-' + hex.Encode(buf[19:23], u[8:10]) + buf[23] = '-' + hex.Encode(buf[24:], u[10:]) + return string(buf) +} diff --git a/service/core/v2ray/v2rayTmpl.go b/service/core/v2ray/v2rayTmpl.go index 89722ec1..676ce5c0 100644 --- a/service/core/v2ray/v2rayTmpl.go +++ b/service/core/v2ray/v2rayTmpl.go @@ -303,6 +303,10 @@ func ResolveOutbound(v *vmessInfo.VmessInfo, tag string, pluginPort *int) (o Out aid, _ := strconv.Atoi(v.Aid) switch strings.ToLower(v.Protocol) { case "vmess", "vless": + id := v.ID + if l := len([]byte(id)); l < 32 || l > 36 { + id = common.StringToUUID5(id) + } switch strings.ToLower(v.Protocol) { case "vmess": o.Settings.Vnext = []Vnext{ @@ -311,7 +315,7 @@ func ResolveOutbound(v *vmessInfo.VmessInfo, tag string, pluginPort *int) (o Out Port: port, Users: []User{ { - ID: v.ID, + ID: id, AlterID: aid, Security: "auto", }, @@ -325,7 +329,7 @@ func ResolveOutbound(v *vmessInfo.VmessInfo, tag string, pluginPort *int) (o Out Port: port, Users: []User{ { - ID: v.ID, + ID: id, //AlterID: 0, // keep AEAD on Encryption: "none", },