feat(anytls): add AnyTLS protocol support with parsing and configuration options

This commit is contained in:
Chang lue Tsen
2025-07-05 14:30:12 -04:00
parent 1a849fd461
commit 4f49dea769
4 changed files with 76 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
package singbox
import "github.com/perfect-panel/server/pkg/adapter/proxy"
type AnyTLSOutboundOptions struct {
ServerOptions
OutboundTLSOptionsContainer
Password string `json:"password,omitempty"`
}
func ParseAnyTLS(data proxy.Proxy, password string) (*Proxy, error) {
anyTLS := data.Option.(proxy.AnyTLS)
config := &AnyTLSOutboundOptions{
ServerOptions: ServerOptions{
Tag: data.Name,
Type: AnyTLS,
Server: data.Server,
ServerPort: data.Port,
},
OutboundTLSOptionsContainer: OutboundTLSOptionsContainer{
TLS: &OutboundTLSOptions{
Enabled: true,
ALPN: []string{"h2", "http/1.1"},
Insecure: anyTLS.SecurityConfig.AllowInsecure,
},
},
Password: password,
}
if anyTLS.SecurityConfig.SNI != "" {
config.OutboundTLSOptionsContainer.TLS.ServerName = anyTLS.SecurityConfig.SNI
}
p := &Proxy{
Tag: data.Name,
Type: AnyTLS,
AnyTLSOptions: config,
}
return p, nil
}
+4
View File
@@ -11,6 +11,7 @@ const (
VMess = "vmess"
TUIC = "tuic"
Hysteria2 = "hysteria2"
AnyTLS = "anytls"
Shadowsocks = "shadowsocks"
Selector = "selector"
URLTest = "urltest"
@@ -27,6 +28,7 @@ type Proxy struct {
TrojanOptions *TrojanOutboundOptions `json:"-"`
VLESSOptions *VLESSOutboundOptions `json:"-"`
VMessOptions *VMessOutboundOptions `json:"-"`
AnyTLSOptions *AnyTLSOutboundOptions `json:"-"`
Hysteria2Options *Hysteria2OutboundOptions `json:"-"`
SelectorOptions *SelectorOutboundOptions `json:"-"`
URLTestOptions *URLTestOutboundOptions `json:"-"`
@@ -86,6 +88,8 @@ func (p Proxy) MarshalJSON() ([]byte, error) {
return json.Marshal(p.VMessOptions)
case Hysteria2:
return json.Marshal(p.Hysteria2Options)
case AnyTLS:
return json.Marshal(p.AnyTLSOptions)
case Selector:
return json.Marshal(p.SelectorOptions)
case URLTest: