Skip to content

Commit cc02729

Browse files
authored
Merge pull request #39 from HTensor/master
fix: protocol identification compatibility issue
2 parents 16638cf + 9bfc84d commit cc02729

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

Diff for: src/client.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,21 @@ where
128128
methods: Vec<AuthenticationMethod>,
129129
) -> Result<Vec<AuthenticationMethod>> {
130130
debug!(
131-
"Send version and method len [{}, {}]",
131+
"Client's version and method len [{}, {}]",
132132
consts::SOCKS5_VERSION,
133133
methods.len()
134134
);
135-
// write the first 2 bytes which contains the SOCKS version and the methods len()
136-
self.socket
137-
.write(&[consts::SOCKS5_VERSION, methods.len() as u8])
138-
.await
139-
.context("Couldn't write SOCKS version & methods len")?;
135+
// the first 2 bytes which contains the SOCKS version and the methods len()
136+
let mut packet = vec![consts::SOCKS5_VERSION, methods.len() as u8];
140137

141138
let auth = methods.iter().map(|l| l.as_u8()).collect::<Vec<_>>();
142-
143139
debug!("client auth methods supported: {:?}", &auth);
140+
packet.extend(auth);
141+
144142
self.socket
145-
.write(&auth)
143+
.write_all(&packet)
146144
.await
147-
.context("Couldn't write supported auth methods")?;
145+
.context("Couldn't write SOCKS version & methods len & supported auth methods")?;
148146

149147
// Return methods available
150148
Ok(methods)
@@ -218,23 +216,13 @@ where
218216
let user_bytes = username.as_bytes();
219217
let pass_bytes = password.as_bytes();
220218

221-
// send username len
222-
self.socket
223-
.write(&[1, user_bytes.len() as u8])
224-
.await
225-
.context("Can't send username len")?;
226-
self.socket
227-
.write(user_bytes)
228-
.await
229-
.context("Can't send username")?;
219+
let mut packet: Vec<u8> = vec![1, user_bytes.len() as u8];
220+
packet.extend(user_bytes);
221+
packet.push(pass_bytes.len() as u8);
222+
packet.extend(pass_bytes);
230223

231-
// send password len
232-
self.socket
233-
.write(&[pass_bytes.len() as u8])
234-
.await
235-
.context("Can't send password len")?;
236224
self.socket
237-
.write(pass_bytes)
225+
.write_all(&packet)
238226
.await
239227
.context("Can't send password")?;
240228

0 commit comments

Comments
 (0)