diff --git a/examples/ws.server.toml b/examples/ws.server.toml index 54b0f44..1cf1205 100644 --- a/examples/ws.server.toml +++ b/examples/ws.server.toml @@ -8,9 +8,11 @@ fallback = ":80" cert = "cert.pem" key = "cert.key" advancedLayer = "ws" -path = "/ohmygod_verysimple_is_very_simple" +path = "/ohmygod_verysimple_is_very_simple" # 这个path必须要给出,就算你path是默认的 "/", 也要写在这里。 # early = true +# 关于ws+ header的配置,请参考 httpheader.client.toml 和 httpheader.server.toml 的注释 + [[dial]] protocol = "direct" diff --git a/proxy/tlsConfig.go b/proxy/tlsConfig.go index 6372081..11b68c2 100644 --- a/proxy/tlsConfig.go +++ b/proxy/tlsConfig.go @@ -6,6 +6,7 @@ import ( "github.com/e1732a364fed/v2ray_simple/advLayer" "github.com/e1732a364fed/v2ray_simple/tlsLayer" "github.com/e1732a364fed/v2ray_simple/utils" + "go.uber.org/zap" ) func updateAlpnListByAdvLayer(com BaseInterface, alpnList []string) (result []string) { @@ -124,13 +125,25 @@ func getTlsMinVerFromExtra(extra map[string]any) uint16 { } func getTlsMaxVerFromExtra(extra map[string]any) uint16 { + + fromStr := func(str string) uint16 { + switch str { + case "1.2": + return tls.VersionTLS12 + case "1.3": + return tls.VersionTLS13 + default: + if ce := utils.CanLogErr("parse tls version failed"); ce != nil { + ce.Write(zap.String("given", str)) + } + return tls.VersionTLS13 + } + } + if len(extra) > 0 { if thing := extra["tls_maxVersion"]; thing != nil { if str, ok := (thing).(string); ok && len(str) > 0 { - switch str { - case "1.2": - return tls.VersionTLS12 - } + return fromStr(str) } } } @@ -145,6 +158,12 @@ func getTlsRejectUnknownSniFromExtra(extra map[string]any) bool { return true } } + + if thing := extra["rejectUnknownSni"]; thing != nil { + if is, ok := utils.AnyToBool(thing); ok && is { + return true + } + } } return false diff --git a/proxy/vmess/client.go b/proxy/vmess/client.go index 2da6dff..53b15bb 100644 --- a/proxy/vmess/client.go +++ b/proxy/vmess/client.go @@ -74,7 +74,9 @@ func (ClientCreator) NewClient(dc *proxy.DialConf) (proxy.Client, error) { if err != nil { return nil, err } - c := &Client{} + c := &Client{ + use_mux: dc.Mux, + } c.V2rayUser = utils.V2rayUser(uuid) c.opt = OptChunkStream @@ -94,12 +96,23 @@ type Client struct { opt byte security byte + use_mux bool } func (*Client) GetCreator() proxy.ClientCreator { return ClientCreator{} } +func (c *Client) HasInnerMux() (int, string) { + if c.use_mux { + return 2, "simplesocks" + + } else { + return 0, "" + + } +} + func (c *Client) specifySecurityByStr(security string) error { security = strings.ToLower(security) switch security { @@ -168,14 +181,19 @@ func (c *Client) commonHandshake(underlay net.Conn, firstPayload []byte, target var err error - // Request - if target.IsUDP() { - err = conn.handshake(CmdUDP, firstPayload) - conn.theTarget = target + if c.use_mux { + err = conn.handshake(CMDMux_VS, firstPayload) } else { - err = conn.handshake(CmdTCP, firstPayload) + // Request + if target.IsUDP() { + err = conn.handshake(CmdUDP, firstPayload) + conn.theTarget = target + } else { + err = conn.handshake(CmdTCP, firstPayload) + + } } if err != nil { diff --git a/proxy/vmess/server.go b/proxy/vmess/server.go index 9cea0ab..dd0d01c 100644 --- a/proxy/vmess/server.go +++ b/proxy/vmess/server.go @@ -150,6 +150,10 @@ func (s *Server) addUser(u utils.V2rayUser) { s.authPairList = append(s.authPairList, p) } +func (*Server) HasInnerMux() (int, string) { + return 1, "simplesocks" +} + func (s *Server) Handshake(underlay net.Conn) (tcpConn net.Conn, msgConn netLayer.MsgConn, targetAddr netLayer.Addr, returnErr error) { if err := proxy.SetCommonReadTimeout(underlay); err != nil { returnErr = err @@ -230,6 +234,8 @@ func (s *Server) Handshake(underlay net.Conn) (tcpConn net.Conn, msgConn netLaye return } + var ismux bool + switch sc.cmd { case CmdTCP, CmdUDP: ad, err := netLayer.V2rayGetAddrFrom(aeadDataBuf) @@ -248,6 +254,15 @@ func (s *Server) Handshake(underlay net.Conn) (tcpConn net.Conn, msgConn netLaye case cmd_muxcool_unimplemented: returnErr = utils.ErrInErr{ErrDesc: "Vmess mux.cool is not supported by verysimple ", ErrDetail: utils.ErrInvalidData} + case CMDMux_VS: + ismux = true + + _, err := netLayer.V2rayGetAddrFrom(aeadDataBuf) + if err != nil { + returnErr = utils.NumErr{E: utils.ErrInvalidData, N: 4} + return + } + default: returnErr = utils.ErrInErr{ErrDesc: "Vmess Invalid command ", ErrDetail: utils.ErrInvalidData, Data: sc.cmd} @@ -284,6 +299,22 @@ func (s *Server) Handshake(underlay net.Conn) (tcpConn net.Conn, msgConn netLaye sc.aead_encodeRespHeader(buf) sc.firstWriteBuf = buf + if ismux { + + mh := &proxy.MuxMarkerConn{ + ReadWrapper: netLayer.ReadWrapper{ + Conn: sc, + }, + } + + if l := remainBuf.Len(); l > 0 { + mh.RemainFirstBufLen = l + mh.OptionalReader = io.MultiReader(remainBuf, underlay) + } + + return mh, nil, targetAddr, nil + } + if sc.cmd == CmdTCP { tcpConn = sc diff --git a/proxy/vmess/vmess.go b/proxy/vmess/vmess.go index 7994541..a7d19fe 100644 --- a/proxy/vmess/vmess.go +++ b/proxy/vmess/vmess.go @@ -62,6 +62,7 @@ const ( CmdUDP byte = 2 cmd_muxcool_unimplemented byte = 3 //mux.cool的command的定义 在 v2ray源代码的 common/protocol/headers.go 的 RequestCommandMux。 + CMDMux_VS byte = 4 //新定义的值,用于使用我们vs的mux方式 ) var getkeyBs = []byte("c48619fe-8f02-49e0-b9e9-edf763e17e21")