Added IP -> I2P URL mapping support to SOCKS client tunnels

To use, add custom options to the SOCKS client tunnel like:

ipmapping.127.12.12.12=stats.i2p

Then save and restart the tunnel.
This commit is contained in:
str4d
2013-01-24 00:14:03 +00:00
parent a7fc8bdf53
commit 42040eb6c8
4 changed files with 36 additions and 4 deletions

View File

@@ -46,9 +46,11 @@ public class SOCKS4aServer extends SOCKSServer {
* client socket.
*
* @param clientSock client socket
* @param props non-null
*/
public SOCKS4aServer(Socket clientSock) {
public SOCKS4aServer(Socket clientSock, Properties props) {
this.clientSock = clientSock;
this.props = props;
}
public Socket getClientSocket() throws SOCKSException {
@@ -116,6 +118,13 @@ public class SOCKS4aServer extends SOCKSServer {
}
}
// Check if the requested IP should be mapped to a .i2p URL
String mappedUrl = getMappedUrlForIP(connHostName);
if (mappedUrl != null && mappedUrl.toLowerCase(Locale.US).endsWith(".i2p")) {
_log.debug("IPV4 address " + connHostName + " was mapped to URL " + mappedUrl);
connHostName = mappedUrl;
}
// discard user name
readString(in);

View File

@@ -42,7 +42,6 @@ public class SOCKS5Server extends SOCKSServer {
private static final int SOCKS_VERSION_5 = 0x05;
private final Socket clientSock;
private final Properties props;
private boolean setupCompleted = false;
private final boolean authRequired;
@@ -207,7 +206,12 @@ public class SOCKS5Server extends SOCKSServer {
connHostName += ".";
}
}
if (command != Command.UDP_ASSOCIATE)
// Check if the requested IP should be mapped to a .i2p URL
String mappedUrl = getMappedUrlForIP(connHostName);
if (mappedUrl != null && mappedUrl.toLowerCase(Locale.US).endsWith(".i2p")) {
_log.debug("IPV4 address " + connHostName + " was mapped to URL " + mappedUrl);
connHostName = mappedUrl;
} else if (command != Command.UDP_ASSOCIATE)
_log.warn("IPV4 address type in request: " + connHostName + ". Is your client secure?");
break;
case AddressType.DOMAINNAME:

View File

@@ -7,6 +7,7 @@
package net.i2p.i2ptunnel.socks;
import java.net.Socket;
import java.util.Properties;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.util.Log;
@@ -19,11 +20,29 @@ import net.i2p.util.Log;
public abstract class SOCKSServer {
private static final Log _log = new Log(SOCKSServer.class);
private static final String PROP_MAPPING_PREFIX = "ipmapping.";
/* Details about the connection requested by client */
protected String connHostName;
protected int connPort;
protected int addressType;
protected Properties props;
/**
* IP to I2P URL mapping support. This matches the given IP string against
* a user-set list of mappings. This enables applications which do not
* properly support the SOCKS5 DOMAINNAME feature to be used with I2P.
* @param ip The IP address to check.
* @return The I2P URL if a mapping is found, or null otherwise.
* @since 0.9.5
*/
protected String getMappedUrlForIP(String ip) {
if (props.containsKey(PROP_MAPPING_PREFIX + ip))
return props.getProperty(PROP_MAPPING_PREFIX + ip);
return null;
}
/**
* Perform server initialization (expecially regarding protected
* variables).

View File

@@ -54,7 +54,7 @@ public class SOCKSServerFactory {
props.containsKey(I2PTunnelHTTPClientBase.PROP_PW)) {
throw new SOCKSException("SOCKS 4/4a not supported when authorization is required");
}
serv = new SOCKS4aServer(s);
serv = new SOCKS4aServer(s, props);
break;
case 0x05:
// SOCKS version 5