From 0681136d6572adb2b94c56034fa6aac9db5e7fa1 Mon Sep 17 00:00:00 2001 From: nite07 Date: Sat, 16 Nov 2024 00:26:54 +0800 Subject: [PATCH] fix: hy2 parser --- parser/hysteria.go | 3 ++- parser/hysteria2.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/parser/hysteria.go b/parser/hysteria.go index 455d471..a7db730 100755 --- a/parser/hysteria.go +++ b/parser/hysteria.go @@ -55,6 +55,7 @@ func ParseHysteria(proxy string) (model.Outbound, error) { protocol, auth, insecure, upmbps, downmbps, obfs, alpnStr := query.Get("protocol"), query.Get("auth"), query.Get("insecure"), query.Get("upmbps"), query.Get("downmbps"), query.Get("obfs"), query.Get("alpn") insecureBool, err := strconv.ParseBool(insecure) + enableTLS := insecureBool || alpnStr != "" if err != nil { insecureBool = false } @@ -86,7 +87,7 @@ func ParseHysteria(proxy string) (model.Outbound, error) { Network: option.NetworkList(protocol), OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{ TLS: &option.OutboundTLSOptions{ - Enabled: true, + Enabled: enableTLS, Insecure: insecureBool, ALPN: alpn, }, diff --git a/parser/hysteria2.go b/parser/hysteria2.go index ed2e1f5..dd57e12 100755 --- a/parser/hysteria2.go +++ b/parser/hysteria2.go @@ -55,9 +55,16 @@ func ParseHysteria2(proxy string) (model.Outbound, error) { Raw: portStr, } } - network, obfs, obfsPassword, pinSHA256, insecure, sni := query.Get("network"), query.Get("obfs"), query.Get("obfs-password"), query.Get("pinSHA256"), query.Get("insecure"), query.Get("sni") - enableTLS := pinSHA256 != "" || sni != "" + network, obfs, obfsPassword, pinSHA256, insecure, sni, alpnStr := query.Get("network"), query.Get("obfs"), query.Get("obfs-password"), query.Get("pinSHA256"), query.Get("insecure"), query.Get("sni"), query.Get("alpn") insecureBool := insecure == "1" + enableTLS := pinSHA256 != "" || sni != "" || alpnStr != "" + + var alpn []string + alpnStr = strings.TrimSpace(alpnStr) + if alpnStr != "" { + alpn = strings.Split(alpnStr, ",") + } + remarks := link.Fragment if remarks == "" { remarks = fmt.Sprintf("%s:%s", server, portStr) @@ -79,6 +86,7 @@ func ParseHysteria2(proxy string) (model.Outbound, error) { Enabled: enableTLS, Insecure: insecureBool, ServerName: sni, + ALPN: alpn, }, }, Network: option.NetworkList(network),