From 23b6b987ca87fe59e69f7e713069345c656766f6 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 20 Jan 2016 16:45:50 +0000 Subject: [PATCH] fix a bug in cmdkey generation --- common/serial/bytes.go | 9 +++++++++ proxy/vmess/id.go | 2 +- proxy/vmess/id_test.go | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 proxy/vmess/id_test.go diff --git a/common/serial/bytes.go b/common/serial/bytes.go index 45f49666a..2ffb2570f 100644 --- a/common/serial/bytes.go +++ b/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 +} \ No newline at end of file diff --git a/proxy/vmess/id.go b/proxy/vmess/id.go index 3d29d5329..7033dab5e 100644 --- a/proxy/vmess/id.go +++ b/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 } diff --git a/proxy/vmess/id_test.go b/proxy/vmess/id_test.go new file mode 100644 index 000000000..0a6046d4c --- /dev/null +++ b/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() +}