From 303fd6e26178d9d89e6a7e904d360d939bf6aee0 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Thu, 28 Jan 2021 03:11:17 +0000 Subject: [PATCH] Standardize Socks Outbound Authentication Behavior --- proxy/socks/protocol.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index 5701678e..29b9c913 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -422,16 +422,6 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i defer b.Release() common.Must2(b.Write([]byte{socks5Version, 0x01, authByte})) - if authByte == authPassword { - account := request.User.Account.(*Account) - - common.Must(b.WriteByte(0x01)) - common.Must(b.WriteByte(byte(len(account.Username)))) - common.Must2(b.WriteString(account.Username)) - common.Must(b.WriteByte(byte(len(account.Password)))) - common.Must2(b.WriteString(account.Password)) - } - if err := buf.WriteAllBytes(writer, b.Bytes()); err != nil { return nil, err } @@ -449,6 +439,17 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i } if authByte == authPassword { + b.Clear() + account := request.User.Account.(*Account) + common.Must(b.WriteByte(0x01)) + common.Must(b.WriteByte(byte(len(account.Username)))) + common.Must2(b.WriteString(account.Username)) + common.Must(b.WriteByte(byte(len(account.Password)))) + common.Must2(b.WriteString(account.Password)) + if err := buf.WriteAllBytes(writer, b.Bytes()); err != nil { + return nil, err + } + b.Clear() if _, err := b.ReadFullFrom(reader, 2); err != nil { return nil, err