diff --git a/protocol/vless/encryption/common.go b/protocol/vless/encryption/common.go index ad2592d0..6fbb35df 100644 --- a/protocol/vless/encryption/common.go +++ b/protocol/vless/encryption/common.go @@ -113,7 +113,7 @@ func (c *CommonConn) Read(b []byte) (int, error) { if _, err := io.ReadFull(c.Conn, peerHeader[:]); err != nil { return 0, err } - l, err := DecodeHeader(peerHeader[:]) // l: 17~17000 + l, err := DecodeHeader(peerHeader[:]) // l: 17~16640 if err != nil { if c.Client != nil && errors.Is(err, ErrInvalidHeader) { // client's 0-RTT c.Client.RWLock.Lock() @@ -238,7 +238,7 @@ func DecodeHeader(h []byte) (l int, err error) { if h[0] != 23 || h[1] != 3 || h[2] != 3 { l = 0 } - if l < 17 || l > 17000 { // TODO: TLSv1.3 max length + if l < 17 || l > 16640 { // TLS 1.3 max record: 16384 + 256 (RFC 8446 ยง5.2) err = fmt.Errorf("%w: %v", ErrInvalidHeader, h[:5]) // DO NOT CHANGE: relied by client's Read() } return diff --git a/protocol/vless/inbound.go b/protocol/vless/inbound.go index 1a76e522..04d6968c 100644 --- a/protocol/vless/inbound.go +++ b/protocol/vless/inbound.go @@ -319,6 +319,10 @@ func parseServerDecryption(raw string) (serverDecryptionConfig, error) { if segment == "" { return cfg, E.New("invalid empty segment in decryption string") } + if paddingPhase && len(segment) < 20 { + paddingParts = append(paddingParts, segment) + continue + } if data, err := base64.RawURLEncoding.DecodeString(segment); err == nil { if len(data) == 32 || len(data) == 64 { cfg.keys = append(cfg.keys, data) @@ -327,10 +331,6 @@ func parseServerDecryption(raw string) (serverDecryptionConfig, error) { } return cfg, E.New("invalid decryption key length: ", len(data)) } - if paddingPhase { - paddingParts = append(paddingParts, segment) - continue - } return cfg, E.New("invalid decryption key: ", segment) } if len(cfg.keys) == 0 {