Skip to content

Commit

Permalink
Support SOCKS5 proxy with username/password authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 authored and ok2c committed Sep 15, 2023
1 parent f255736 commit f44526e
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ private enum State {
@Override
public void connected(final IOSession session) throws IOException {
this.buffer.put(CLIENT_VERSION);
this.buffer.put((byte) 1);
this.buffer.put(NO_AUTHENTICATION_REQUIRED);
if (this.reactorConfig.getSocksProxyUsername() != null && this.reactorConfig.getSocksProxyPassword() != null) {
this.buffer.put((byte) 2);
this.buffer.put(NO_AUTHENTICATION_REQUIRED);
this.buffer.put(USERNAME_PASSWORD);
} else {
this.buffer.put((byte) 1);
this.buffer.put(NO_AUTHENTICATION_REQUIRED);
}
this.buffer.flip();
session.setEventMask(SelectionKey.OP_WRITE);
}
Expand Down Expand Up @@ -171,6 +177,7 @@ public void inputReady(final IOSession session, final ByteBuffer src) throws IOE
this.buffer.put(username);
this.buffer.put((byte) password.length);
this.buffer.put(password);
this.buffer.flip();
session.setEventMask(SelectionKey.OP_WRITE);
this.state = State.SEND_USERNAME_PASSWORD;
} else if (serverMethod == NO_AUTHENTICATION_REQUIRED) {
Expand Down

0 comments on commit f44526e

Please sign in to comment.