From 2a3fe1195282cf206fdab5a10e64ab9f419aea95 Mon Sep 17 00:00:00 2001 From: Kslr Date: Wed, 9 Sep 2020 00:02:53 +0800 Subject: [PATCH] VMess AEAD will be used when alterId is 0 --- infra/conf/vmess.go | 8 +++----- proxy/vmess/account.go | 9 +++------ proxy/vmess/encoding/client.go | 21 ++------------------- proxy/vmess/outbound/outbound.go | 2 +- proxy/vmess/vmessCtxInterface.go | 2 +- 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/infra/conf/vmess.go b/infra/conf/vmess.go index 838fa2632..093bf62de 100644 --- a/infra/conf/vmess.go +++ b/infra/conf/vmess.go @@ -14,10 +14,9 @@ import ( ) type VMessAccount struct { - ID string `json:"id"` - AlterIds uint16 `json:"alterId"` - Security string `json:"security"` - TestsEnabled string `json:"testsEnabled"` + ID string `json:"id"` + AlterIds uint16 `json:"alterId"` + Security string `json:"security"` } // Build implements Buildable @@ -41,7 +40,6 @@ func (a *VMessAccount) Build() *vmess.Account { SecuritySettings: &protocol.SecurityConfig{ Type: st, }, - TestsEnabled: a.TestsEnabled, } } diff --git a/proxy/vmess/account.go b/proxy/vmess/account.go index 0f77a51ef..eff55debb 100644 --- a/proxy/vmess/account.go +++ b/proxy/vmess/account.go @@ -16,8 +16,6 @@ type MemoryAccount struct { AlterIDs []*protocol.ID // Security type of the account. Used for client connections. Security protocol.SecurityType - - TestsEnabled string } // AnyValidID returns an ID that is either the main ID or one of the alternative IDs if any. @@ -46,9 +44,8 @@ func (a *Account) AsAccount() (protocol.Account, error) { } protoID := protocol.NewID(id) return &MemoryAccount{ - ID: protoID, - AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)), - Security: a.SecuritySettings.GetSecurityType(), - TestsEnabled: a.TestsEnabled, + ID: protoID, + AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)), + Security: a.SecuritySettings.GetSecurityType(), }, nil } diff --git a/proxy/vmess/encoding/client.go b/proxy/vmess/encoding/client.go index 9ecd74824..96808622a 100644 --- a/proxy/vmess/encoding/client.go +++ b/proxy/vmess/encoding/client.go @@ -9,12 +9,9 @@ import ( "crypto/rand" "crypto/sha256" "encoding/binary" - "fmt" "hash" "hash/fnv" "io" - "os" - "strings" vmessaead "v2ray.com/core/proxy/vmess/aead" "golang.org/x/crypto/chacha20poly1305" @@ -59,26 +56,12 @@ func NewClientSession(idHash protocol.IDHash, ctx context.Context) *ClientSessio session.isAEADRequest = false - if ctxValueTestsEnabled := ctx.Value(vmess.TestsEnabled); ctxValueTestsEnabled != nil { - testsEnabled := ctxValueTestsEnabled.(string) - if strings.Contains(testsEnabled, "VMessAEAD") { + if ctxValueAlterID := ctx.Value(vmess.AlterID); ctxValueAlterID != nil { + if ctxValueAlterID == 0 { session.isAEADRequest = true } } - if vmessexp, vmessexp_found := os.LookupEnv("VMESSAEADEXPERIMENT"); vmessexp_found { - if vmessexp == "y" { - session.isAEADRequest = true - } - if vmessexp == "n" { - session.isAEADRequest = false - } - } - - if session.isAEADRequest { - fmt.Println("=======VMESSAEADEXPERIMENT ENABLED========") - } - copy(session.requestBodyKey[:], randomBytes[:16]) copy(session.requestBodyIV[:], randomBytes[16:32]) session.responseHeader = randomBytes[32] diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index 5b5fdd0d9..cbbbf585f 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -113,7 +113,7 @@ func (v *Handler) Process(ctx context.Context, link *transport.Link, dialer inte input := link.Reader output := link.Writer - ctx = context.WithValue(ctx, vmess.TestsEnabled, user.Account.(*vmess.MemoryAccount).TestsEnabled) + ctx = context.WithValue(ctx, vmess.AlterID, len(account.AlterIDs)) session := encoding.NewClientSession(protocol.DefaultIDHash, ctx) sessionPolicy := v.policyManager.ForLevel(request.User.Level) diff --git a/proxy/vmess/vmessCtxInterface.go b/proxy/vmess/vmessCtxInterface.go index edaad0606..dbfb5b72e 100644 --- a/proxy/vmess/vmessCtxInterface.go +++ b/proxy/vmess/vmessCtxInterface.go @@ -1,3 +1,3 @@ package vmess -const TestsEnabled = "VMessCtxInterface_TestsEnabled" +const AlterID = "VMessCtxInterface_AlterID"