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)
+2 -3
View File
@@ -8,6 +8,7 @@ import (
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"hash/fnv"
"io"
"math/rand"
@@ -18,7 +19,6 @@ import (
"golang.org/x/crypto/chacha20poly1305"
"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
)
@@ -321,8 +321,7 @@ func (c *Conn) Read(b []byte) (n int, err error) {
err = c.DecodeRespHeader()
if err != nil {
log.F("[vmess] DecodeRespHeader error: %s", err)
return 0, err
return 0, fmt.Errorf("[vmess] error in DecodeRespHeader: %w", err)
}
c.dataReader = c.Conn
+12 -1
View File
@@ -3,6 +3,7 @@ package vmess
import (
"bytes"
"crypto/md5"
"crypto/sha1"
"encoding/binary"
"encoding/hex"
"errors"
@@ -53,8 +54,17 @@ func (u *User) GenAlterIDUsers(alterID int) []*User {
}
// 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)
@@ -63,6 +73,7 @@ func StrToUUID(s string) (uuid [16]byte, err error) {
return
}
// GetKey returns the key of AES-128-CFB encrypter.
// Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))
func GetKey(uuid [16]byte) []byte {