1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-24 11:54:41 -05:00

fix: 清除多余 alpn 字段

This commit is contained in:
Nite07 2024-03-12 00:13:59 +08:00
parent 043167cccf
commit d26c809edd
7 changed files with 52 additions and 25 deletions

View File

@ -5,11 +5,11 @@ type OutboundTLSOptions struct {
DisableSNI bool `json:"disable_sni,omitempty"` DisableSNI bool `json:"disable_sni,omitempty"`
ServerName string `json:"server_name,omitempty"` ServerName string `json:"server_name,omitempty"`
Insecure bool `json:"insecure,omitempty"` Insecure bool `json:"insecure,omitempty"`
ALPN []string `json:"alpn,omitempty"` ALPN Listable[string] `json:"alpn,omitempty"`
MinVersion string `json:"min_version,omitempty"` MinVersion string `json:"min_version,omitempty"`
MaxVersion string `json:"max_version,omitempty"` MaxVersion string `json:"max_version,omitempty"`
CipherSuites []string `json:"cipher_suites,omitempty"` CipherSuites Listable[string] `json:"cipher_suites,omitempty"`
Certificate []string `json:"certificate,omitempty"` Certificate Listable[string] `json:"certificate,omitempty"`
CertificatePath string `json:"certificate_path,omitempty"` CertificatePath string `json:"certificate_path,omitempty"`
ECH *OutboundECHOptions `json:"ech,omitempty"` ECH *OutboundECHOptions `json:"ech,omitempty"`
UTLS *OutboundUTLSOptions `json:"utls,omitempty"` UTLS *OutboundUTLSOptions `json:"utls,omitempty"`
@ -17,11 +17,11 @@ type OutboundTLSOptions struct {
} }
type OutboundECHOptions struct { type OutboundECHOptions struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
PQSignatureSchemesEnabled bool `json:"pq_signature_schemes_enabled,omitempty"` PQSignatureSchemesEnabled bool `json:"pq_signature_schemes_enabled,omitempty"`
DynamicRecordSizingDisabled bool `json:"dynamic_record_sizing_disabled,omitempty"` DynamicRecordSizingDisabled bool `json:"dynamic_record_sizing_disabled,omitempty"`
Config []string `json:"config,omitempty"` Config Listable[string] `json:"config,omitempty"`
ConfigPath string `json:"config_path,omitempty"` ConfigPath string `json:"config_path,omitempty"`
} }
type OutboundUTLSOptions struct { type OutboundUTLSOptions struct {

View File

@ -53,7 +53,7 @@ func (o *V2RayTransportOptions) MarshalJSON() ([]byte, error) {
} }
type V2RayHTTPOptions struct { type V2RayHTTPOptions struct {
Host []string `json:"host,omitempty"` Host Listable[string] `json:"host,omitempty"`
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"` Method string `json:"method,omitempty"`
Headers map[string]string `json:"headers,omitempty"` Headers map[string]string `json:"headers,omitempty"`

View File

@ -47,9 +47,14 @@ func ParseHysteria(proxy string) (model.Proxy, error) {
insecure := params.Get("insecure") insecure := params.Get("insecure")
upmbps := params.Get("upmbps") upmbps := params.Get("upmbps")
downmbps := params.Get("downmbps") downmbps := params.Get("downmbps")
alpn := params.Get("alpn")
obfs := params.Get("obfs") obfs := params.Get("obfs")
// obfsParam := params.Get("obfsParam") // obfsParam := params.Get("obfsParam")
var alpn []string
if params.Get("alpn") != "" {
alpn = strings.Split(params.Get("alpn"), ",")
} else {
alpn = nil
}
remarks := "" remarks := ""
if strings.Contains(parts[1], "#") { if strings.Contains(parts[1], "#") {
r := strings.Split(parts[1], "#") r := strings.Split(parts[1], "#")
@ -75,7 +80,7 @@ func ParseHysteria(proxy string) (model.Proxy, error) {
TLS: &model.OutboundTLSOptions{ TLS: &model.OutboundTLSOptions{
Enabled: true, Enabled: true,
Insecure: insecureBool, Insecure: insecureBool,
ALPN: strings.Split(alpn, ","), ALPN: alpn,
}, },
}, },
} }

View File

@ -1,7 +1,7 @@
package parser package parser
import ( import (
"fmt" "errors"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
@ -10,11 +10,11 @@ import (
func ParseTrojan(proxy string) (model.Proxy, error) { func ParseTrojan(proxy string) (model.Proxy, error) {
if !strings.HasPrefix(proxy, "trojan://") { 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) parts := strings.SplitN(strings.TrimPrefix(proxy, "trojan://"), "@", 2)
if len(parts) != 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) serverInfo := strings.SplitN(parts[1], "#", 2)
serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2) serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2)
@ -24,7 +24,7 @@ func ParseTrojan(proxy string) (model.Proxy, error) {
return model.Proxy{}, err return model.Proxy{}, err
} }
if len(serverAndPort) != 2 { 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])) port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1]))
if err != nil { if err != nil {
@ -49,9 +49,15 @@ func ParseTrojan(proxy string) (model.Proxy, error) {
}, },
} }
if params.Get("security") == "xtls" || params.Get("security") == "tls" { 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{ result.Trojan.TLS = &model.OutboundTLSOptions{
Enabled: true, Enabled: true,
ALPN: strings.Split(params.Get("alpn"), ","), ALPN: alpn,
ServerName: params.Get("sni"), ServerName: params.Get("sni"),
} }
} }

