Compare commits

..
2 Commits
Author SHA1 Message Date
Fangliding 8fa1d96baf simplify 2026-12-01 14:33:41 +08:00
Fangliding a8d14de333 Delete ALPS for utls H1 2026-12-01 00:53:01 +08:00
2 changed files with 12 additions and 26 deletions
+5 -26
View File
@@ -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{}
+7
View File
@@ -130,6 +130,13 @@ func (c *UConn) WebsocketHandshakeContext(ctx context.Context) error {
config.NextProtos = []string{"http/1.1"}
return c.HandshakeContext(ctx)
}
// Chrome won't send ApplicationSettingsExtension for h1 request
if slices.Equal(ALPN, []string{"http/1.1"}) {
c.Extensions = slices.DeleteFunc(c.Extensions, func(extension utls.TLSExtension) bool {
_, ok := extension.(*utls.ApplicationSettingsExtensionNew)
return ok
})
}
// Iterate over extensions and check for utls.ALPNExtension
hasALPNExtension := false
for _, extension := range c.Extensions {