mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-12-02 06:38:45 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a93737452e |
@@ -26,14 +26,7 @@ var (
|
||||
)
|
||||
|
||||
func IsValidTLSVersion(major, minor byte) bool {
|
||||
if major != 3 {
|
||||
return false
|
||||
}
|
||||
// 1 = TLS 1.0, 4 = TLS 1.3
|
||||
if minor < 1 || minor > 4 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return major == 3
|
||||
}
|
||||
|
||||
// ReadClientHello returns server name (if any) from TLS client hello message.
|
||||
@@ -140,33 +133,19 @@ func ReadClientHello(data []byte, h *SniffHeader) error {
|
||||
}
|
||||
|
||||
func SniffTLS(b []byte) (*SniffHeader, error) {
|
||||
if len(b) < 11 {
|
||||
if len(b) < 5 {
|
||||
return nil, common.ErrNoClue
|
||||
}
|
||||
// Record type: Handshake
|
||||
if b[0] != 0x16 {
|
||||
|
||||
if b[0] != 0x16 /* TLS Handshake */ {
|
||||
return nil, errNotTLS
|
||||
}
|
||||
// Record version
|
||||
if !IsValidTLSVersion(b[1], b[2]) {
|
||||
return nil, errNotTLS
|
||||
}
|
||||
// Message type: ClientHello
|
||||
if b[5] != 0x01 {
|
||||
return nil, errNotClientHello
|
||||
}
|
||||
// Handshake version
|
||||
if !IsValidTLSVersion(b[9], b[10]) {
|
||||
return nil, errNotTLS
|
||||
}
|
||||
headerLen := int(binary.BigEndian.Uint16(b[3:5]))
|
||||
// TLS maximum record length
|
||||
if headerLen > 16384 {
|
||||
return nil, errNotTLS
|
||||
}
|
||||
// In rare cases, the record might still be incomplete after 2 read operations
|
||||
if 5+headerLen > len(b) {
|
||||
return nil, protocol.ErrProtoNeedMoreData
|
||||
return nil, common.ErrNoClue
|
||||
}
|
||||
|
||||
h := &SniffHeader{}
|
||||
|
||||
@@ -255,10 +255,11 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
|
||||
}
|
||||
ips, err := LookupForIP(dest.Address.Domain(), finalStrategy, src)
|
||||
if err != nil {
|
||||
errors.LogErrorInner(ctx, err, "failed to resolve ip")
|
||||
if sockopt.DomainStrategy.ForceIP() {
|
||||
errors.LogErrorInner(ctx, err, "failed to resolve ip for: ", dest.Address.Domain())
|
||||
return nil, err
|
||||
}
|
||||
errors.LogInfoInner(ctx, err, "failed to resolve ip for: ", dest.Address.Domain(), ", but continue due to USEIP* strategy")
|
||||
} else if sockopt.HappyEyeballs == nil || sockopt.HappyEyeballs.TryDelayMs == 0 || sockopt.HappyEyeballs.MaxConcurrentTry == 0 || len(ips) < 2 || len(sockopt.DialerProxy) > 0 || dest.Network != net.Network_TCP {
|
||||
dest.Address = net.IPAddress(ips[dice.Roll(len(ips))])
|
||||
errors.LogInfo(ctx, "replace destination with "+dest.String())
|
||||
|
||||
Reference in New Issue
Block a user