mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
v2rayA dropped allowInsecure years ago: VMess, VLESS and Trojan links carrying it are parsed and the flag ignored, and a self-signed server is reached by pinning its certificate. The three native protocols added in May brought the switch back in their own config, service objects and forms. It goes everywhere: the core's dialers verify or pin (the proto field 5 is reserved), the service no longer parses, stores or exports allow_insecure for them, the forms lose the switch, the codec ignores the parameter, and the quick-start docs say so in six locales. Certificate pinning stays as it was.
128 lines
3.1 KiB
Go
128 lines
3.1 KiB
Go
package serverObj
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"github.com/v2rayA/v2rayA/kernel/coreObj"
|
|
)
|
|
|
|
func init() {
|
|
FromLinkRegister("anytls", NewAnyTLS)
|
|
EmptyRegister("anytls", func() (ServerObj, error) {
|
|
return new(AnyTLS), nil
|
|
})
|
|
}
|
|
|
|
type AnyTLS struct {
|
|
Name string `json:"name"`
|
|
Server string `json:"server"`
|
|
Port int `json:"port"`
|
|
Protocol string `json:"protocol"`
|
|
Link string `json:"link"`
|
|
}
|
|
|
|
func NewAnyTLS(link string) (ServerObj, error) {
|
|
return ParseAnyTLSURL(link)
|
|
}
|
|
|
|
func ParseAnyTLSURL(link string) (data *AnyTLS, err error) {
|
|
u, err := url.Parse(link)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%w: anytls link is not a valid URL; expected anytls://password@host:port", ErrInvalidParameter)
|
|
}
|
|
port, err := strconv.Atoi(u.Port())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%w: anytls link for %q has a missing or invalid port; expected anytls://password@host:port", ErrInvalidParameter, u.Hostname())
|
|
}
|
|
return &AnyTLS{
|
|
Name: u.Fragment,
|
|
Server: u.Hostname(),
|
|
Port: port,
|
|
Protocol: "anytls",
|
|
Link: link,
|
|
}, nil
|
|
}
|
|
|
|
// anytlsSettings holds the settings serialized into the hybrid-core xray config.
|
|
type anytlsSettings struct {
|
|
Address string `json:"address"`
|
|
Port int `json:"port"`
|
|
Password string `json:"password"`
|
|
SNI string `json:"sni,omitempty"`
|
|
MinIdleSessions int `json:"min_idle_sessions,omitempty"`
|
|
PinnedPeerCertificateChainSha256 string `json:"pinned_peer_certificate_chain_sha256,omitempty"`
|
|
VerifyPeerCertByName string `json:"verifyPeerCertByName,omitempty"`
|
|
}
|
|
|
|
func (s *AnyTLS) Configuration(info PriorInfo) (c Configuration, err error) {
|
|
u, err := url.Parse(s.Link)
|
|
if err != nil {
|
|
return c, fmt.Errorf("anytls: parse link: %w", err)
|
|
}
|
|
|
|
password := ""
|
|
if u.User != nil {
|
|
password = u.User.Username()
|
|
}
|
|
q := u.Query()
|
|
sni := q.Get("sni")
|
|
minIdle, _ := strconv.Atoi(q.Get("minIdleSession"))
|
|
|
|
settingsJSON, err := json.Marshal(anytlsSettings{
|
|
Address: s.Server,
|
|
Port: s.Port,
|
|
Password: password,
|
|
SNI: sni,
|
|
MinIdleSessions: minIdle,
|
|
PinnedPeerCertificateChainSha256: q.Get("pinnedPeerCertSha256"),
|
|
VerifyPeerCertByName: q.Get("verifyPeerCertByName"),
|
|
})
|
|
if err != nil {
|
|
return c, fmt.Errorf("anytls: marshal settings: %w", err)
|
|
}
|
|
|
|
return Configuration{
|
|
CoreOutbound: coreObj.OutboundObject{
|
|
Tag: info.Tag,
|
|
Protocol: "anytls",
|
|
Settings: coreObj.Settings{Inlined: settingsJSON},
|
|
},
|
|
UDPSupport: true,
|
|
}, nil
|
|
}
|
|
|
|
func (s *AnyTLS) ExportToURL() string {
|
|
return s.Link
|
|
}
|
|
|
|
func (s *AnyTLS) NeedPluginPort() bool {
|
|
return false
|
|
}
|
|
|
|
func (s *AnyTLS) ProtoToShow() string {
|
|
return fmt.Sprintf("anytls")
|
|
}
|
|
|
|
func (s *AnyTLS) GetProtocol() string {
|
|
return s.Protocol
|
|
}
|
|
|
|
func (s *AnyTLS) GetHostname() string {
|
|
return s.Server
|
|
}
|
|
|
|
func (s *AnyTLS) GetPort() int {
|
|
return s.Port
|
|
}
|
|
|
|
func (s *AnyTLS) GetName() string {
|
|
return s.Name
|
|
}
|
|
|
|
func (s *AnyTLS) SetName(name string) {
|
|
s.Name = name
|
|
}
|