Class Socks5ProxyHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.proxy.ProxyHandler
io.netty.handler.proxy.Socks5ProxyHandler
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler
Handler that establishes a blind forwarding proxy tunnel using
SOCKS Protocol Version 5.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final java.lang.Stringprivate static final java.lang.Stringprivate final Socks5ClientEncoderprivate java.lang.Stringprivate java.lang.Stringprivate static final Socks5InitialRequestprivate static final Socks5InitialRequestprivate static final byteprivate final java.lang.Stringprivate final byteprivate final byte[]private static final java.lang.Stringprivate final java.lang.StringFields inherited from class ProxyHandler
AUTH_NONE -
Constructor Summary
ConstructorsConstructorDescriptionSocks5ProxyHandler(java.net.SocketAddress proxyAddress) Socks5ProxyHandler(java.net.SocketAddress proxyAddress, byte privateAuthMethod, byte[] privateToken, Socks5ClientEncoder customEncoder) Creates a new SOCKS5 proxy handler with a custom private authentication method.Socks5ProxyHandler(java.net.SocketAddress proxyAddress, java.lang.String username, java.lang.String password) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds the codec handlers required to communicate with the proxy server.java.lang.StringReturns the name of the authentication scheme in use.protected booleanhandleResponse(ChannelHandlerContext ctx, java.lang.Object response) Handles the message received from the proxy server.protected java.lang.ObjectReturns a new message that is sent at first time when the connection to the proxy server has been established.java.lang.Stringpassword()java.lang.Stringprotocol()Returns the name of the proxy protocol in use.protected voidRemoves the decoders added inProxyHandler.addCodec(ChannelHandlerContext).protected voidRemoves the encoders added inProxyHandler.addCodec(ChannelHandlerContext).private voidprivate Socks5AuthMethodjava.lang.Stringusername()Methods inherited from class ProxyHandler
channelActive, channelInactive, channelRead, channelReadComplete, connect, connectFuture, connectTimeoutMillis, destinationAddress, exceptionCaught, exceptionMessage, flush, handlerAdded, handlerRemoved, isConnected, proxyAddress, sendToProxyServer, setConnectTimeoutMillis, writeMethods inherited from class ChannelDuplexHandler
bind, close, deregister, disconnect, readMethods inherited from class ChannelInboundHandlerAdapter
channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
PROTOCOL
private static final java.lang.String PROTOCOL- See Also:
-
AUTH_PASSWORD
private static final java.lang.String AUTH_PASSWORD- See Also:
-
AUTH_PRIVATE
private static final java.lang.String AUTH_PRIVATE- See Also:
-
NO_PRIVATE_AUTH_METHOD
private static final byte NO_PRIVATE_AUTH_METHOD -
INIT_REQUEST_NO_AUTH
-
INIT_REQUEST_PASSWORD
-
username
private final java.lang.String username -
password
private final java.lang.String password -
privateAuthMethod
private final byte privateAuthMethod -
privateToken
private final byte[] privateToken -
clientEncoder
-
decoderName
private java.lang.String decoderName -
encoderName
private java.lang.String encoderName
-
-
Constructor Details
-
Socks5ProxyHandler
public Socks5ProxyHandler(java.net.SocketAddress proxyAddress) -
Socks5ProxyHandler
public Socks5ProxyHandler(java.net.SocketAddress proxyAddress, java.lang.String username, java.lang.String password) -
Socks5ProxyHandler
public Socks5ProxyHandler(java.net.SocketAddress proxyAddress, byte privateAuthMethod, byte[] privateToken, Socks5ClientEncoder customEncoder) Creates a new SOCKS5 proxy handler with a custom private authentication method.- Parameters:
proxyAddress- The address of the SOCKS5 proxy serverprivateAuthMethod- The private authentication method code (must be in range 0x80-0xFE)privateToken- The token to use for private authenticationcustomEncoder- The custom encoder to use for encoding SOCKS5 messages, ifnulltheSocks5ClientEncoder.DEFAULTwill be used- Throws:
java.lang.IllegalArgumentException- If privateAuthMethod is not in the valid range
-
-
Method Details
-
protocol
public java.lang.String protocol()Description copied from class:ProxyHandlerReturns the name of the proxy protocol in use.- Specified by:
protocolin classProxyHandler
-
authScheme
public java.lang.String authScheme()Description copied from class:ProxyHandlerReturns the name of the authentication scheme in use.- Specified by:
authSchemein classProxyHandler
-
username
public java.lang.String username() -
password
public java.lang.String password() -
addCodec
Description copied from class:ProxyHandlerAdds the codec handlers required to communicate with the proxy server.- Specified by:
addCodecin classProxyHandler- Throws:
java.lang.Exception
-
removeEncoder
Description copied from class:ProxyHandlerRemoves the encoders added inProxyHandler.addCodec(ChannelHandlerContext).- Specified by:
removeEncoderin classProxyHandler- Throws:
java.lang.Exception
-
removeDecoder
Description copied from class:ProxyHandlerRemoves the decoders added inProxyHandler.addCodec(ChannelHandlerContext).- Specified by:
removeDecoderin classProxyHandler- Throws:
java.lang.Exception
-
newInitialMessage
Description copied from class:ProxyHandlerReturns a new message that is sent at first time when the connection to the proxy server has been established.- Specified by:
newInitialMessagein classProxyHandler- Returns:
- the initial message, or
nullif the proxy server is expected to send the first message instead - Throws:
java.lang.Exception
-
handleResponse
protected boolean handleResponse(ChannelHandlerContext ctx, java.lang.Object response) throws java.lang.Exception Description copied from class:ProxyHandlerHandles the message received from the proxy server.- Specified by:
handleResponsein classProxyHandler- Returns:
trueif the connection to the destination has been established,falseif the connection to the destination has not been established and more messages are expected from the proxy server- Throws:
java.lang.Exception
-
socksAuthMethod
-
sendConnectCommand
- Throws:
java.lang.Exception
-