Class Socks5LogicHandler
- java.lang.Object
-
- org.apache.mina.proxy.AbstractProxyLogicHandler
-
- org.apache.mina.proxy.handlers.socks.AbstractSocksLogicHandler
-
- org.apache.mina.proxy.handlers.socks.Socks5LogicHandler
-
- All Implemented Interfaces:
ProxyLogicHandler
public class Socks5LogicHandler extends AbstractSocksLogicHandler
Socks5LogicHandler.java - SOCKS5 authentication mechanisms logic handler.- Since:
- MINA 2.0.0-M3
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringGSS_CONTEXTThe Java GSS-API context attribute key.private static java.lang.StringGSS_TOKENLast GSS token received attribute key.private static java.lang.StringHANDSHAKE_STEPThe current step in the handshake attribute key.private static org.slf4j.LoggerLOGGERprivate static java.lang.StringSELECTED_AUTH_METHODThe selected authentication method attribute key.-
Fields inherited from class org.apache.mina.proxy.handlers.socks.AbstractSocksLogicHandler
request
-
-
Constructor Summary
Constructors Constructor Description Socks5LogicHandler(ProxyIoSession proxyIoSession)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseSession(java.lang.String message)Closes the session.voiddoHandshake(IoFilter.NextFilter nextFilter)Performs the handshake process.private IoBufferencodeAuthenticationPacket(SocksProxyRequest request)Encodes the authentication packet for supported authentication methods.private IoBufferencodeGSSAPIAuthenticationPacket(SocksProxyRequest request)Encodes the authentication packet for supported authentication methods.private IoBufferencodeInitialGreetingPacket(SocksProxyRequest request)Encodes the initial greeting packet.private IoBufferencodeProxyRequestPacket(SocksProxyRequest request)Encodes the proxy authorization request packet.protected voidhandleResponse(IoFilter.NextFilter nextFilter, IoBuffer buf, int step)Handle a SOCKS v5 response from the proxy server.voidmessageReceived(IoFilter.NextFilter nextFilter, IoBuffer buf)Handles incoming data during the handshake process.private voidwriteRequest(IoFilter.NextFilter nextFilter, SocksProxyRequest request, int step)Encodes a SOCKS5 request and writes it to the next filter so it can be sent to the proxy server.-
Methods inherited from class org.apache.mina.proxy.AbstractProxyLogicHandler
closeSession, enqueueWriteRequest, flushPendingWriteRequests, getProxyFilter, getProxyIoSession, getSession, isHandshakeComplete, setHandshakeComplete, writeData
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
SELECTED_AUTH_METHOD
private static final java.lang.String SELECTED_AUTH_METHOD
The selected authentication method attribute key.
-
HANDSHAKE_STEP
private static final java.lang.String HANDSHAKE_STEP
The current step in the handshake attribute key.
-
GSS_CONTEXT
private static final java.lang.String GSS_CONTEXT
The Java GSS-API context attribute key.
-
GSS_TOKEN
private static final java.lang.String GSS_TOKEN
Last GSS token received attribute key.
-
-
Constructor Detail
-
Socks5LogicHandler
public Socks5LogicHandler(ProxyIoSession proxyIoSession)
- Parameters:
proxyIoSession- The original session- See Also:
AbstractSocksLogicHandler(ProxyIoSession)
-
-
Method Detail
-
doHandshake
public void doHandshake(IoFilter.NextFilter nextFilter)
Performs the handshake process.- Parameters:
nextFilter- the next filter
-
encodeInitialGreetingPacket
private IoBuffer encodeInitialGreetingPacket(SocksProxyRequest request)
Encodes the initial greeting packet.- Parameters:
request- the socks proxy request data- Returns:
- the encoded buffer
-
encodeProxyRequestPacket
private IoBuffer encodeProxyRequestPacket(SocksProxyRequest request)
Encodes the proxy authorization request packet.- Parameters:
request- the socks proxy request data- Returns:
- the encoded buffer
-
encodeAuthenticationPacket
private IoBuffer encodeAuthenticationPacket(SocksProxyRequest request) throws org.ietf.jgss.GSSException
Encodes the authentication packet for supported authentication methods.- Parameters:
request- the socks proxy request data- Returns:
- the encoded buffer, if null then authentication step is over and handshake process can jump immediately to the next step without waiting for a server reply.
- Throws:
org.ietf.jgss.GSSException- when something fails while using GSSAPI
-
encodeGSSAPIAuthenticationPacket
private IoBuffer encodeGSSAPIAuthenticationPacket(SocksProxyRequest request) throws org.ietf.jgss.GSSException
Encodes the authentication packet for supported authentication methods.- Parameters:
request- the socks proxy request data- Returns:
- the encoded buffer
- Throws:
org.ietf.jgss.GSSException- when something fails while using GSSAPI
-
writeRequest
private void writeRequest(IoFilter.NextFilter nextFilter, SocksProxyRequest request, int step)
Encodes a SOCKS5 request and writes it to the next filter so it can be sent to the proxy server.- Parameters:
nextFilter- the next filterrequest- the request to send.step- the current step in the handshake process
-
messageReceived
public void messageReceived(IoFilter.NextFilter nextFilter, IoBuffer buf)
Handles incoming data during the handshake process. Should consume only the handshake data from the buffer, leaving any extra data in place.- Parameters:
nextFilter- the next filterbuf- the buffered data received
-
handleResponse
protected void handleResponse(IoFilter.NextFilter nextFilter, IoBuffer buf, int step) throws java.lang.Exception
Handle a SOCKS v5 response from the proxy server.- Parameters:
nextFilter- the next filterbuf- the buffered data receivedstep- the current step in the authentication process- Throws:
java.lang.Exception- If something went wrong
-
closeSession
protected void closeSession(java.lang.String message)
Closes the session. If anyGSSContextis present in the session then it is closed.- Overrides:
closeSessionin classAbstractProxyLogicHandler- Parameters:
message- the error message
-
-