From d26c809edd99733235701aa1f3605615d7fbad09 Mon Sep 17 00:00:00 2001 From: nite07 Date: Tue, 12 Mar 2024 00:13:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E9=99=A4=E5=A4=9A=E4=BD=99=20a?= =?UTF-8?q?lpn=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/model/tls.go | 16 ++++++++-------- internal/model/v2ray_transport.go | 2 +- pkg/parser/hysteria.go | 9 +++++++-- pkg/parser/trojan.go | 16 +++++++++++----- pkg/parser/vless.go | 24 ++++++++++++++++++------ pkg/parser/vmess.go | 8 +++++++- pkg/util/convert.go | 2 -- 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/internal/model/tls.go b/internal/model/tls.go index 50e5f78..6542944 100644 --- a/internal/model/tls.go +++ b/internal/model/tls.go @@ -5,11 +5,11 @@ type OutboundTLSOptions struct { DisableSNI bool `json:"disable_sni,omitempty"` ServerName string `json:"server_name,omitempty"` Insecure bool `json:"insecure,omitempty"` - ALPN []string `json:"alpn,omitempty"` + ALPN Listable[string] `json:"alpn,omitempty"` MinVersion string `json:"min_version,omitempty"` MaxVersion string `json:"max_version,omitempty"` - CipherSuites []string `json:"cipher_suites,omitempty"` - Certificate []string `json:"certificate,omitempty"` + CipherSuites Listable[string] `json:"cipher_suites,omitempty"` + Certificate Listable[string] `json:"certificate,omitempty"` CertificatePath string `json:"certificate_path,omitempty"` ECH *OutboundECHOptions `json:"ech,omitempty"` UTLS *OutboundUTLSOptions `json:"utls,omitempty"` @@ -17,11 +17,11 @@ type OutboundTLSOptions struct { } type OutboundECHOptions struct { - Enabled bool `json:"enabled,omitempty"` - PQSignatureSchemesEnabled bool `json:"pq_signature_schemes_enabled,omitempty"` - DynamicRecordSizingDisabled bool `json:"dynamic_record_sizing_disabled,omitempty"` - Config []string `json:"config,omitempty"` - ConfigPath string `json:"config_path,omitempty"` + Enabled bool `json:"enabled,omitempty"` + PQSignatureSchemesEnabled bool `json:"pq_signature_schemes_enabled,omitempty"` + DynamicRecordSizingDisabled bool `json:"dynamic_record_sizing_disabled,omitempty"` + Config Listable[string] `json:"config,omitempty"` + ConfigPath string `json:"config_path,omitempty"` } type OutboundUTLSOptions struct { diff --git a/internal/model/v2ray_transport.go b/internal/model/v2ray_transport.go index 2b9ea80..46ac7a6 100644 --- a/internal/model/v2ray_transport.go +++ b/internal/model/v2ray_transport.go @@ -53,7 +53,7 @@ func (o *V2RayTransportOptions) MarshalJSON() ([]byte, error) { } type V2RayHTTPOptions struct { - Host []string `json:"host,omitempty"` + Host Listable[string] `json:"host,omitempty"` Path string `json:"path,omitempty"` Method string `json:"method,omitempty"` Headers map[string]string `json:"headers,omitempty"` diff --git a/pkg/parser/hysteria.go b/pkg/parser/hysteria.go index 7f02fa0..bcfebfe 100644 --- a/pkg/parser/hysteria.go +++ b/pkg/parser/hysteria.go @@ -47,9 +47,14 @@ func ParseHysteria(proxy string) (model.Proxy, error) { insecure := params.Get("insecure") upmbps := params.Get("upmbps") downmbps := params.Get("downmbps") - alpn := params.Get("alpn") obfs := params.Get("obfs") // obfsParam := params.Get("obfsParam") + var alpn []string + if params.Get("alpn") != "" { + alpn = strings.Split(params.Get("alpn"), ",") + } else { + alpn = nil + } remarks := "" if strings.Contains(parts[1], "#") { r := strings.Split(parts[1], "#") @@ -75,7 +80,7 @@ func ParseHysteria(proxy string) (model.Proxy, error) { TLS: &model.OutboundTLSOptions{ Enabled: true, Insecure: insecureBool, - ALPN: strings.Split(alpn, ","), + ALPN: alpn, }, }, } diff --git a/pkg/parser/trojan.go b/pkg/parser/trojan.go index 95051c9..dd1ab3b 100644 --- a/pkg/parser/trojan.go +++ b/pkg/parser/trojan.go @@ -1,7 +1,7 @@ package parser import ( - "fmt" + "errors" "net/url" "strconv" "strings" @@ -10,11 +10,11 @@ import ( func ParseTrojan(proxy string) (model.Proxy, error) { if !strings.HasPrefix(proxy, "trojan://") { - return model.Proxy{}, fmt.Errorf("invalid trojan Url") + return model.Proxy{}, errors.New("invalid trojan Url") } parts := strings.SplitN(strings.TrimPrefix(proxy, "trojan://"), "@", 2) if len(parts) != 2 { - return model.Proxy{}, fmt.Errorf("invalid trojan Url") + return model.Proxy{}, errors.New("invalid trojan Url") } serverInfo := strings.SplitN(parts[1], "#", 2) serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2) @@ -24,7 +24,7 @@ func ParseTrojan(proxy string) (model.Proxy, error) { return model.Proxy{}, err } if len(serverAndPort) != 2 { - return model.Proxy{}, fmt.Errorf("invalid trojan") + return model.Proxy{}, errors.New("invalid trojan Url") } port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1])) if err != nil { @@ -49,9 +49,15 @@ func ParseTrojan(proxy string) (model.Proxy, error) { }, } if params.Get("security") == "xtls" || params.Get("security") == "tls" { + var alpn []string + if strings.Contains(params.Get("alpn"), ",") { + alpn = strings.Split(params.Get("alpn"), ",") + } else { + alpn = nil + } result.Trojan.TLS = &model.OutboundTLSOptions{ Enabled: true, - ALPN: strings.Split(params.Get("alpn"), ","), + ALPN: alpn, ServerName: params.Get("sni"), } } diff --git a/pkg/parser/vless.go b/pkg/parser/vless.go index 30005c3..a7767dc 100644 --- a/pkg/parser/vless.go +++ b/pkg/parser/vless.go @@ -1,7 +1,7 @@ package parser import ( - "fmt" + "errors" "net/url" "strconv" "strings" @@ -10,11 +10,11 @@ import ( func ParseVless(proxy string) (model.Proxy, error) { if !strings.HasPrefix(proxy, "vless://") { - return model.Proxy{}, fmt.Errorf("invalid vless Url") + return model.Proxy{}, errors.New("invalid vless Url") } parts := strings.SplitN(strings.TrimPrefix(proxy, "vless://"), "@", 2) if len(parts) != 2 { - return model.Proxy{}, fmt.Errorf("invalid vless Url") + return model.Proxy{}, errors.New("invalid vless Url") } serverInfo := strings.SplitN(parts[1], "#", 2) serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2) @@ -24,7 +24,7 @@ func ParseVless(proxy string) (model.Proxy, error) { return model.Proxy{}, err } if len(serverAndPort) != 2 { - return model.Proxy{}, fmt.Errorf("invalid vless") + return model.Proxy{}, errors.New("invalid vless Url") } port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1])) if err != nil { @@ -59,13 +59,25 @@ func ParseVless(proxy string) (model.Proxy, error) { }, } if params.Get("security") == "tls" { + var alpn []string + if strings.Contains(params.Get("alpn"), ",") { + alpn = strings.Split(params.Get("alpn"), ",") + } else { + alpn = nil + } result.VLESS.TLS = &model.OutboundTLSOptions{ Enabled: true, - ALPN: strings.Split(params.Get("alpn"), ","), + ALPN: alpn, Insecure: params.Get("allowInsecure") == "1", } } if params.Get("security") == "reality" { + var alpn []string + if strings.Contains(params.Get("alpn"), ",") { + alpn = strings.Split(params.Get("alpn"), ",") + } else { + alpn = nil + } result.VLESS.TLS = &model.OutboundTLSOptions{ Enabled: true, ServerName: params.Get("sni"), @@ -78,7 +90,7 @@ func ParseVless(proxy string) (model.Proxy, error) { PublicKey: params.Get("pbk"), ShortID: params.Get("sid"), }, - ALPN: strings.Split(params.Get("alpn"), ","), + ALPN: alpn, } } if params.Get("type") == "ws" { diff --git a/pkg/parser/vmess.go b/pkg/parser/vmess.go index 1605677..74b044b 100644 --- a/pkg/parser/vmess.go +++ b/pkg/parser/vmess.go @@ -65,12 +65,18 @@ func ParseVmess(proxy string) (model.Proxy, error) { } if vmess.Tls == "tls" { + var alpn []string + if strings.Contains(vmess.Alpn, ",") { + alpn = strings.Split(vmess.Alpn, ",") + } else { + alpn = nil + } tls := model.OutboundTLSOptions{ Enabled: true, UTLS: &model.OutboundUTLSOptions{ Fingerprint: vmess.Fp, }, - ALPN: strings.Split(vmess.Alpn, ","), + ALPN: alpn, } result.VMess.TLS = &tls } diff --git a/pkg/util/convert.go b/pkg/util/convert.go index 02d1ef8..e9682dd 100644 --- a/pkg/util/convert.go +++ b/pkg/util/convert.go @@ -3,7 +3,6 @@ package util import ( "encoding/json" "errors" - "fmt" "io" "net/http" "os" @@ -25,7 +24,6 @@ func MergeTemplate(proxies []model.Proxy, template string) (string, error) { proxyTags = append(proxyTags, p.Tag) } ps, err := json.Marshal(&proxies) - fmt.Print(string(ps)) if err != nil { return "", err }