mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-24 15:38:36 +00:00
Three types of ALPN for post-handshake records detection & imitation
https://github.com/XTLS/Xray-core/issues/4778#issuecomment-3072047745
This commit is contained in:
parent
e62c4aed0d
commit
05a351a645
@ -5,6 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -16,7 +17,8 @@ var GlobalPostHandshakeRecordsLens sync.Map
|
||||
|
||||
func DetectPostHandshakeRecordsLens(config *Config) {
|
||||
for sni := range config.ServerNames {
|
||||
key := config.Dest + " " + sni
|
||||
for alpn := range 3 { // 0, 1, 2
|
||||
key := config.Dest + " " + sni + " " + strconv.Itoa(alpn)
|
||||
if _, loaded := GlobalPostHandshakeRecordsLens.LoadOrStore(key, false); !loaded {
|
||||
go func() {
|
||||
defer func() {
|
||||
@ -38,9 +40,21 @@ func DetectPostHandshakeRecordsLens(config *Config) {
|
||||
Conn: target,
|
||||
Key: key,
|
||||
}
|
||||
fingerprint := utls.HelloChrome_Auto
|
||||
nextProtos := []string{"h2", "http/1.1"}
|
||||
if alpn != 2 {
|
||||
fingerprint = utls.HelloGolang
|
||||
}
|
||||
if alpn == 1 {
|
||||
nextProtos = []string{"http/1.1"}
|
||||
}
|
||||
if alpn == 0 {
|
||||
nextProtos = nil
|
||||
}
|
||||
uConn := utls.UClient(detectConn, &utls.Config{
|
||||
ServerName: sni, // needs new loopvar behaviour
|
||||
}, utls.HelloChrome_Auto)
|
||||
NextProtos: nextProtos,
|
||||
}, fingerprint)
|
||||
if err = uConn.Handshake(); err != nil {
|
||||
return
|
||||
}
|
||||
@ -49,6 +63,7 @@ func DetectPostHandshakeRecordsLens(config *Config) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type DetectConn struct {
|
||||
net.Conn
|
||||
|
10
tls.go
10
tls.go
@ -371,7 +371,15 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
||||
break
|
||||
}
|
||||
for {
|
||||
if val, ok := GlobalPostHandshakeRecordsLens.Load(config.Dest + " " + hs.clientHello.serverName); ok {
|
||||
key := config.Dest + " " + hs.clientHello.serverName
|
||||
if len(hs.clientHello.alpnProtocols) == 0 {
|
||||
key += " 0"
|
||||
} else if hs.clientHello.alpnProtocols[0] == "h2" {
|
||||
key += " 2"
|
||||
} else {
|
||||
key += " 1"
|
||||
}
|
||||
if val, ok := GlobalPostHandshakeRecordsLens.Load(key); ok {
|
||||
if postHandshakeRecordsLens, ok := val.([]int); ok {
|
||||
for _, length := range postHandshakeRecordsLens {
|
||||
plainText := make([]byte, length-16)
|
||||
|
Loading…
Reference in New Issue
Block a user