/** * Handle incoming data during the handshake process. Should consume only the * handshake data from the buffer, leaving any extra data in place. * * @param nextFilter the next filter * @param buf the server response data buffer */ public void messageReceived(final NextFilter nextFilter, final IoBuffer buf) { try { if (buf.remaining() >= SocksProxyConstants.SOCKS_4_RESPONSE_SIZE) { handleResponse(buf); } } catch (Exception ex) { closeSession("Proxy handshake failed: ", ex); } }
/** * Perform the handshake. * * @param nextFilter the next filter */ @Override public void doHandshake(final NextFilter nextFilter) { logger.debug(" doHandshake()"); // Send request writeRequest(nextFilter, request); }
writeData(nextFilter, buf); } catch (Exception ex) { closeSession("Unable to send Socks request: ", ex);
/** * Handle a SOCKS4/SOCKS4a response from the proxy server. Test * the response buffer reply code and call {@link #setHandshakeComplete()} * if access is granted. * * @param buf the buffer holding the server response data. * @throws Exception if server response is malformed or if request is rejected * by the proxy server. */ protected void handleResponse(final IoBuffer buf) throws Exception { byte first = buf.get(0); if (first != 0) { throw new Exception("Socks response seems to be malformed"); } byte status = buf.get(1); // Consumes all the response data from the buffer buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE); if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) { setHandshakeComplete(); } else { throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " (" + SocksProxyConstants.getReplyCodeAsString(status) + ")"); } } }
SocksProxyRequest req = (SocksProxyRequest) request; if (req.getProtocolVersion() == SocksProxyConstants.SOCKS_VERSION_4) { handler = new Socks4LogicHandler(proxyIoSession); } else { handler = new Socks5LogicHandler(proxyIoSession);
writeData(nextFilter, buf); } catch (Exception ex) { closeSession("Unable to send Socks request: ", ex);
/** * Handle a SOCKS4/SOCKS4a response from the proxy server. Test * the response buffer reply code and call {@link #setHandshakeComplete()} * if access is granted. * * @param buf the buffer holding the server response data. * @throws Exception if server response is malformed or if request is rejected * by the proxy server. */ protected void handleResponse(final IoBuffer buf) throws Exception { byte first = buf.get(0); if (first != 0) { throw new Exception("Socks response seems to be malformed"); } byte status = buf.get(1); // Consumes all the response data from the buffer buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE); if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) { setHandshakeComplete(); } else { throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " (" + SocksProxyConstants.getReplyCodeAsString(status) + ")"); } } }
SocksProxyRequest req = (SocksProxyRequest) request; if (req.getProtocolVersion() == SocksProxyConstants.SOCKS_VERSION_4) { handler = new Socks4LogicHandler(proxyIoSession); } else { handler = new Socks5LogicHandler(proxyIoSession);
/** * Handle incoming data during the handshake process. Should consume only the * handshake data from the buffer, leaving any extra data in place. * * @param nextFilter the next filter * @param buf the server response data buffer */ @Override public void messageReceived(final NextFilter nextFilter, final IoBuffer buf) { try { if (buf.remaining() >= SocksProxyConstants.SOCKS_4_RESPONSE_SIZE) { handleResponse(buf); } } catch (Exception ex) { closeSession("Proxy handshake failed: ", ex); } }
writeData(nextFilter, buf); } catch (Exception ex) { closeSession("Unable to send Socks request: ", ex);
/** * Perform the handshake. * * @param nextFilter the next filter */ @Override public void doHandshake(final NextFilter nextFilter) { logger.debug(" doHandshake()"); // Send request writeRequest(nextFilter, request); }
/** * Handle a SOCKS4/SOCKS4a response from the proxy server. Test * the response buffer reply code and call {@link #setHandshakeComplete()} * if access is granted. * * @param buf the buffer holding the server response data. * @throws exception if server response is malformed or if request is rejected * by the proxy server. */ protected void handleResponse(final IoBuffer buf) throws Exception { byte first = buf.get(0); if (first != 0) { throw new Exception("Socks response seems to be malformed"); } byte status = buf.get(1); // Consumes all the response data from the buffer buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE); if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) { setHandshakeComplete(); } else { throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " (" + SocksProxyConstants.getReplyCodeAsString(status) + ")"); } } }
SocksProxyRequest req = (SocksProxyRequest) request; if (req.getProtocolVersion() == SocksProxyConstants.SOCKS_VERSION_4) { handler = new Socks4LogicHandler(proxyIoSession); } else { handler = new Socks5LogicHandler(proxyIoSession);
/** * Handle incoming data during the handshake process. Should consume only the * handshake data from the buffer, leaving any extra data in place. * * @param nextFilter the next filter * @param buf the server response data buffer */ @Override public void messageReceived(final NextFilter nextFilter, final IoBuffer buf) { try { if (buf.remaining() >= SocksProxyConstants.SOCKS_4_RESPONSE_SIZE) { handleResponse(buf); } } catch (Exception ex) { closeSession("Proxy handshake failed: ", ex); } }
/** * Perform the handshake. * * @param nextFilter the next filter */ public void doHandshake(final NextFilter nextFilter) { logger.debug(" doHandshake()"); // Send request writeRequest(nextFilter, request); }