diff --git a/protocol/shadowsocks/service.go b/protocol/shadowsocks/service.go index 14716a5..63d4076 100644 --- a/protocol/shadowsocks/service.go +++ b/protocol/shadowsocks/service.go @@ -41,7 +41,6 @@ func (e *ServerConnError) Error() string { } type ServerPacketError struct { - N.PacketConn Source M.Socksaddr Cause error } diff --git a/protocol/shadowsocks/shadowaead/service.go b/protocol/shadowsocks/shadowaead/service.go index dd47ce9..8db96b3 100644 --- a/protocol/shadowsocks/shadowaead/service.go +++ b/protocol/shadowsocks/shadowaead/service.go @@ -201,7 +201,7 @@ func (c *serverConn) WriterReplaceable() bool { func (s *Service) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(conn, buffer, metadata) if err != nil { - err = &shadowsocks.ServerPacketError{PacketConn: conn, Source: metadata.Source, Cause: err} + err = &shadowsocks.ServerPacketError{Source: metadata.Source, Cause: err} } return err } diff --git a/protocol/shadowsocks/shadowaead_2022/protocol.go b/protocol/shadowsocks/shadowaead_2022/protocol.go index e9ec7aa..999cef9 100644 --- a/protocol/shadowsocks/shadowaead_2022/protocol.go +++ b/protocol/shadowsocks/shadowaead_2022/protocol.go @@ -67,7 +67,6 @@ var List = []string{ func New(method string, pskList [][]byte, password string, secureRNG io.Reader) (shadowsocks.Method, error) { m := &Method{ name: method, - pskList: pskList, secureRNG: secureRNG, replayFilter: replay.NewCuckoo(60), } @@ -125,6 +124,7 @@ func New(method string, pskList [][]byte, password string, secureRNG io.Reader) m.udpCipher = newXChacha20Poly1305(pskList[0]) } + m.pskList = pskList return m, nil } @@ -479,9 +479,6 @@ func (c *clientPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksad if err != nil { return err } - if err != nil { - return err - } if c.udpCipher != nil { c.udpCipher.Seal(buffer.Index(dataIndex), buffer.To(dataIndex), buffer.From(dataIndex), nil) buffer.Extend(c.udpCipher.Overhead()) @@ -687,9 +684,6 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { if err != nil { return } - if err != nil { - return - } if c.udpCipher != nil { c.udpCipher.Seal(buffer.Index(dataIndex), buffer.To(dataIndex), buffer.From(dataIndex), nil) buffer.Extend(c.udpCipher.Overhead()) diff --git a/protocol/shadowsocks/shadowaead_2022/service.go b/protocol/shadowsocks/shadowaead_2022/service.go index e9a12f0..dd2d282 100644 --- a/protocol/shadowsocks/shadowaead_2022/service.go +++ b/protocol/shadowsocks/shadowaead_2022/service.go @@ -71,17 +71,14 @@ func NewService(method string, psk []byte, password string, secureRNG io.Reader, s.constructor = newChacha20Poly1305 } - if len(psk) == s.keySaltLength { - s.psk = psk - } else if len(psk) != 0 { - if len(psk) < s.keySaltLength { - return nil, shadowsocks.ErrBadKey - } - s.psk = Key(psk, s.keySaltLength) + if len(psk) < s.keySaltLength { + return nil, shadowsocks.ErrBadKey + } else if len(psk) > s.keySaltLength { + psk = Key(psk, s.keySaltLength) } else if password == "" { return nil, ErrMissingPasswordPSK } else { - s.psk = Key([]byte(password), s.keySaltLength) + psk = Key([]byte(password), s.keySaltLength) } switch method { @@ -93,6 +90,7 @@ func NewService(method string, psk []byte, password string, secureRNG io.Reader, s.udpCipher = newXChacha20Poly1305(psk) } + s.psk = psk return s, nil } @@ -271,7 +269,7 @@ func (c *serverConn) WriterReplaceable() bool { func (s *Service) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(conn, buffer, metadata) if err != nil { - err = &shadowsocks.ServerPacketError{PacketConn: conn, Source: metadata.Source, Cause: err} + err = &shadowsocks.ServerPacketError{Source: metadata.Source, Cause: err} } return err } diff --git a/protocol/shadowsocks/shadowaead_2022/service_multi.go b/protocol/shadowsocks/shadowaead_2022/service_multi.go index 9c0df4b..6269379 100644 --- a/protocol/shadowsocks/shadowaead_2022/service_multi.go +++ b/protocol/shadowsocks/shadowaead_2022/service_multi.go @@ -191,7 +191,7 @@ func (s *MultiService[U]) newConnection(ctx context.Context, conn net.Conn, meta func (s *MultiService[U]) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(conn, buffer, metadata) if err != nil { - err = &shadowsocks.ServerPacketError{PacketConn: conn, Source: metadata.Source, Cause: err} + err = &shadowsocks.ServerPacketError{Source: metadata.Source, Cause: err} } return err }