From fc5b74e3b20486363420ecc048cad1d1fec75453 Mon Sep 17 00:00:00 2001 From: zero-systems Date: Thu, 1 Oct 2020 20:03:48 +1000 Subject: [PATCH] Return error if authorization is required but credentials are not present --- src/error.rs | 3 +++ src/tcp.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/error.rs b/src/error.rs index 1425625..ddf34b1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -62,6 +62,9 @@ pub enum Error { /// Password auth failure #[error("Password auth failure, code: {0}")] PasswordAuthFailure(u8), + + #[error("Authorization required")] + AuthorizationRequired, } ///// Result type of `tokio-socks` diff --git a/src/tcp.rs b/src/tcp.rs index ab0e00e..c0f4781 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -385,6 +385,10 @@ where S: Stream> + Unpin } async fn password_authentication_protocol(&mut self, tcp: &mut T) -> Result<()> { + if let Authentication::None = self.auth { + return Err(Error::AuthorizationRequired); + } + self.prepare_send_password_auth(); tcp.write_all(&self.buf[self.ptr..self.len]).await?;