mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-12-01 14:18:38 +00:00
Compare commits
1
Commits
findprocess
...
tls-sniff
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc23e8c51e |
@@ -26,7 +26,14 @@ var (
|
||||
)
|
||||
|
||||
func IsValidTLSVersion(major, minor byte) bool {
|
||||
return major == 3
|
||||
if major != 3 {
|
||||
return false
|
||||
}
|
||||
// 1 = TLS 1.0, 4 = TLS 1.3
|
||||
if minor < 1 || minor > 4 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ReadClientHello returns server name (if any) from TLS client hello message.
|
||||
@@ -133,19 +140,33 @@ func ReadClientHello(data []byte, h *SniffHeader) error {
|
||||
}
|
||||
|
||||
func SniffTLS(b []byte) (*SniffHeader, error) {
|
||||
if len(b) < 5 {
|
||||
if len(b) < 11 {
|
||||
return nil, common.ErrNoClue
|
||||
}
|
||||
|
||||
if b[0] != 0x16 /* TLS Handshake */ {
|
||||
// Record type: Handshake
|
||||
if b[0] != 0x16 {
|
||||
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, common.ErrNoClue
|
||||
return nil, protocol.ErrProtoNeedMoreData
|
||||
}
|
||||
|
||||
h := &SniffHeader{}
|
||||
|
||||
Reference in New Issue
Block a user