chore: add get tls connection state function in component/tls

This commit is contained in:
wwqgtxx committed 2026-04-04 09:39:59 +08:00
1 parent 0d85eaa34d
commit 3db64d039f
2 files changed
+16 -13

No files matched your search

+12
View File
@@ -308,6 +308,18 @@ func BuildRemovedX25519MLKEM768HandshakeState(c *UConn) error {
return nil
}
func GetTLSConnectionState(conn net.Conn) (tlsState tls.ConnectionState) {
switch tlsConn := conn.(type) {
case interface{ ConnectionState() tls.ConnectionState }:
state := tlsConn.ConnectionState()
return state
case interface{ ConnectionState() utls.ConnectionState }:
state := tlsConn.ConnectionState()
return tlsConnectionState(state)
}
return
}
var globalFingerprint string
func SetGlobalFingerprint(fingerprint string) {
+4 -13
View File
@@ -267,19 +267,10 @@ func NewTransport(dialFn DialFn, tlsConfig *vmess.TLSConfig, gunCfg *Config) *Tr
}
if tlsConfig.Reality == nil { // reality doesn't return the negotiated ALPN
switch tlsConn := conn.(type) {
case interface{ ConnectionState() tls.ConnectionState }:
state := tlsConn.ConnectionState()
if p := state.NegotiatedProtocol; p != http.Http2NextProtoTLS {
_ = conn.Close()
return nil, fmt.Errorf("http2: unexpected ALPN protocol %s, want %s", p, http.Http2NextProtoTLS)
}
case interface{ ConnectionState() tlsC.ConnectionState }:
state := tlsConn.ConnectionState()
if p := state.NegotiatedProtocol; p != http.Http2NextProtoTLS {
_ = conn.Close()
return nil, fmt.Errorf("http2: unexpected ALPN protocol %s, want %s", p, http.Http2NextProtoTLS)
}
state := tlsC.GetTLSConnectionState(conn)
if p := state.NegotiatedProtocol; p != http.Http2NextProtoTLS {
_ = conn.Close()
return nil, fmt.Errorf("http2: unexpected ALPN protocol %s, want %s", p, http.Http2NextProtoTLS)
}
}
return conn, nil