1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 21:14:43 -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"`
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 {

View File

@ -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"`

View File

@ -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,
},
},
}

View File

@ -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"),
}
}

View File

@ -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" {

View File

@ -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
}

View File

@ -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
}