View File

@ -1,7 +1,7 @@
package parser package parser
import ( import (
"fmt" "errors"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
@ -10,11 +10,11 @@ import (
func ParseVless(proxy string) (model.Proxy, error) { func ParseVless(proxy string) (model.Proxy, error) {
if !strings.HasPrefix(proxy, "vless://") { 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) parts := strings.SplitN(strings.TrimPrefix(proxy, "vless://"), "@", 2)
if len(parts) != 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) serverInfo := strings.SplitN(parts[1], "#", 2)
serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2) serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2)
@ -24,7 +24,7 @@ func ParseVless(proxy string) (model.Proxy, error) {
return model.Proxy{}, err return model.Proxy{}, err
} }
if len(serverAndPort) != 2 { 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])) port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1]))
if err != nil { if err != nil {
@ -59,13 +59,25 @@ func ParseVless(proxy string) (model.Proxy, error) {
}, },
} }
if params.Get("security") == "tls" { 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{ result.VLESS.TLS = &model.OutboundTLSOptions{
Enabled: true, Enabled: true,
ALPN: strings.Split(params.Get("alpn"), ","), ALPN: alpn,
Insecure: params.Get("allowInsecure") == "1", Insecure: params.Get("allowInsecure") == "1",
} }
} }
if params.Get("security") == "reality" { 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{ result.VLESS.TLS = &model.OutboundTLSOptions{
Enabled: true, Enabled: true,
ServerName: params.Get("sni"), ServerName: params.Get("sni"),
@ -78,7 +90,7 @@ func ParseVless(proxy string) (model.Proxy, error) {
PublicKey: params.Get("pbk"), PublicKey: params.Get("pbk"),
ShortID: params.Get("sid"), ShortID: params.Get("sid"),
}, },
ALPN: strings.Split(params.Get("alpn"), ","), ALPN: alpn,
} }
} }
if params.Get("type") == "ws" { if params.Get("type") == "ws" {

View File

@ -65,12 +65,18 @@ func ParseVmess(proxy string) (model.Proxy, error) {
} }
if vmess.Tls == "tls" { if vmess.Tls == "tls" {
var alpn []string
if strings.Contains(vmess.Alpn, ",") {
alpn = strings.Split(vmess.Alpn, ",")
} else {
alpn = nil
}
tls := model.OutboundTLSOptions{ tls := model.OutboundTLSOptions{
Enabled: true, Enabled: true,
UTLS: &model.OutboundUTLSOptions{ UTLS: &model.OutboundUTLSOptions{
Fingerprint: vmess.Fp, Fingerprint: vmess.Fp,
}, },
ALPN: strings.Split(vmess.Alpn, ","), ALPN: alpn,
} }
result.VMess.TLS = &tls result.VMess.TLS = &tls
} }

View File

@ -3,7 +3,6 @@ package util
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"net/http" "net/http"
"os" "os"
@ -25,7 +24,6 @@ func MergeTemplate(proxies []model.Proxy, template string) (string, error) {
proxyTags = append(proxyTags, p.Tag) proxyTags = append(proxyTags, p.Tag)
} }
ps, err := json.Marshal(&proxies) ps, err := json.Marshal(&proxies)
fmt.Print(string(ps))
if err != nil { if err != nil {
return "", err return "", err
} }