Ver código fonte

fix a bug in cmdkey generation

Darien Raymond 9 anos atrás
pai
commit
23b6b987ca
3 arquivos alterados com 28 adições e 1 exclusões
  1. 9 0
      common/serial/bytes.go
  2. 1 1
      proxy/vmess/id.go
  3. 18 0
      proxy/vmess/id_test.go

+ 9 - 0
common/serial/bytes.go

@@ -25,3 +25,12 @@ func (this BytesLiteral) Int64Value() int64 {
 func (this BytesLiteral) String() string {
 	return string(this.Value())
 }
+
+func (this BytesLiteral) AllZero() bool {
+  for _, b := range this {
+    if b != 0 {
+      return false
+    }
+  }
+  return true
+}

+ 1 - 1
proxy/vmess/id.go

@@ -46,6 +46,6 @@ func NewID(uuid *uuid.UUID) *ID {
 	md5hash := md5.New()
 	md5hash.Write(uuid.Bytes())
 	md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21"))
-	md5.Sum(id.cmdKey[:0])
+	md5hash.Sum(id.cmdKey[:0])
 	return id
 }

+ 18 - 0
proxy/vmess/id_test.go

@@ -0,0 +1,18 @@
+package vmess_test
+
+import (
+  "testing"
+
+  "github.com/v2ray/v2ray-core/common/uuid"
+  "github.com/v2ray/v2ray-core/common/serial"
+  . "github.com/v2ray/v2ray-core/proxy/vmess"
+  v2testing "github.com/v2ray/v2ray-core/testing"
+  "github.com/v2ray/v2ray-core/testing/assert"
+)
+
+func TestCmdKey(t *testing.T) {
+  v2testing.Current(t)
+
+  id := NewID(uuid.New())
+  assert.Bool(serial.BytesLiteral(id.CmdKey()).AllZero()).IsFalse()
+}