broke i2ptunnel ircserver again

This commit is contained in:
dev
2009-02-28 01:39:58 +00:00
parent 467095f85e
commit 7f33eb4959

View File

@ -16,6 +16,7 @@ import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.Base32;
import net.i2p.util.EventDispatcher; import net.i2p.util.EventDispatcher;
import net.i2p.util.I2PThread; import net.i2p.util.I2PThread;
import net.i2p.util.Log; import net.i2p.util.Log;
@ -36,26 +37,27 @@ import net.i2p.util.Log;
* "custom options" section of i2ptunnel. * "custom options" section of i2ptunnel.
* - ircserver.cloakKey unset: Cloak with a random value that is persistent for * - ircserver.cloakKey unset: Cloak with a random value that is persistent for
* the life of this tunnel. This is the default. * the life of this tunnel. This is the default.
* - ircserver.cloakKey=none: Don't cloak. Users may be correlated with their
* (probably) shared clients destination.
* Of course if the ircd does cloaking than this is ok.
* - ircserver.cloakKey=somepassphrase: Cloak with the hash of the passphrase. Use this to * - ircserver.cloakKey=somepassphrase: Cloak with the hash of the passphrase. Use this to
* have consistent mangling across restarts, or to * have consistent mangling across restarts, or to
* have multiple IRC servers cloak consistently to * have multiple IRC servers cloak consistently to
* be able to track users even when they switch servers. * be able to track users even when they switch servers.
* Note: don't quote or put spaces in the passphrase, * Note: don't quote or put spaces in the passphrase,
* the i2ptunnel gui can't handle it. * the i2ptunnel gui can't handle it.
* - ircserver.fakeHostname=%f.b32.i2p: Set the fake hostname sent by I2PTunnel,
* %f is the full B32 destination hash
* %c is the cloaked hash.
* *
* There is no outbound filtering. * There is no outbound filtering.
* *
* @author zzz * @author zzz
*/ */
public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable { public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
public static final String PROP_CLOAK="ircserver.cloakKey";
public static final String PROP_HOSTNAME="ircserver.fakeHostname";
public static final String PROP_HOSTNAME_DEFAULT="%f.b32.i2p";
private static final Log _log = new Log(I2PTunnelIRCServer.class); private static final Log _log = new Log(I2PTunnelIRCServer.class);
private static final String PROP_CLOAK="ircserver.cloakKey";
private boolean _cloak;
private byte[] _cloakKey; // 32 bytes of stuff to scramble the dest with
/** /**
* @throws IllegalArgumentException if the I2PTunnel does not contain * @throws IllegalArgumentException if the I2PTunnel does not contain
@ -71,15 +73,14 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
private void initCloak(I2PTunnel tunnel) { private void initCloak(I2PTunnel tunnel) {
Properties opts = tunnel.getClientOptions(); Properties opts = tunnel.getClientOptions();
String passphrase = opts.getProperty(PROP_CLOAK); String passphrase = opts.getProperty(PROP_CLOAK);
_cloak = passphrase == null || !"none".equals(passphrase); if (passphrase == null) {
if (_cloak) { this.cloakKey = new byte[Hash.HASH_LENGTH];
if (passphrase == null) { tunnel.getContext().random().nextBytes(this.cloakKey);
_cloakKey = new byte[Hash.HASH_LENGTH]; } else {
tunnel.getContext().random().nextBytes(_cloakKey); this.cloakKey = SHA256Generator.getInstance().calculateHash(passphrase.trim().getBytes()).getData();
} else {
_cloakKey = SHA256Generator.getInstance().calculateHash(passphrase.trim().getBytes()).getData();
}
} }
this.hostname = opts.getProperty(PROP_HOSTNAME, PROP_HOSTNAME_DEFAULT);
} }
protected void blockingHandle(I2PSocket socket) { protected void blockingHandle(I2PSocket socket) {
@ -122,16 +123,17 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
* *
*/ */
String cloakDest(Destination d) { String cloakDest(Destination d) {
Hash h; String hf;
if (_cloak) { String hc;
byte[] b = new byte[d.size() + _cloakKey.length];
System.arraycopy(b, 0, d.toByteArray(), 0, d.size()); byte[] b = new byte[d.size() + this.cloakKey.length];
System.arraycopy(b, d.size(), _cloakKey, 0, _cloakKey.length); System.arraycopy(b, 0, d.toByteArray(), 0, d.size());
h = SHA256Generator.getInstance().calculateHash(b); System.arraycopy(b, d.size(), this.cloakKey, 0, this.cloakKey.length);
} else { hc = Base32.encode(SHA256Generator.getInstance().calculateHash(b).getData());
h = d.calculateHash();
} hf = Base32.encode(d.calculateHash().getData());
return h.toBase64().substring(0, 8) + ".i2p";
return this.hostname.replace("%f", hf).replace("%c", hc);
} }
/** keep reading until we see USER or SERVER */ /** keep reading until we see USER or SERVER */
@ -156,9 +158,10 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
if(field[0].charAt(0)==':') if(field[0].charAt(0)==':')
idx++; idx++;
try { command = field[idx++]; } try {
catch (IndexOutOfBoundsException ioobe) // wtf, server sent borked command? command = field[idx++];
{ } catch (IndexOutOfBoundsException ioobe) {
// wtf, server sent borked command?
throw new IOException("Dropping defective message: index out of bounds while extracting command."); throw new IOException("Dropping defective message: index out of bounds while extracting command.");
} }
@ -169,7 +172,7 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
// => // =>
// USER zzz1 abcd1234.i2p localhost :zzz // USER zzz1 abcd1234.i2p localhost :zzz
// this whole class is for these two lines... // this whole class is for these two lines...
buf.append("USER ").append(field[idx]).append(' ').append(newHostname).append(".i2p "); buf.append("USER ").append(field[idx]).append(' ').append(newHostname);
buf.append(field[idx+2]).append(' ').append(field[idx+3]).append("\r\n"); buf.append(field[idx+2]).append(' ').append(field[idx+3]).append("\r\n");
break; break;
} }
@ -181,4 +184,7 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
_log.debug("All done, sending: " + buf.toString()); _log.debug("All done, sending: " + buf.toString());
return buf.toString(); return buf.toString();
} }
private byte[] cloakKey; // 32 bytes of stuff to scramble the dest with
private String hostname;
} }