forked from I2P_Developers/i2p.i2p
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:
@@ -46,9 +46,11 @@ public class SOCKS4aServer extends SOCKSServer {
|
|||||||
* client socket.
|
* client socket.
|
||||||
*
|
*
|
||||||
* @param clientSock client socket
|
* @param clientSock client socket
|
||||||
|
* @param props non-null
|
||||||
*/
|
*/
|
||||||
public SOCKS4aServer(Socket clientSock) {
|
public SOCKS4aServer(Socket clientSock, Properties props) {
|
||||||
this.clientSock = clientSock;
|
this.clientSock = clientSock;
|
||||||
|
this.props = props;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Socket getClientSocket() throws SOCKSException {
|
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
|
// discard user name
|
||||||
readString(in);
|
readString(in);
|
||||||
|
|
||||||
|
@@ -42,7 +42,6 @@ public class SOCKS5Server extends SOCKSServer {
|
|||||||
private static final int SOCKS_VERSION_5 = 0x05;
|
private static final int SOCKS_VERSION_5 = 0x05;
|
||||||
|
|
||||||
private final Socket clientSock;
|
private final Socket clientSock;
|
||||||
private final Properties props;
|
|
||||||
private boolean setupCompleted = false;
|
private boolean setupCompleted = false;
|
||||||
private final boolean authRequired;
|
private final boolean authRequired;
|
||||||
|
|
||||||
@@ -207,7 +206,12 @@ public class SOCKS5Server extends SOCKSServer {
|
|||||||
connHostName += ".";
|
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?");
|
_log.warn("IPV4 address type in request: " + connHostName + ". Is your client secure?");
|
||||||
break;
|
break;
|
||||||
case AddressType.DOMAINNAME:
|
case AddressType.DOMAINNAME:
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
package net.i2p.i2ptunnel.socks;
|
package net.i2p.i2ptunnel.socks;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
@@ -19,11 +20,29 @@ import net.i2p.util.Log;
|
|||||||
public abstract class SOCKSServer {
|
public abstract class SOCKSServer {
|
||||||
private static final Log _log = new Log(SOCKSServer.class);
|
private static final Log _log = new Log(SOCKSServer.class);
|
||||||
|
|
||||||
|
private static final String PROP_MAPPING_PREFIX = "ipmapping.";
|
||||||
|
|
||||||
/* Details about the connection requested by client */
|
/* Details about the connection requested by client */
|
||||||
protected String connHostName;
|
protected String connHostName;
|
||||||
protected int connPort;
|
protected int connPort;
|
||||||
protected int addressType;
|
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
|
* Perform server initialization (expecially regarding protected
|
||||||
* variables).
|
* variables).
|
||||||
|
@@ -54,7 +54,7 @@ public class SOCKSServerFactory {
|
|||||||
props.containsKey(I2PTunnelHTTPClientBase.PROP_PW)) {
|
props.containsKey(I2PTunnelHTTPClientBase.PROP_PW)) {
|
||||||
throw new SOCKSException("SOCKS 4/4a not supported when authorization is required");
|
throw new SOCKSException("SOCKS 4/4a not supported when authorization is required");
|
||||||
}
|
}
|
||||||
serv = new SOCKS4aServer(s);
|
serv = new SOCKS4aServer(s, props);
|
||||||
break;
|
break;
|
||||||
case 0x05:
|
case 0x05:
|
||||||
// SOCKS version 5
|
// SOCKS version 5
|
||||||
|
Reference in New Issue
Block a user