mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
修订tls配置格式,代码,移除utls项,添加 tls_type项。为shadowTls做准备
This commit is contained in:
@@ -230,7 +230,7 @@ func interactively_generateConf(confClient, confServer *proxy.StandardConf) {
|
||||
clientDial.Protocol = theProtocol
|
||||
clientDial.TLS = true
|
||||
clientDial.Tag = "my_proxy"
|
||||
clientDial.Utls = true
|
||||
//clientDial.Utls = true
|
||||
|
||||
select4 := promptui.Select{
|
||||
Label: "请选择你客户端拨号想使用的高级层(与服务端监听的高级层相同)",
|
||||
|
||||
@@ -222,7 +222,7 @@ func (dm *DNSMachine) SetDefaultConn(c net.Conn, addr *Addr) {
|
||||
dm.defaultConn.raddr = addr
|
||||
}
|
||||
|
||||
// 添加一个 特定的DNS服务器 , name为该dns服务器的名称. 若第一次调用, 则会设为 dm.DefaultConn
|
||||
// 添加一个 特定的DNS服务器 , name为该dns服务器的名称. 若dm.DefaultConn.Conn为空, 则会设为 dm.DefaultConn
|
||||
func (dm *DNSMachine) AddNewServer(name string, addr *Addr) error {
|
||||
|
||||
if dm.defaultConn.Conn == nil { //若未配置过 DefaultConn
|
||||
|
||||
@@ -9,21 +9,21 @@ import (
|
||||
)
|
||||
|
||||
// 用于 tproxy 或 tun/tap 这种 只有 网络层 和传输层的情况
|
||||
type LesserConf struct {
|
||||
Addr string
|
||||
Tag string
|
||||
UseSniffing bool
|
||||
Fullcone bool
|
||||
}
|
||||
// type LesserConf struct {
|
||||
// Addr string
|
||||
// Tag string
|
||||
// UseSniffing bool
|
||||
// Fullcone bool
|
||||
// }
|
||||
|
||||
// CommonConf is the common part of ListenConf and DialConf.
|
||||
type CommonConf struct {
|
||||
Tag string `toml:"tag"` //可选
|
||||
|
||||
Extra map[string]any `toml:"extra"` //用于包含任意其它数据.虽然本包自己定义的协议肯定都是已知的,但是如果其他人使用了本包的话,那就有可能添加一些 新协议 特定的数据.
|
||||
Extra map[string]any `toml:"extra"` //用于包含任意其它数据.虽然本包自己定义的协议肯定都是已知的,但是如果其他人使用了本包的话,那就有可能添加一些 新协议 特定的数据. 而且这也便于扁平化,避免出现大量各种子块。任何子块内容都放在extra中,比如 quic的就是 extra.quic_xxx
|
||||
|
||||
//tls 的最低版本号配置填在这里:
|
||||
//extra = { tls_minVersion = "1.2" }
|
||||
//extra = { tls_minVersion = "1.2" }, 或 extra.tls_minVersion = "1.2"
|
||||
|
||||
/////////////////// 网络层 ///////////////////
|
||||
|
||||
@@ -47,6 +47,7 @@ type CommonConf struct {
|
||||
/////////////////// tls层 ///////////////////
|
||||
|
||||
TLS bool `toml:"tls"` //tls层; 可选. 如果不使用 's' 后缀法,则还可以配置这一项来更清晰地标明使用tls
|
||||
TlsType string `toml:"tls_type"` //可选,可以为 utls或者shadowTls, 若不给出或为空, 则为golang的标准tls. utls 只在客户端有效。
|
||||
Insecure bool `toml:"insecure"` //tls 是否安全
|
||||
Alpn []string `toml:"alpn"`
|
||||
|
||||
@@ -142,10 +143,7 @@ type DialConf struct {
|
||||
CommonConf
|
||||
|
||||
SendThrough string `toml:"sendThrough"` //可选,用于发送数据的 IP 地址, 可以是ip:port, 或者 tcp:ip:port\nudp:ip:port
|
||||
|
||||
Utls bool `toml:"utls"` //是否使用 uTls 库 替换 go官方tls库
|
||||
|
||||
Mux bool `toml:"use_mux"` //是否使用内层mux。在某些支持mux命令的协议中(vless v1/trojan), 开启此开关会让 dial 使用 内层mux。
|
||||
Mux bool `toml:"use_mux"` //是否使用内层mux。在某些支持mux命令的协议中(vless v1/trojan), 开启此开关会让 dial 使用 内层mux。
|
||||
}
|
||||
|
||||
type SniffConf struct {
|
||||
|
||||
@@ -243,7 +243,8 @@ func URLToDialConf(u *url.URL, conf *DialConf) error {
|
||||
|
||||
if conf.TLS {
|
||||
conf.Insecure = utils.QueryPositive(q, "insecure")
|
||||
conf.Utls = utils.QueryPositive(q, "utls")
|
||||
//conf.Utls = utils.QueryPositive(q, "utls")
|
||||
conf.TlsType = q.Get("tls_type")
|
||||
|
||||
}
|
||||
|
||||
@@ -364,8 +365,11 @@ func ToStandardUrl(cc *CommonConf, dc *DialConf, lc *ListenConf) string {
|
||||
if cc.Insecure {
|
||||
q.Add("insecure", "true")
|
||||
}
|
||||
if dc != nil && dc.Utls {
|
||||
q.Add("utls", "true")
|
||||
// if dc != nil && dc.Utls {
|
||||
// q.Add("utls", "true")
|
||||
// }
|
||||
if dc.TlsType != "" {
|
||||
q.Add("tls_type", dc.TlsType)
|
||||
}
|
||||
if cc.TLSCert != "" {
|
||||
q.Add("cert", cc.TLSCert)
|
||||
|
||||
@@ -65,9 +65,10 @@ func prepareTLS_forClient(com BaseInterface, dc *DialConf) error {
|
||||
}
|
||||
|
||||
conf := tlsLayer.Conf{
|
||||
Host: dc.Host,
|
||||
Insecure: dc.Insecure,
|
||||
Use_uTls: dc.Utls,
|
||||
Host: dc.Host,
|
||||
Insecure: dc.Insecure,
|
||||
//Use_uTls: dc.Utls,
|
||||
Tls_type: tlsLayer.StrToType(dc.TlsType),
|
||||
AlpnList: alpnList,
|
||||
CertConf: certConf,
|
||||
Minver: getTlsMinVerFromExtra(dc.Extra),
|
||||
@@ -94,6 +95,8 @@ func prepareTLS_forServer(com BaseInterface, lc *ListenConf) error {
|
||||
CertConf: &tlsLayer.CertConf{
|
||||
CertFile: lc.TLSCert, KeyFile: lc.TLSKey, CA: lc.CA,
|
||||
},
|
||||
Tls_type: tlsLayer.StrToType(lc.TlsType),
|
||||
|
||||
Insecure: lc.Insecure,
|
||||
AlpnList: alpnList,
|
||||
Minver: getTlsMinVerFromExtra(lc.Extra),
|
||||
|
||||
@@ -16,27 +16,28 @@ import (
|
||||
type Client struct {
|
||||
tlsConfig *tls.Config
|
||||
uTlsConfig utls.Config
|
||||
use_uTls bool
|
||||
alpnList []string
|
||||
//use_uTls bool
|
||||
tlsType int
|
||||
alpnList []string
|
||||
}
|
||||
|
||||
func NewClient(conf Conf) *Client {
|
||||
|
||||
c := &Client{
|
||||
use_uTls: conf.Use_uTls,
|
||||
//use_uTls: conf.Use_uTls,
|
||||
tlsType: conf.Tls_type,
|
||||
}
|
||||
|
||||
c.alpnList = conf.AlpnList
|
||||
|
||||
if conf.Use_uTls {
|
||||
|
||||
switch conf.Tls_type {
|
||||
case uTls_t:
|
||||
c.uTlsConfig = GetUTlsConfig(conf)
|
||||
|
||||
if ce := utils.CanLogInfo("Using uTls and Chrome fingerprint for"); ce != nil {
|
||||
ce.Write(zap.String("host", conf.Host))
|
||||
}
|
||||
} else {
|
||||
|
||||
default:
|
||||
c.tlsConfig = GetTlsConfig(false, conf)
|
||||
|
||||
}
|
||||
@@ -46,7 +47,8 @@ func NewClient(conf Conf) *Client {
|
||||
|
||||
func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) {
|
||||
|
||||
if c.use_uTls {
|
||||
switch c.tlsType {
|
||||
case uTls_t:
|
||||
configCopy := c.uTlsConfig //发现uTlsConfig竟然没法使用指针,握手一次后配置文件就会被污染,只能拷贝
|
||||
//否则的话接下来的握手客户端会报错: tls: CurvePreferences includes unsupported curve
|
||||
|
||||
@@ -60,8 +62,7 @@ func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) {
|
||||
ptr: unsafe.Pointer(utlsConn.Conn),
|
||||
tlsPackageType: utlsPackage,
|
||||
}
|
||||
|
||||
} else {
|
||||
case tls_t:
|
||||
officialConn := tls.Client(underlay, c.tlsConfig)
|
||||
err = officialConn.Handshake()
|
||||
if err != nil {
|
||||
@@ -73,7 +74,9 @@ func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) {
|
||||
ptr: unsafe.Pointer(officialConn),
|
||||
tlsPackageType: official,
|
||||
}
|
||||
case shadowTls_t:
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
|
||||
type Server struct {
|
||||
tlsConfig *tls.Config
|
||||
|
||||
isShadow bool
|
||||
}
|
||||
|
||||
// 如 certFile, keyFile 有一项没给出,则会自动生成随机证书
|
||||
@@ -34,12 +36,18 @@ func NewServer(conf Conf) (*Server, error) {
|
||||
|
||||
s := &Server{
|
||||
tlsConfig: GetTlsConfig(true, conf),
|
||||
isShadow: conf.Tls_type == shadowTls_t,
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Server) Handshake(underlay net.Conn) (tlsConn *Conn, err error) {
|
||||
if s.isShadow {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
rawTlsConn := tls.Server(underlay, s.tlsConfig)
|
||||
err = rawTlsConn.Handshake()
|
||||
if err != nil {
|
||||
|
||||
@@ -8,6 +8,7 @@ package tlsLayer
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/e1732a364fed/v2ray_simple/utils"
|
||||
@@ -15,6 +16,26 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
tls_t = iota
|
||||
uTls_t
|
||||
shadowTls_t
|
||||
)
|
||||
|
||||
func StrToType(str string) int {
|
||||
str = strings.ToLower(str)
|
||||
switch str {
|
||||
default:
|
||||
fallthrough
|
||||
case "", "tls", "gotls":
|
||||
return tls_t
|
||||
case "utls":
|
||||
return uTls_t
|
||||
case "shadow", "shadowtls":
|
||||
return shadowTls_t
|
||||
}
|
||||
}
|
||||
|
||||
type Conf struct {
|
||||
Host string
|
||||
Insecure bool
|
||||
@@ -23,7 +44,9 @@ type Conf struct {
|
||||
AlpnList []string
|
||||
CertConf *CertConf
|
||||
|
||||
Use_uTls bool //only client
|
||||
Tls_type int
|
||||
|
||||
//Use_uTls bool //only client
|
||||
RejectUnknownSni bool //only server
|
||||
CipherSuites []uint16
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user