feat/fix: support the UUID mapping standard. #211

This commit is contained in:
mzz2017 committed 2021-07-21 16:51:27 +08:00
1 parent fb1c9e9d4b
commit 8dce041ae8
3 files changed
+32 -4

No files matched your search

+1 -1
View File
@@ -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 || "",
+25 -1
View File
@@ -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
}
}
// 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)
}
+6 -2
View File
@@ -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",
},