From 399701df33e62674eee9330121326b949ee37adb Mon Sep 17 00:00:00 2001 From: Oscar Linderholm Date: Fri, 6 Sep 2024 16:00:30 +0200 Subject: [PATCH] Do not share the XOR key offset between the send and receive threads --- CHANGELOG.md | 6 ++++++ proxy/xorv2/xorv2.go | 10 +++++----- vendor/github.com/mullvad/proxy/xorv2/xorv2.go | 10 +++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e460597..9887820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,10 +19,16 @@ Line wrap the file at 100 chars. Th * **Fixed**: for any bug fixes. * **Security**: in case of vulnerabilities. +## [1.1.1] - 2024-09-06 +### Fixed +- Do not share the XOR key offset between the send and receive threads. + + ## [1.1.0] - 2024-09-05 ### Added - Add XOR v2. + ## [1.0.4] - 2024-07-04 ### Changed - Upgrade to use Go 1.22.5 diff --git a/proxy/xorv2/xorv2.go b/proxy/xorv2/xorv2.go index ed72c9a..2015ce0 100644 --- a/proxy/xorv2/xorv2.go +++ b/proxy/xorv2/xorv2.go @@ -9,9 +9,8 @@ import ( ) type xor struct { - addrPort string - xorKey []byte - xorKeyOffset int + addrPort string + xorKey []byte } func New(ip net.IP) (*xor, error) { @@ -33,6 +32,7 @@ func (x *xor) ToPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) } func (x *xor) forward(dst io.Writer, src io.Reader) { buf := make([]byte, 1024*64) + offset := 0 for { nr, err := src.Read(buf) @@ -41,8 +41,8 @@ func (x *xor) forward(dst io.Writer, src io.Reader) { } for i := 0; i < nr; i++ { - buf[i] ^= x.xorKey[x.xorKeyOffset] - x.xorKeyOffset = (x.xorKeyOffset + 1) % len(x.xorKey) + buf[i] ^= x.xorKey[offset] + offset = (offset + 1) % len(x.xorKey) } nw, err := dst.Write(buf[0:nr]) diff --git a/vendor/github.com/mullvad/proxy/xorv2/xorv2.go b/vendor/github.com/mullvad/proxy/xorv2/xorv2.go index ed72c9a..2015ce0 100644 --- a/vendor/github.com/mullvad/proxy/xorv2/xorv2.go +++ b/vendor/github.com/mullvad/proxy/xorv2/xorv2.go @@ -9,9 +9,8 @@ import ( ) type xor struct { - addrPort string - xorKey []byte - xorKeyOffset int + addrPort string + xorKey []byte } func New(ip net.IP) (*xor, error) { @@ -33,6 +32,7 @@ func (x *xor) ToPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) } func (x *xor) forward(dst io.Writer, src io.Reader) { buf := make([]byte, 1024*64) + offset := 0 for { nr, err := src.Read(buf) @@ -41,8 +41,8 @@ func (x *xor) forward(dst io.Writer, src io.Reader) { } for i := 0; i < nr; i++ { - buf[i] ^= x.xorKey[x.xorKeyOffset] - x.xorKeyOffset = (x.xorKeyOffset + 1) % len(x.xorKey) + buf[i] ^= x.xorKey[offset] + offset = (offset + 1) % len(x.xorKey) } nw, err := dst.Write(buf[0:nr])