mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-09 16:17:45 +00:00
Support authentication without credentials if credentials are provided
This commit is contained in:
parent
e5d1cfbef1
commit
75bfdcc95a
1 changed files with 10 additions and 5 deletions
15
src/socks.rs
15
src/socks.rs
|
@ -166,13 +166,14 @@ impl SocksConnection {
|
|||
if credentials.is_some() {
|
||||
self.server_outbuf.extend(&[
|
||||
self.version as u8,
|
||||
SocksCommand::Connect as u8,
|
||||
2u8,
|
||||
SocksAuthentication::None as u8,
|
||||
SocksAuthentication::Password as u8,
|
||||
]);
|
||||
} else {
|
||||
self.server_outbuf.extend(&[
|
||||
self.version as u8,
|
||||
SocksCommand::Connect as u8,
|
||||
1u8,
|
||||
SocksAuthentication::None as u8,
|
||||
]);
|
||||
}
|
||||
|
@ -207,15 +208,19 @@ impl SocksConnection {
|
|||
return Err("SOCKS5 server replied with an unexpected version.".into());
|
||||
}
|
||||
|
||||
if self.server_inbuf[1] != 0 && self.credentials.is_none()
|
||||
|| self.server_inbuf[1] != 2 && self.credentials.is_some()
|
||||
let auth_method = self.server_inbuf[1];
|
||||
|
||||
if auth_method != SocksAuthentication::None as u8 && self.credentials.is_none()
|
||||
|| (auth_method != SocksAuthentication::None as u8
|
||||
&& auth_method != SocksAuthentication::Password as u8)
|
||||
&& self.credentials.is_some()
|
||||
{
|
||||
return Err("SOCKS5 server requires an unsupported authentication method.".into());
|
||||
}
|
||||
|
||||
self.server_inbuf.drain(0..2);
|
||||
|
||||
if self.credentials.is_some() {
|
||||
if auth_method == SocksAuthentication::Password as u8 {
|
||||
self.state = SocksState::SendAuthData;
|
||||
} else {
|
||||
self.state = SocksState::SendRequest;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue