mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-01 21:45:44 +00:00
Compare commits
1
Commits
v26.9.30
...
vision-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aac8019566 |
@@ -277,6 +277,7 @@ func (w *VisionReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||||||
w.ob.CanSpliceCopy = 1
|
w.ob.CanSpliceCopy = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SuppressOuterCloseNotify(w.conn)
|
||||||
readerConn, readCounter, _ := UnwrapRawConn(w.conn)
|
readerConn, readCounter, _ := UnwrapRawConn(w.conn)
|
||||||
w.directReadCounter = readCounter
|
w.directReadCounter = readCounter
|
||||||
w.Reader = buf.NewReader(readerConn)
|
w.Reader = buf.NewReader(readerConn)
|
||||||
@@ -340,6 +341,7 @@ func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||||||
// w.ob.CanSpliceCopy = 1
|
// w.ob.CanSpliceCopy = 1
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
SuppressOuterCloseNotify(w.conn)
|
||||||
rawConn, _, writerCounter := UnwrapRawConn(w.conn)
|
rawConn, _, writerCounter := UnwrapRawConn(w.conn)
|
||||||
w.Writer = buf.NewWriter(rawConn)
|
w.Writer = buf.NewWriter(rawConn)
|
||||||
w.directWriteCounter = writerCounter
|
w.directWriteCounter = writerCounter
|
||||||
@@ -669,6 +671,19 @@ func XtlsFilterTls(buffer buf.MultiBuffer, trafficState *TrafficState, ctx conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CloseNotifySuppressor interface {
|
||||||
|
SuppressCloseNotify()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close our local TLS conn instance might send a incorrect close_notify alert
|
||||||
|
// if the XTLS direct copy mode is enabled and cause TLS BAD_RECORD_MAC on users' browser
|
||||||
|
// Close the underlying connection directly to avoid this issue.
|
||||||
|
func SuppressOuterCloseNotify(conn net.Conn) {
|
||||||
|
if suppressor, ok := stat.TryUnwrapStatsConn(conn).(CloseNotifySuppressor); ok {
|
||||||
|
suppressor.SuppressCloseNotify()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UnwrapRawConn support unwrap encryption, stats, mask wrappers, tls, utls, reality, proxyproto, uds-wrapper conn and get raw tcp/uds conn from it
|
// UnwrapRawConn support unwrap encryption, stats, mask wrappers, tls, utls, reality, proxyproto, uds-wrapper conn and get raw tcp/uds conn from it
|
||||||
func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter) {
|
func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter) {
|
||||||
var readCounter, writerCounter stats.Counter
|
var readCounter, writerCounter stats.Counter
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@@ -36,6 +37,18 @@ import (
|
|||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
*reality.Conn
|
*reality.Conn
|
||||||
|
suppressCloseNotify atomic.Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conn) SuppressCloseNotify() {
|
||||||
|
c.suppressCloseNotify.Store(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conn) Close() error {
|
||||||
|
if c.suppressCloseNotify.Load() {
|
||||||
|
return c.Conn.NetConn().Close()
|
||||||
|
}
|
||||||
|
return c.Conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) HandshakeAddress() net.Address {
|
func (c *Conn) HandshakeAddress() net.Address {
|
||||||
@@ -56,10 +69,22 @@ func Server(c net.Conn, config *reality.Config) (net.Conn, error) {
|
|||||||
|
|
||||||
type UConn struct {
|
type UConn struct {
|
||||||
*utls.UConn
|
*utls.UConn
|
||||||
Config *Config
|
Config *Config
|
||||||
ServerName string
|
ServerName string
|
||||||
AuthKey []byte
|
AuthKey []byte
|
||||||
Verified bool
|
Verified bool
|
||||||
|
suppressCloseNotify atomic.Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *UConn) SuppressCloseNotify() {
|
||||||
|
c.suppressCloseNotify.Store(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *UConn) Close() error {
|
||||||
|
if c.suppressCloseNotify.Load() {
|
||||||
|
return c.NetConn().Close()
|
||||||
|
}
|
||||||
|
return c.UConn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *UConn) HandshakeAddress() net.Address {
|
func (c *UConn) HandshakeAddress() net.Address {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"math/big"
|
"math/big"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
utls "github.com/refraction-networking/utls"
|
utls "github.com/refraction-networking/utls"
|
||||||
@@ -29,11 +30,19 @@ var (
|
|||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
*tls.Conn
|
*tls.Conn
|
||||||
|
suppressCloseNotify atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const tlsCloseTimeout = 250 * time.Millisecond
|
const tlsCloseTimeout = 250 * time.Millisecond
|
||||||
|
|
||||||
|
func (c *Conn) SuppressCloseNotify() {
|
||||||
|
c.suppressCloseNotify.Store(true)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Conn) Close() error {
|
func (c *Conn) Close() error {
|
||||||
|
if c.suppressCloseNotify.Load() {
|
||||||
|
return c.Conn.NetConn().Close()
|
||||||
|
}
|
||||||
timer := time.AfterFunc(tlsCloseTimeout, func() {
|
timer := time.AfterFunc(tlsCloseTimeout, func() {
|
||||||
c.Conn.NetConn().Close()
|
c.Conn.NetConn().Close()
|
||||||
})
|
})
|
||||||
@@ -74,11 +83,19 @@ func Server(c net.Conn, config *tls.Config) net.Conn {
|
|||||||
|
|
||||||
type UConn struct {
|
type UConn struct {
|
||||||
*utls.UConn
|
*utls.UConn
|
||||||
|
suppressCloseNotify atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Interface = (*UConn)(nil)
|
var _ Interface = (*UConn)(nil)
|
||||||
|
|
||||||
|
func (c *UConn) SuppressCloseNotify() {
|
||||||
|
c.suppressCloseNotify.Store(true)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *UConn) Close() error {
|
func (c *UConn) Close() error {
|
||||||
|
if c.suppressCloseNotify.Load() {
|
||||||
|
return c.Conn.NetConn().Close()
|
||||||
|
}
|
||||||
timer := time.AfterFunc(tlsCloseTimeout, func() {
|
timer := time.AfterFunc(tlsCloseTimeout, func() {
|
||||||
c.Conn.NetConn().Close()
|
c.Conn.NetConn().Close()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user