use of net.i2p.socks.SOCKSException in project i2p.i2p by i2p.
the class SOCKS5Server method setupServer.
protected void setupServer() throws SOCKSException {
if (setupCompleted) {
return;
}
DataInputStream in;
DataOutputStream out;
try {
in = new DataInputStream(clientSock.getInputStream());
out = new DataOutputStream(clientSock.getOutputStream());
init(in, out);
if (manageRequest(in, out) == Command.UDP_ASSOCIATE)
handleUDP(in, out);
} catch (IOException e) {
throw new SOCKSException("Connection error", e);
}
setupCompleted = true;
}
use of net.i2p.socks.SOCKSException in project i2p.i2p by i2p.
the class SOCKS5Server method outproxyConnect.
/**
* Act as a SOCKS 5 client to connect to an outproxy
* @return open socket or throws error
* @since 0.8.2
*/
private I2PSocket outproxyConnect(I2PSOCKSTunnel tun, String proxy) throws IOException, I2PException {
Properties overrides = new Properties();
overrides.setProperty("option.i2p.streaming.connectDelay", "1000");
I2PSocketOptions proxyOpts = tun.buildOptions(overrides);
Destination dest = _context.namingService().lookup(proxy);
if (dest == null)
throw new SOCKSException("Outproxy not found");
I2PSocket destSock = tun.createI2PSocket(dest, proxyOpts);
OutputStream out = null;
InputStream in = null;
try {
out = destSock.getOutputStream();
in = destSock.getInputStream();
boolean authAvail = Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH));
String configUser = null;
String configPW = null;
if (authAvail) {
configUser = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_USER_PREFIX + proxy);
configPW = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_PW_PREFIX + proxy);
if (configUser == null || configPW == null) {
configUser = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_USER);
configPW = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_PW);
}
}
SOCKS5Client.connect(in, out, connHostName, connPort, configUser, configPW);
} catch (IOException e) {
try {
destSock.close();
} catch (IOException ioe) {
}
if (in != null)
try {
in.close();
} catch (IOException ioe) {
}
if (out != null)
try {
out.close();
} catch (IOException ioe) {
}
throw e;
}
// that's it, caller will send confirmation to our client
return destSock;
}
use of net.i2p.socks.SOCKSException in project i2p.i2p by i2p.
the class SOCKSServerFactory method createSOCKSServer.
/**
* Create a new SOCKS server, using the provided socket (that must
* be connected to a client) to select the proper SOCKS protocol
* version. This method wil strip the SOCKS VER field from the
* provided sockets's input stream.
*
* @param s a Socket used to choose the SOCKS server type
* @param props non-null
*/
public static SOCKSServer createSOCKSServer(I2PAppContext ctx, Socket s, Properties props) throws SOCKSException {
SOCKSServer serv;
try {
DataInputStream in = new DataInputStream(s.getInputStream());
int socksVer = in.readByte();
switch(socksVer) {
case 0x04:
// SOCKS version 4/4a
if (Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_AUTH)) && props.containsKey(I2PTunnelHTTPClientBase.PROP_USER) && props.containsKey(I2PTunnelHTTPClientBase.PROP_PW)) {
throw new SOCKSException("SOCKS 4/4a not supported when authorization is required");
}
serv = new SOCKS4aServer(ctx, s, props);
break;
case 0x05:
// SOCKS version 5
serv = new SOCKS5Server(ctx, s, props);
break;
case 'C':
case 'G':
case 'H':
case 'P':
DataOutputStream out = new DataOutputStream(s.getOutputStream());
out.write(DataHelper.getASCII(ERR_REQUEST_DENIED));
throw new SOCKSException("HTTP request to socks");
default:
throw new SOCKSException("SOCKS protocol version not supported (" + Integer.toHexString(socksVer) + ")");
}
} catch (IOException e) {
// _log.debug("error reading SOCKS protocol version");
throw new SOCKSException("Connection error", e);
}
return serv;
}
use of net.i2p.socks.SOCKSException in project i2p.i2p by i2p.
the class I2PSOCKSIRCTunnel method clientConnectionRun.
/**
* Same as in I2PSOCKSTunnel, but run the filters from I2PTunnelIRCClient
* instead of I2PTunnelRunner
*/
@Override
protected void clientConnectionRun(Socket s) {
I2PSocket destSock = null;
try {
// _log.error("SOCKS IRC Tunnel Start");
try {
s.setSoTimeout(INITIAL_SO_TIMEOUT);
} catch (SocketException ioe) {
}
SOCKSServer serv = SOCKSServerFactory.createSOCKSServer(_context, s, getTunnel().getClientOptions());
Socket clientSock = serv.getClientSocket();
try {
s.setSoTimeout(0);
} catch (SocketException ioe) {
}
destSock = serv.getDestinationI2PSocket(this);
StringBuffer expectedPong = new StringBuffer();
int id = __clientId.incrementAndGet();
Thread in = new I2PAppThread(new IrcInboundFilter(clientSock, destSock, expectedPong, _log), "SOCKS IRC Client " + id + " in", true);
in.start();
// Thread out = new I2PAppThread(new IrcOutboundFilter(clientSock, destSock, expectedPong, _log),
// "SOCKS IRC Client " + id + " out", true);
Runnable out = new IrcOutboundFilter(clientSock, destSock, expectedPong, _log);
// we are called from an unlimited thread pool, so run inline
// out.start();
out.run();
} catch (SOCKSException e) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error from SOCKS connection", e);
} finally {
// only because we are running it inline
closeSocket(s);
if (destSock != null)
try {
destSock.close();
} catch (IOException ioe) {
}
}
}
use of net.i2p.socks.SOCKSException in project i2p.i2p by i2p.
the class SOCKS4aServer method confirmConnection.
protected void confirmConnection() throws SOCKSException {
DataOutputStream out;
try {
out = new DataOutputStream(clientSock.getOutputStream());
sendRequestReply(Reply.SUCCEEDED, InetAddress.getByName("127.0.0.1"), 1, out);
} catch (IOException e) {
throw new SOCKSException("Connection error", e);
}
}
Aggregations