Implement GFW bypass (see issue #35)

This commit is contained in:
B. Blechschmidt 2023-05-31 18:25:24 +02:00
parent 75bfdcc95a
commit 6767076a6b

View file

@ -69,7 +69,11 @@ pub enum SocksCommand {
#[allow(dead_code)] #[allow(dead_code)]
enum SocksAuthentication { enum SocksAuthentication {
None = 0, None = 0,
GssApi = 1,
Password = 2, Password = 2,
ChallengeHandshake = 3,
Unassigned = 4,
Unassigned100 = 100,
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -163,18 +167,24 @@ impl SocksConnection {
} }
SocksVersion::V5 => { SocksVersion::V5 => {
// Providing unassigned methods is supposed to bypass China's GFW.
// For details, refer to https://github.com/blechschmidt/tun2proxy/issues/35.
if credentials.is_some() { if credentials.is_some() {
self.server_outbuf.extend(&[ self.server_outbuf.extend(&[
self.version as u8, self.version as u8,
2u8, 4u8,
SocksAuthentication::None as u8, SocksAuthentication::None as u8,
SocksAuthentication::Password as u8, SocksAuthentication::Password as u8,
SocksAuthentication::Unassigned as u8,
SocksAuthentication::Unassigned100 as u8,
]); ]);
} else { } else {
self.server_outbuf.extend(&[ self.server_outbuf.extend(&[
self.version as u8, self.version as u8,
1u8, 3u8,
SocksAuthentication::None as u8, SocksAuthentication::None as u8,
SocksAuthentication::Unassigned as u8,
SocksAuthentication::Unassigned100 as u8,
]); ]);
} }
} }