Files
v2ray_simple/proxy/tlsConfig.go
e1732a364fed cc758dec66 全面修订代码;完成 grpcSimple包;使用 tag选择编译quic 和 grpc
grpcSimple包的服务端和客户端现在都已完成,且兼容v2ray等内核。
grpcSimple包 简洁、高效,更加科学。暂不支持multiMode。

若 grpc_full 给出,则使用grpc包,否则默认使用 grpcSimple包。
若 noquic给出,则不使用 quic,否则 默认使用 quic。

修复 ws early 失效问题;
2022-04-28 05:41:56 +08:00

97 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package proxy
import (
"net"
"net/url"
"github.com/e1732a364fed/v2ray_simple/advLayer"
"github.com/e1732a364fed/v2ray_simple/tlsLayer"
)
func updateAlpnListByAdvLayer(com ProxyCommon, alpnList []string) (result []string) {
result = alpnList
if adv := com.AdvancedLayer(); adv != "" {
if creator := advLayer.ProtocolsMap[adv]; creator != nil {
if alpn, must := creator.GetDefaultAlpn(); must {
has_alpn := false
for _, a := range alpnList {
if a == alpn {
has_alpn = true
break
}
}
if !has_alpn {
result = append([]string{alpn}, alpnList...)
}
}
}
}
return
}
//use dc.Host, dc.Insecure, dc.Utls, dc.Alpn.
func prepareTLS_forClient(com ProxyCommon, dc *DialConf) error {
alpnList := updateAlpnListByAdvLayer(com, dc.Alpn)
clic := com.getCommon()
if clic == nil {
return nil
}
clic.setTLS_Client(tlsLayer.NewClient(dc.Host, dc.Insecure, dc.Utls, alpnList))
return nil
}
//use lc.Host, lc.TLSCert, lc.TLSKey, lc.Insecure, lc.Alpn.
func prepareTLS_forServer(com ProxyCommon, lc *ListenConf) error {
serc := com.getCommon()
if serc == nil {
return nil
}
alpnList := updateAlpnListByAdvLayer(com, lc.Alpn)
tlsserver, err := tlsLayer.NewServer(lc.Host, lc.TLSCert, lc.TLSKey, lc.Insecure, alpnList)
if err == nil {
serc.setTLS_Server(tlsserver)
} else {
return err
}
return nil
}
//给 ProxyCommon 的tls做一些配置上的准备从url读取配置
func prepareTLS_forProxyCommon_withURL(u *url.URL, isclient bool, com ProxyCommon) error {
insecureStr := u.Query().Get("insecure")
insecure := false
if insecureStr != "" && insecureStr != "false" && insecureStr != "0" {
insecure = true
}
if isclient {
utlsStr := u.Query().Get("utls")
useUtls := utlsStr != "" && utlsStr != "false" && utlsStr != "0"
com.getCommon().setTLS_Client(tlsLayer.NewClient(u.Host, insecure, useUtls, nil))
} else {
certFile := u.Query().Get("cert")
keyFile := u.Query().Get("key")
hostAndPort := u.Host
sni, _, _ := net.SplitHostPort(hostAndPort)
tlsserver, err := tlsLayer.NewServer(sni, certFile, keyFile, insecure, nil)
if err == nil {
com.getCommon().setTLS_Server(tlsserver)
} else {
return err
}
}
return nil
}