private void handlePasswordAuthRequest(ChannelHandlerContext ctx, Socks5PasswordAuthRequest passwordAuthRequest) { String username = ConfigurationProperties.proxyAuthenticationUsername(); String password = ConfigurationProperties.proxyAuthenticationPassword(); // we need the null-check again here, in case the properties got unset between init and auth request if (!username.isEmpty() && !password.isEmpty() && username.equals(passwordAuthRequest.username()) && password.equals(passwordAuthRequest.password())) { ctx.pipeline().replace(Socks5PasswordAuthRequestDecoder.class, null, new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS)); } else { ctx.writeAndFlush(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE)).addListener(ChannelFutureListener.CLOSE); } }
private void handleInitialRequest(ChannelHandlerContext ctx, Socks5InitialRequest initialRequest) { String username = ConfigurationProperties.proxyAuthenticationUsername(); String password = ConfigurationProperties.proxyAuthenticationPassword(); Socks5AuthMethod requiredAuthMethod; ChannelHandler nextRequestDecoder; if (!username.isEmpty() && !password.isEmpty()) { requiredAuthMethod = Socks5AuthMethod.PASSWORD; nextRequestDecoder = new Socks5PasswordAuthRequestDecoder(); } else { requiredAuthMethod = Socks5AuthMethod.NO_AUTH; nextRequestDecoder = new Socks5CommandRequestDecoder(); } answerInitialRequest(ctx, initialRequest, requiredAuthMethod, nextRequestDecoder); }
private void handlePasswordAuthRequest(ChannelHandlerContext ctx, Socks5PasswordAuthRequest passwordAuthRequest) { String username = ConfigurationProperties.proxyAuthenticationUsername(); String password = ConfigurationProperties.proxyAuthenticationPassword(); // we need the null-check again here, in case the properties got unset between init and auth request if (!username.isEmpty() && !password.isEmpty() && username.equals(passwordAuthRequest.username()) && password.equals(passwordAuthRequest.password())) { ctx.pipeline().replace(Socks5PasswordAuthRequestDecoder.class, null, new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS)); } else { ctx.writeAndFlush(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE)).addListener(ChannelFutureListener.CLOSE); } }
private void handleInitialRequest(ChannelHandlerContext ctx, Socks5InitialRequest initialRequest) { String username = ConfigurationProperties.proxyAuthenticationUsername(); String password = ConfigurationProperties.proxyAuthenticationPassword(); Socks5AuthMethod requiredAuthMethod; ChannelHandler nextRequestDecoder; if (!username.isEmpty() && !password.isEmpty()) { requiredAuthMethod = Socks5AuthMethod.PASSWORD; nextRequestDecoder = new Socks5PasswordAuthRequestDecoder(); } else { requiredAuthMethod = Socks5AuthMethod.NO_AUTH; nextRequestDecoder = new Socks5CommandRequestDecoder(); } answerInitialRequest(ctx, initialRequest, requiredAuthMethod, nextRequestDecoder); }
@Override protected void channelRead0(ChannelHandlerContext ctx, SocksMessage msg) throws Exception { switch (msg.version()) { case SOCKS4a: ctx.pipeline().remove(this); ctx.pipeline().addLast(new SocksServerConnectHandler(sshSessionProvider)); ctx.fireChannelRead(msg); break; case SOCKS5: // For SOCKS5 protocol, needs to handle the initial authentication handshake if (msg instanceof Socks5InitialRequest) { ctx.pipeline().remove(this); ctx.pipeline().addFirst(new Socks5CommandRequestDecoder()); ctx.pipeline().addLast(new SocksServerConnectHandler(sshSessionProvider)); ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH)); } else { // We don't expect other type of Socks5 message throw new NotSupportedException("Unsupported SOCKS message " + msg); } break; default: throw new NotSupportedException("Unsupported SOCKS version '" + msg.version() + "'"); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, SocksMessage msg) throws Exception { switch (msg.version()) { case SOCKS4a: ctx.pipeline().remove(this); ctx.pipeline().addLast(new SocksServerConnectHandler(sshSessionProvider)); ctx.fireChannelRead(msg); break; case SOCKS5: // For SOCKS5 protocol, needs to handle the initial authentication handshake if (msg instanceof Socks5InitialRequest) { ctx.pipeline().remove(this); ctx.pipeline().addFirst(new Socks5CommandRequestDecoder()); ctx.pipeline().addLast(new SocksServerConnectHandler(sshSessionProvider)); ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH)); } else { // We don't expect other type of Socks5 message throw new NotSupportedException("Unsupported SOCKS message " + msg); } break; default: throw new NotSupportedException("Unsupported SOCKS version '" + msg.version() + "'"); } }
ctx.pipeline().addFirst(new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH)); } else if (socksRequest instanceof Socks5CommandRequest) {
case SOCKS5: if (socksMessage instanceof Socks5InitialRequest) { ctx.pipeline().addFirst(addChannelHandler(new Socks5CommandRequestDecoder())); ctx.writeAndFlush(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH)); } else if (socksMessage instanceof Socks5PasswordAuthRequest) { ctx.pipeline().addFirst(addChannelHandler(new Socks5CommandRequestDecoder())); ctx.writeAndFlush(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS)); } else if (socksMessage instanceof Socks5CommandRequest) {