Skip to content

Commit

Permalink
Merge pull request #24 from zero-systems/master
Browse files Browse the repository at this point in the history
Return error if authorization is required but credentials are not present
  • Loading branch information
sticnarf authored Oct 2, 2020
2 parents 3175474 + fc5b74e commit 002a16d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 4 additions & 0 deletions src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ where S: Stream<Item = Result<SocketAddr>> + Unpin
}

async fn password_authentication_protocol<T: AsyncRead + AsyncWrite + Unpin>(&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?;

Expand Down

0 comments on commit 002a16d

Please sign in to comment.