1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

Merge pull request #170 from v2fly/dev-enable-vmessaead-alter-0

VMess AEAD will be used when alterId is 0
This commit is contained in:
Kslr 2020-09-09 21:42:31 +08:00 committed by GitHub
commit c2d3a7339d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 32 deletions

View File

@ -14,10 +14,9 @@ import (
) )
type VMessAccount struct { type VMessAccount struct {
ID string `json:"id"` ID string `json:"id"`
AlterIds uint16 `json:"alterId"` AlterIds uint16 `json:"alterId"`
Security string `json:"security"` Security string `json:"security"`
TestsEnabled string `json:"testsEnabled"`
} }
// Build implements Buildable // Build implements Buildable
@ -41,7 +40,6 @@ func (a *VMessAccount) Build() *vmess.Account {
SecuritySettings: &protocol.SecurityConfig{ SecuritySettings: &protocol.SecurityConfig{
Type: st, Type: st,
}, },
TestsEnabled: a.TestsEnabled,
} }
} }

View File

@ -16,8 +16,6 @@ type MemoryAccount struct {
AlterIDs []*protocol.ID AlterIDs []*protocol.ID
// Security type of the account. Used for client connections. // Security type of the account. Used for client connections.
Security protocol.SecurityType Security protocol.SecurityType
TestsEnabled string
} }
// AnyValidID returns an ID that is either the main ID or one of the alternative IDs if any. // 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) protoID := protocol.NewID(id)
return &MemoryAccount{ return &MemoryAccount{
ID: protoID, ID: protoID,
AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)), AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)),
Security: a.SecuritySettings.GetSecurityType(), Security: a.SecuritySettings.GetSecurityType(),
TestsEnabled: a.TestsEnabled,
}, nil }, nil
} }

View File

@ -9,12 +9,9 @@ import (
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"encoding/binary" "encoding/binary"
"fmt"
"hash" "hash"
"hash/fnv" "hash/fnv"
"io" "io"
"os"
"strings"
vmessaead "v2ray.com/core/proxy/vmess/aead" vmessaead "v2ray.com/core/proxy/vmess/aead"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
@ -59,26 +56,12 @@ func NewClientSession(idHash protocol.IDHash, ctx context.Context) *ClientSessio
session.isAEADRequest = false session.isAEADRequest = false
if ctxValueTestsEnabled := ctx.Value(vmess.TestsEnabled); ctxValueTestsEnabled != nil { if ctxValueAlterID := ctx.Value(vmess.AlterID); ctxValueAlterID != nil {
testsEnabled := ctxValueTestsEnabled.(string) if ctxValueAlterID == 0 {
if strings.Contains(testsEnabled, "VMessAEAD") {
session.isAEADRequest = true 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.requestBodyKey[:], randomBytes[:16])
copy(session.requestBodyIV[:], randomBytes[16:32]) copy(session.requestBodyIV[:], randomBytes[16:32])
session.responseHeader = randomBytes[32] session.responseHeader = randomBytes[32]

View File

@ -113,7 +113,7 @@ func (v *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
input := link.Reader input := link.Reader
output := link.Writer 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) session := encoding.NewClientSession(protocol.DefaultIDHash, ctx)
sessionPolicy := v.policyManager.ForLevel(request.User.Level) sessionPolicy := v.policyManager.ForLevel(request.User.Level)

View File

@ -1,3 +1,3 @@
package vmess package vmess
const TestsEnabled = "VMessCtxInterface_TestsEnabled" const AlterID = "VMessCtxInterface_AlterID"