Commit 5fb4054f authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:ginuerzh/gost

parents bc5af161 937b27dd
Pipeline #10029 passed with stages
in 5 minutes and 16 seconds
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"net/url" "net/url"
"time" "time"
"github.com/ginuerzh/gosocks5" "github.com/go-gost/gosocks5"
) )
// Client is a proxy client. // Client is a proxy client.
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"net" "net"
"strconv" "strconv"
"github.com/ginuerzh/gosocks5" "github.com/go-gost/gosocks5"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks" ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
) )
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"fmt" "fmt"
"github.com/ginuerzh/gosocks5" "github.com/go-gost/gosocks5"
"github.com/go-log/log" "github.com/go-log/log"
smux "github.com/xtaci/smux" smux "github.com/xtaci/smux"
) )
......
module github.com/ginuerzh/gost module github.com/ginuerzh/gost
go 1.16 go 1.17
require ( require (
git.torproject.org/pluggable-transports/goptlib.git v0.0.0-20180321061416-7d56ec4f381e git.torproject.org/pluggable-transports/goptlib.git v1.2.0
git.torproject.org/pluggable-transports/obfs4.git v0.0.0-20181103133120-08f4d470188e
github.com/LiamHaworth/go-tproxy v0.0.0-20190726054950-ef7efd7f24ed github.com/LiamHaworth/go-tproxy v0.0.0-20190726054950-ef7efd7f24ed
github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/coreos/go-iptables v0.5.0 // indirect
github.com/docker/libcontainer v2.2.1+incompatible github.com/docker/libcontainer v2.2.1+incompatible
github.com/ginuerzh/gosocks4 v0.0.1 github.com/go-gost/gosocks4 v0.0.1
github.com/ginuerzh/gosocks5 v0.2.0 github.com/go-gost/gosocks5 v0.3.0
github.com/ginuerzh/tls-dissector v0.0.2-0.20200224064855-24ab2b3a3796 github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7
github.com/go-gost/relay v0.1.0 github.com/go-gost/tls-dissector v0.0.2-0.20211125135007-2b5d5bd9c07e
github.com/go-log/log v0.2.0 github.com/go-log/log v0.2.0
github.com/gobwas/glob v0.2.3 github.com/gobwas/glob v0.2.3
github.com/google/gopacket v1.1.19 // indirect
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/klauspost/compress v1.13.6
github.com/klauspost/compress v1.11.12 github.com/lucas-clemente/quic-go v0.24.0
github.com/klauspost/reedsolomon v1.9.12 // indirect github.com/miekg/dns v1.1.43
github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f // indirect
github.com/lucas-clemente/quic-go v0.10.0
github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced // indirect
github.com/miekg/dns v1.1.41
github.com/milosgajdos/tenus v0.0.3 github.com/milosgajdos/tenus v0.0.3
github.com/pkg/errors v0.9.1 // indirect
github.com/ryanuber/go-glob v1.0.0 github.com/ryanuber/go-glob v1.0.0
github.com/shadowsocks/go-shadowsocks2 v0.1.4 github.com/shadowsocks/go-shadowsocks2 v0.1.5
github.com/shadowsocks/shadowsocks-go v0.0.0-20170121203516-97a5c71f80ba github.com/shadowsocks/shadowsocks-go v0.0.0-20200409064450-3e585ff90601
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
github.com/tjfoc/gmsm v1.4.0 // indirect
github.com/xtaci/kcp-go v5.4.20+incompatible github.com/xtaci/kcp-go v5.4.20+incompatible
github.com/xtaci/smux v1.5.15 github.com/xtaci/smux v1.5.16
github.com/xtaci/tcpraw v1.2.25 github.com/xtaci/tcpraw v1.2.25
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 gitlab.com/yawning/obfs4.git v0.0.0-20210511220700-e330d1b7024b
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
golang.org/x/text v0.3.5 // indirect golang.org/x/net v0.0.0-20211215060638-4ddde0e984e9
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/coreos/go-iptables v0.6.0 // indirect
github.com/dchest/siphash v1.2.2 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/klauspost/reedsolomon v1.9.15 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
github.com/tjfoc/gmsm v1.4.1 // indirect
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
) )
This diff is collapsed.
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"net/url" "net/url"
"time" "time"
"github.com/ginuerzh/gosocks4" "github.com/go-gost/gosocks4"
"github.com/ginuerzh/gosocks5" "github.com/go-gost/gosocks5"
"github.com/go-log/log" "github.com/go-log/log"
) )
......
...@@ -20,9 +20,9 @@ import ( ...@@ -20,9 +20,9 @@ import (
"github.com/go-log/log" "github.com/go-log/log"
pt "git.torproject.org/pluggable-transports/goptlib.git" pt "git.torproject.org/pluggable-transports/goptlib.git"
"git.torproject.org/pluggable-transports/obfs4.git/transports/base" "gitlab.com/yawning/obfs4.git/transports/base"
"git.torproject.org/pluggable-transports/obfs4.git/transports/obfs4" "gitlab.com/yawning/obfs4.git/transports/obfs4"
dissector "github.com/ginuerzh/tls-dissector" dissector "github.com/go-gost/tls-dissector"
) )
const ( const (
......
package gost package gost
import ( import (
"context"
"crypto/aes" "crypto/aes"
"crypto/cipher" "crypto/cipher"
"crypto/rand" "crypto/rand"
...@@ -21,7 +22,7 @@ type quicSession struct { ...@@ -21,7 +22,7 @@ type quicSession struct {
} }
func (session *quicSession) GetConn() (*quicConn, error) { func (session *quicSession) GetConn() (*quicConn, error) {
stream, err := session.session.OpenStreamSync() stream, err := session.session.OpenStreamSync(context.Background())
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -33,7 +34,7 @@ func (session *quicSession) GetConn() (*quicConn, error) { ...@@ -33,7 +34,7 @@ func (session *quicSession) GetConn() (*quicConn, error) {
} }
func (session *quicSession) Close() error { func (session *quicSession) Close() error {
return session.session.Close() return session.session.CloseWithError(quic.ApplicationErrorCode(0), "closed")
} }
type quicTransporter struct { type quicTransporter struct {
...@@ -139,15 +140,15 @@ func (tr *quicTransporter) initSession(addr string, conn net.Conn, config *QUICC ...@@ -139,15 +140,15 @@ func (tr *quicTransporter) initSession(addr string, conn net.Conn, config *QUICC
return nil, err return nil, err
} }
quicConfig := &quic.Config{ quicConfig := &quic.Config{
HandshakeTimeout: config.Timeout, HandshakeIdleTimeout: config.Timeout,
KeepAlive: config.KeepAlive, KeepAlive: config.KeepAlive,
IdleTimeout: config.IdleTimeout,
Versions: []quic.VersionNumber{ Versions: []quic.VersionNumber{
quic.VersionGQUIC43, quic.Version1,
quic.VersionGQUIC39, quic.VersionDraft29,
}, },
MaxIdleTimeout: config.IdleTimeout,
} }
session, err := quic.Dial(udpConn, udpAddr, addr, config.TLSConfig, quicConfig) session, err := quic.Dial(udpConn, udpAddr, addr, tlsConfigQUICALPN(config.TLSConfig), quicConfig)
if err != nil { if err != nil {
log.Logf("quic dial %s: %v", addr, err) log.Logf("quic dial %s: %v", addr, err)
return nil, err return nil, err
...@@ -180,16 +181,19 @@ func QUICListener(addr string, config *QUICConfig) (Listener, error) { ...@@ -180,16 +181,19 @@ func QUICListener(addr string, config *QUICConfig) (Listener, error) {
config = &QUICConfig{} config = &QUICConfig{}
} }
quicConfig := &quic.Config{ quicConfig := &quic.Config{
HandshakeTimeout: config.Timeout, HandshakeIdleTimeout: config.Timeout,
KeepAlive: config.KeepAlive, KeepAlive: config.KeepAlive,
IdleTimeout: config.IdleTimeout, MaxIdleTimeout: config.IdleTimeout,
Versions: []quic.VersionNumber{
quic.Version1,
quic.VersionDraft29,
},
} }
tlsConfig := config.TLSConfig tlsConfig := config.TLSConfig
if tlsConfig == nil { if tlsConfig == nil {
tlsConfig = DefaultTLSConfig tlsConfig = DefaultTLSConfig
} }
var conn net.PacketConn var conn net.PacketConn
udpAddr, err := net.ResolveUDPAddr("udp", addr) udpAddr, err := net.ResolveUDPAddr("udp", addr)
...@@ -206,7 +210,7 @@ func QUICListener(addr string, config *QUICConfig) (Listener, error) { ...@@ -206,7 +210,7 @@ func QUICListener(addr string, config *QUICConfig) (Listener, error) {
conn = &quicCipherConn{UDPConn: lconn, key: config.Key} conn = &quicCipherConn{UDPConn: lconn, key: config.Key}
} }
ln, err := quic.Listen(conn, tlsConfig, quicConfig) ln, err := quic.Listen(conn, tlsConfigQUICALPN(tlsConfig), quicConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -223,7 +227,7 @@ func QUICListener(addr string, config *QUICConfig) (Listener, error) { ...@@ -223,7 +227,7 @@ func QUICListener(addr string, config *QUICConfig) (Listener, error) {
func (l *quicListener) listenLoop() { func (l *quicListener) listenLoop() {
for { for {
session, err := l.ln.Accept() session, err := l.ln.Accept(context.Background())
if err != nil { if err != nil {
log.Log("[quic] accept:", err) log.Log("[quic] accept:", err)
l.errChan <- err l.errChan <- err
...@@ -239,10 +243,10 @@ func (l *quicListener) sessionLoop(session quic.Session) { ...@@ -239,10 +243,10 @@ func (l *quicListener) sessionLoop(session quic.Session) {
defer log.Logf("[quic] %s >-< %s", session.RemoteAddr(), session.LocalAddr()) defer log.Logf("[quic] %s >-< %s", session.RemoteAddr(), session.LocalAddr())
for { for {
stream, err := session.AcceptStream() stream, err := session.AcceptStream(context.Background())
if err != nil { if err != nil {
log.Log("[quic] accept stream:", err) log.Log("[quic] accept stream:", err)
session.Close() session.CloseWithError(quic.ApplicationErrorCode(0), "closed")
return return
} }
...@@ -362,3 +366,13 @@ func (conn *quicCipherConn) decrypt(data []byte) ([]byte, error) { ...@@ -362,3 +366,13 @@ func (conn *quicCipherConn) decrypt(data []byte) ([]byte, error) {
nonce, ciphertext := data[:nonceSize], data[nonceSize:] nonce, ciphertext := data[:nonceSize], data[nonceSize:]
return gcm.Open(nil, nonce, ciphertext, nil) return gcm.Open(nil, nonce, ciphertext, nil)
} }
func tlsConfigQUICALPN(tlsConfig *tls.Config) *tls.Config {
if tlsConfig == nil {
panic("quic: tlsconfig is nil")
}
tlsConfigQUIC := &tls.Config{}
*tlsConfigQUIC = *tlsConfig
tlsConfigQUIC.NextProtos = []string{"http/3", "quic/v1"}
return tlsConfigQUIC
}
...@@ -84,7 +84,7 @@ func (c *relayConnector) ConnectContext(ctx context.Context, conn net.Conn, netw ...@@ -84,7 +84,7 @@ func (c *relayConnector) ConnectContext(ctx context.Context, conn net.Conn, netw
atype = relay.AddrIPv4 atype = relay.AddrIPv4
} }
req.Features = append(req.Features, &relay.TargetAddrFeature{ req.Features = append(req.Features, &relay.AddrFeature{
AType: atype, AType: atype,
Host: host, Host: host,
Port: uint16(nport), Port: uint16(nport),
...@@ -155,8 +155,8 @@ func (h *relayHandler) Handle(conn net.Conn) { ...@@ -155,8 +155,8 @@ func (h *relayHandler) Handle(conn net.Conn) {
feature := f.(*relay.UserAuthFeature) feature := f.(*relay.UserAuthFeature)
user, pass = feature.Username, feature.Password user, pass = feature.Username, feature.Password
} }
if f.Type() == relay.FeatureTargetAddr { if f.Type() == relay.FeatureAddr {
feature := f.(*relay.TargetAddrFeature) feature := f.(*relay.AddrFeature)
raddr = net.JoinHostPort(feature.Host, strconv.Itoa(int(feature.Port))) raddr = net.JoinHostPort(feature.Host, strconv.Itoa(int(feature.Port)))
} }
} }
......
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
"sync" "sync"
"github.com/asaskevich/govalidator" "github.com/asaskevich/govalidator"
dissector "github.com/ginuerzh/tls-dissector" dissector "github.com/go-gost/tls-dissector"
"github.com/go-log/log" "github.com/go-log/log"
) )
......
...@@ -13,8 +13,8 @@ import ( ...@@ -13,8 +13,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/ginuerzh/gosocks4" "github.com/go-gost/gosocks4"
"github.com/ginuerzh/gosocks5" "github.com/go-gost/gosocks5"
"github.com/go-log/log" "github.com/go-log/log"
smux "github.com/xtaci/smux" smux "github.com/xtaci/smux"
) )
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"net/url" "net/url"
"time" "time"
"github.com/ginuerzh/gosocks5" "github.com/go-gost/gosocks5"
"github.com/go-log/log" "github.com/go-log/log"
"github.com/shadowsocks/go-shadowsocks2/core" "github.com/shadowsocks/go-shadowsocks2/core"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks" ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
...@@ -580,7 +580,7 @@ func (c *shadowCipher) StreamConn(conn net.Conn) net.Conn { ...@@ -580,7 +580,7 @@ func (c *shadowCipher) StreamConn(conn net.Conn) net.Conn {
} }
func (c *shadowCipher) PacketConn(conn net.PacketConn) net.PacketConn { func (c *shadowCipher) PacketConn(conn net.PacketConn) net.PacketConn {
return ss.NewSecurePacketConn(conn, c.cipher.Copy(), false) return ss.NewSecurePacketConn(conn, c.cipher.Copy())
} }
func initShadowCipher(info *url.Userinfo) (cipher core.Cipher) { func initShadowCipher(info *url.Userinfo) (cipher core.Cipher) {
......
package gost package gost
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
"syscall"
"github.com/docker/libcontainer/netlink" "github.com/docker/libcontainer/netlink"
"github.com/go-log/log" "github.com/go-log/log"
...@@ -149,7 +151,7 @@ func addTunRoutes(ifName string, routes ...IPRoute) error { ...@@ -149,7 +151,7 @@ func addTunRoutes(ifName string, routes ...IPRoute) error {
} }
cmd := fmt.Sprintf("ip route add %s dev %s", route.Dest.String(), ifName) cmd := fmt.Sprintf("ip route add %s dev %s", route.Dest.String(), ifName)
log.Logf("[tun] %s", cmd) log.Logf("[tun] %s", cmd)
if err := netlink.AddRoute(route.Dest.String(), "", "", ifName); err != nil { if err := netlink.AddRoute(route.Dest.String(), "", "", ifName); err != nil && !errors.Is(err, syscall.EEXIST) {
return fmt.Errorf("%s: %v", cmd, err) return fmt.Errorf("%s: %v", cmd, err)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment