From a920ff432f122a898b1bbef6efe4192d95c0657d Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sat, 18 Feb 2023 01:11:40 +0800 Subject: [PATCH] feat: support stream ciphers for shadowsocks --- .../outbound/dialer/shadowsocks/shadowsocks.go | 17 ++++++++++------- .../dialer/shadowsocksr/shadowsocksr.go | 9 ++++----- component/outbound/dialer/v2ray/v2ray.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/component/outbound/dialer/shadowsocks/shadowsocks.go b/component/outbound/dialer/shadowsocks/shadowsocks.go index 7464dee..457bdc9 100644 --- a/component/outbound/dialer/shadowsocks/shadowsocks.go +++ b/component/outbound/dialer/shadowsocks/shadowsocks.go @@ -44,12 +44,6 @@ func NewShadowsocksFromLink(option *dialer.GlobalOption, iOption dialer.Instance } func (s *Shadowsocks) Dialer(option *dialer.GlobalOption, iOption dialer.InstanceOption) (*dialer.Dialer, error) { - // FIXME: support plain/none. - switch s.Cipher { - case "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305": - default: - return nil, fmt.Errorf("unsupported shadowsocks encryption method: %v", s.Cipher) - } var err error var d netproxy.Dialer switch s.Plugin.Name { @@ -81,7 +75,16 @@ func (s *Shadowsocks) Dialer(option *dialer.GlobalOption, iOption dialer.Instanc default: d = direct.FullconeDirect // Shadowsocks Proxy supports full-cone. } - d, err = protocol.NewDialer("shadowsocks", d, protocol.Header{ + var nextDialerName string + switch s.Cipher { + case "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305": + nextDialerName = "shadowsocks" + case "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-ofb", "aes-192-ofb", "aes-256-ofb", "des-cfb", "bf-cfb", "cast5-cfb", "rc4-md5", "rc4-md5-6", "chacha20", "chacha20-ietf", "salsa20", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "rc4", "none", "plain": + nextDialerName = "shadowsocks_stream" + default: + return nil, fmt.Errorf("unsupported shadowsocks encryption method: %v", s.Cipher) + } + d, err = protocol.NewDialer(nextDialerName, d, protocol.Header{ ProxyAddress: net.JoinHostPort(s.Server, strconv.Itoa(s.Port)), Cipher: s.Cipher, Password: s.Password, diff --git a/component/outbound/dialer/shadowsocksr/shadowsocksr.go b/component/outbound/dialer/shadowsocksr/shadowsocksr.go index eac5bdc..38e724a 100644 --- a/component/outbound/dialer/shadowsocksr/shadowsocksr.go +++ b/component/outbound/dialer/shadowsocksr/shadowsocksr.go @@ -55,11 +55,10 @@ func (s *ShadowsocksR) Dialer(option *dialer.GlobalOption, iOption dialer.Instan } d = obfsDialer d, err = shadowsocks_stream.NewDialer(d, protocol.Header{ - ProxyAddress: net.JoinHostPort(s.Server, strconv.Itoa(s.Port)), - Cipher: s.Cipher, - Password: s.Password, - IsClient: true, - ShouldFullCone: false, + ProxyAddress: net.JoinHostPort(s.Server, strconv.Itoa(s.Port)), + Cipher: s.Cipher, + Password: s.Password, + IsClient: true, }) if err != nil { return nil, err diff --git a/component/outbound/dialer/v2ray/v2ray.go b/component/outbound/dialer/v2ray/v2ray.go index 526ac12..4196311 100644 --- a/component/outbound/dialer/v2ray/v2ray.go +++ b/component/outbound/dialer/v2ray/v2ray.go @@ -148,7 +148,7 @@ func (s *V2Ray) Dialer(option *dialer.GlobalOption, iOption dialer.InstanceOptio Cipher: "aes-128-gcm", Password: s.ID, IsClient: true, - //ShouldFullCone: true, + //Flags: protocol.Flags_VMess_UsePacketAddr, }); err != nil { return nil, err } diff --git a/go.mod b/go.mod index d4d4a7a..15e8d61 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/json-iterator/go v1.1.12 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 - github.com/mzz2017/softwind v0.0.0-20230217163103-acb4981669fe + github.com/mzz2017/softwind v0.0.0-20230217170818-542cba31602f github.com/safchain/ethtool v0.0.0-20230116090318-67cc41908669 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.6.1 diff --git a/go.sum b/go.sum index 1f774a7..d12e1c0 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/mzz2017/disk-bloom v1.0.1 h1:rEF9MiXd9qMW3ibRpqcerLXULoTgRlM21yqqJl1B90M= github.com/mzz2017/disk-bloom v1.0.1/go.mod h1:JLHETtUu44Z6iBmsqzkOtFlRvXSlKnxjwiBRDapizDI= -github.com/mzz2017/softwind v0.0.0-20230217163103-acb4981669fe h1:i2YtHdgl0oYWKixm/kX5skbrhaAQj1ZHR5RZKyqaySY= -github.com/mzz2017/softwind v0.0.0-20230217163103-acb4981669fe/go.mod h1:V8GFOtdpTgzCJtCVXRqjmdDsY+PIhCCx4JpD0zq8Z7I= +github.com/mzz2017/softwind v0.0.0-20230217170818-542cba31602f h1:zxc1LkGfczEwEdnOlaGbIhyVsoL9dWHEL2WQ4pPgC0c= +github.com/mzz2017/softwind v0.0.0-20230217170818-542cba31602f/go.mod h1:V8GFOtdpTgzCJtCVXRqjmdDsY+PIhCCx4JpD0zq8Z7I= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=