Changeset 1756997


Ignore:
Timestamp:
Dec 19, 2004 11:04:56 AM (16 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
81f04ca
Parents:
ec11ea4
git-author:
jrandom <jrandom> (12/19/04 11:04:56)
git-committer:
zzz <zzz@…> (12/19/04 11:04:56)
Message:

2004-12-19 jrandom

  • Added a new i2ptunnel type: 'httpserver', allowing you to specify what hostname should be sent to the webserver. By default, new installs will have an httpserver pointing at their jetty instance with the spoofed name 'mysite.i2p' (editable on the /i2ptunnel/edit.jsp page).
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java

    rec11ea4 r1756997  
    230230        } else if ("server".equals(cmdname)) {
    231231            runServer(args, l);
     232        } else if ("httpserver".equals(cmdname)) {
     233            runHttpServer(args, l);
    232234        } else if ("textserver".equals(cmdname)) {
    233235            runTextServer(args, l);
     
    282284        l.log("ping <args>");
    283285        l.log("server <host> <port> <privkeyfile>");
     286        l.log("httpserver <host> <port> <spoofedhost> <privkeyfile>");
    284287        l.log("textserver <host> <port> <privkey>");
    285288        l.log("genkeys <privkeyfile> [<pubkeyfile>]");
     
    367370            l.log("server <host> <port> <privkeyfile>");
    368371            l.log("  creates a server that sends all incoming data\n" + "  of its destination to host:port.");
     372            notifyEvent("serverTaskId", new Integer(-1));
     373        }
     374    }
     375
     376    /**
     377     * Run the HTTP server pointing at the host and port specified using the private i2p
     378     * destination loaded from the specified file, replacing the HTTP headers
     379     * so that the Host: specified is the one spoofed. <p />
     380     *
     381     * Sets the event "serverTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error)
     382     * Also sets the event "openServerResult" = "ok" or "error" (displaying "Ready!" on the logger after
     383     * 'ok').  So, success = serverTaskId != -1 and openServerResult = ok.
     384     *
     385     * @param args {hostname, portNumber, spoofedHost, privKeyFilename}
     386     * @param l logger to receive events and output
     387     */
     388    public void runHttpServer(String args[], Logging l) {
     389        if (args.length == 4) {
     390            InetAddress serverHost = null;
     391            int portNum = -1;
     392            File privKeyFile = null;
     393            try {
     394                serverHost = InetAddress.getByName(args[0]);
     395            } catch (UnknownHostException uhe) {
     396                l.log("unknown host");
     397                _log.error(getPrefix() + "Error resolving " + args[0], uhe);
     398                notifyEvent("serverTaskId", new Integer(-1));
     399                return;
     400            }
     401
     402            try {
     403                portNum = Integer.parseInt(args[1]);
     404            } catch (NumberFormatException nfe) {
     405                l.log("invalid port");
     406                _log.error(getPrefix() + "Port specified is not valid: " + args[1], nfe);
     407                notifyEvent("serverTaskId", new Integer(-1));
     408                return;
     409            }
     410
     411            String spoofedHost = args[2];
     412           
     413            privKeyFile = new File(args[3]);
     414            if (!privKeyFile.canRead()) {
     415                l.log("private key file does not exist");
     416                _log.error(getPrefix() + "Private key file does not exist or is not readable: " + args[3]);
     417                notifyEvent("serverTaskId", new Integer(-1));
     418                return;
     419            }
     420            I2PTunnelHTTPServer serv = new I2PTunnelHTTPServer(serverHost, portNum, privKeyFile, args[3], spoofedHost, l, (EventDispatcher) this, this);
     421            serv.setReadTimeout(readTimeout);
     422            serv.startRunning();
     423            addtask(serv);
     424            notifyEvent("serverTaskId", new Integer(serv.getId()));
     425            return;
     426        } else {
     427            l.log("httpserver <host> <port> <spoofedhost> <privkeyfile>");
     428            l.log("  creates an HTTP server that sends all incoming data\n"
     429                  + "  of its destination to host:port., filtering the HTTP\n"
     430                  + "  headers so it looks like the request is to the spoofed host.");
    369431            notifyEvent("serverTaskId", new Integer(-1));
    370432        }
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java

    rec11ea4 r1756997  
    4141    boolean finished = false;
    4242    HashMap ostreams, sockets;
    43     byte[] initialData;
     43    byte[] initialI2PData;
     44    byte[] initialSocketData;
    4445    /** when the last data was sent/received (or -1 if never) */
    4546    private long lastActivityOn;
     
    5455    private volatile long __forwarderId;
    5556   
    56     public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialData, List sockList) {
    57         this(s, i2ps, slock, initialData, sockList, null);
    58     }
    59     public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialData, List sockList, Runnable onTimeout) {
     57    public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List sockList) {
     58        this(s, i2ps, slock, initialI2PData, null, sockList, null);
     59    }
     60    public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List sockList) {
     61        this(s, i2ps, slock, initialI2PData, initialSocketData, sockList, null);
     62    }
     63    public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List sockList, Runnable onTimeout) {
     64        this(s, i2ps, slock, initialI2PData, null, sockList, onTimeout);
     65    }
     66    public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List sockList, Runnable onTimeout) {
    6067        this.sockList = sockList;
    6168        this.s = s;
    6269        this.i2ps = i2ps;
    6370        this.slock = slock;
    64         this.initialData = initialData;
     71        this.initialI2PData = initialI2PData;
     72        this.initialSocketData = initialSocketData;
    6573        this.onTimeout = onTimeout;
    6674        lastActivityOn = -1;
     
    112120            InputStream i2pin = i2ps.getInputStream();
    113121            OutputStream i2pout = i2ps.getOutputStream(); //new BufferedOutputStream(i2ps.getOutputStream(), MAX_PACKET_SIZE);
    114             if (initialData != null) {
     122            if (initialI2PData != null) {
    115123                synchronized (slock) {
    116                     i2pout.write(initialData);
     124                    i2pout.write(initialI2PData);
    117125                    //i2pout.flush();
    118126                }
    119127            }
     128            if (initialSocketData != null) {
     129                out.write(initialSocketData);
     130            }
    120131            if (_log.shouldLog(Log.DEBUG))
    121                 _log.debug("Initial data " + (initialData != null ? initialData.length : 0)
    122                            + " written, starting forwarders");
     132                _log.debug("Initial data " + (initialI2PData != null ? initialI2PData.length : 0)
     133                           + " written to I2P, " + (initialSocketData != null ? initialSocketData.length : 0)
     134                           + " written to the socket, starting forwarders");
    123135            Thread t1 = new StreamForwarder(in, i2pout, true);
    124136            Thread t2 = new StreamForwarder(i2pin, out, false);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java

    rec11ea4 r1756997  
    3232    private final static Log _log = new Log(I2PTunnelServer.class);
    3333
    34     private I2PSocketManager sockMgr;
    35     private I2PServerSocket i2pss;
    36 
    37     private Object lock = new Object(), slock = new Object();
    38 
    39     private InetAddress remoteHost;
    40     private int remotePort;
     34    protected I2PSocketManager sockMgr;
     35    protected I2PServerSocket i2pss;
     36
     37    private Object lock = new Object();
     38    protected Object slock = new Object();
     39
     40    protected InetAddress remoteHost;
     41    protected int remotePort;
    4142
    4243    private Logging l;
     
    4445    private static final long DEFAULT_READ_TIMEOUT = -1; // 3*60*1000;
    4546    /** default timeout to 3 minutes - override if desired */
    46     private long readTimeout = DEFAULT_READ_TIMEOUT;
     47    protected long readTimeout = DEFAULT_READ_TIMEOUT;
    4748
    4849    public I2PTunnelServer(InetAddress host, int port, String privData, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java

    rec11ea4 r1756997  
    5858        _messages = new ArrayList(4);
    5959        _running = false;
    60         if (createKey && ("server".equals(getType())) )
     60        if (createKey && ("server".equals(getType()) || "httpserver".equals(getType())) )
    6161            createPrivateKey();
    6262        _starting = getStartOnLoad();
     
    133133        } else if ("server".equals(type)) {
    134134            startServer();
     135        } else if ("httpserver".equals(type)) {
     136            startHttpServer();
    135137        } else {
    136138            if (_log.shouldLog(Log.ERROR))
     
    203205        String privKeyFile = getPrivKeyFile();
    204206        _tunnel.runServer(new String[] { targetHost, targetPort, privKeyFile }, this);
     207        acquire();
     208        _running = true;
     209    }
     210   
     211    private void startHttpServer() {
     212        setI2CPOptions();
     213        setSessionOptions();
     214        String targetHost = getTargetHost();
     215        String targetPort = getTargetPort();
     216        String spoofedHost = getSpoofedHost();
     217        String privKeyFile = getPrivKeyFile();
     218        _tunnel.runHttpServer(new String[] { targetHost, targetPort, spoofedHost, privKeyFile }, this);
    205219        acquire();
    206220        _running = true;
     
    298312    public String getTargetHost() { return _config.getProperty("targetHost"); }
    299313    public String getTargetPort() { return _config.getProperty("targetPort"); }
     314    public String getSpoofedHost() { return _config.getProperty("spoofedHost"); }
    300315    public String getPrivKeyFile() { return _config.getProperty("privKeyFile"); }
    301316    public String getListenPort() { return _config.getProperty("listenPort"); }
     
    315330        else if ("server".equals(type))
    316331            getServerSummary(buf);
     332        else if ("httpserver".equals(type))
     333            getHttpServerSummary(buf);
    317334        else
    318335            buf.append("Unknown type ").append(type);
     
    368385    }
    369386   
     387    private void getHttpServerSummary(StringBuffer buf) {
     388        String description = getDescription();
     389        if ( (description != null) && (description.trim().length() > 0) )
     390            buf.append("<i>").append(description).append("</i><br />\n");
     391        buf.append("Server tunnel pointing at port ").append(getTargetPort());
     392        buf.append(" on ").append(getTargetHost());
     393        buf.append(" for the site ").append(getSpoofedHost());
     394        buf.append("<br />\n");
     395        buf.append("Private destination loaded from ").append(getPrivKeyFile()).append("<br />\n");
     396        getOptionSummary(buf);
     397    }
     398   
    370399    private void getOptionSummary(StringBuffer buf) {
    371400        String opts = getClientOptions();
     
    379408                if (dest != null) {
    380409                    buf.append("Destination hash: ").append(dest.calculateHash().toBase64()).append("<br />\n");
    381                     if ("server".equals(getType())) {
     410                    if ( ("server".equals(getType())) || ("httpserver".equals(getType())) ) {
    382411                        buf.append("Full destination: ");
    383412                        buf.append("<input type=\"text\" size=\"10\" onclick=\"this.select();\" ");
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/WebEditPageFormGenerator.java

    rec11ea4 r1756997  
    1919      "<option value=\"client\">Client tunnel</option>" +
    2020      "<option value=\"server\">Server tunnel</option>" +
     21      "<option value=\"httpserver\">HTTP server tunnel</option>" +
    2122      "</select> <input type=\"submit\" value=\"GO\" />" +
    2223      "</form>\n";
     
    4344        else if ("server".equals(type))
    4445            return getEditServerForm(controller, id);
     46        else if ("httpserver".equals(type))
     47            return getEditHttpServerForm(controller, id);
    4548        else
    4649            return "WTF, unknown type [" + type + "]";
     
    112115        else
    113116            buf.append("value=\"80\" ");
     117        buf.append(" /><br />\n");
     118       
     119        buf.append("<b>Private key file:</b> <input type=\"text\" name=\"privKeyFile\" value=\"");
     120        if ( (controller != null) && (controller.getPrivKeyFile() != null) ) {
     121            buf.append(controller.getPrivKeyFile()).append("\" /><br />");
     122        } else {
     123            buf.append("myServer.privKey\" /><br />");
     124            buf.append("<input type=\"hidden\" name=\"privKeyGenerate\" value=\"true\" />");
     125        }
     126       
     127        addOptions(buf, controller);
     128        buf.append("<input type=\"submit\" name=\"action\" value=\"Save\">\n");
     129        buf.append("<input type=\"submit\" name=\"action\" value=\"Remove\">\n");
     130        buf.append(" <i>confirm removal:</i> <input type=\"checkbox\" name=\"removeConfirm\" value=\"true\" />\n");
     131        buf.append("</form>\n");
     132        return buf.toString();
     133    }
     134   
     135    private static String getEditHttpServerForm(TunnelController controller, String id) {
     136        StringBuffer buf = new StringBuffer(1024);
     137        addGeneral(buf, controller, id);
     138        buf.append("<b>Type:</b> <i>HTTP server tunnel</i><input type=\"hidden\" name=\"type\" value=\"httpserver\" /><br />\n");
     139       
     140        buf.append("<b>Target host:</b> <input type=\"text\" size=\"40\" name=\"targetHost\" ");
     141        if ( (controller != null) && (controller.getTargetHost() != null) )
     142            buf.append("value=\"").append(controller.getTargetHost()).append("\" ");
     143        else
     144            buf.append("value=\"127.0.0.1\" ");
     145        buf.append(" /><br />\n");
     146       
     147        buf.append("<b>Target port:</b> <input type=\"text\" size=\"4\" name=\"targetPort\" ");
     148        if ( (controller != null) && (controller.getTargetPort() != null) )
     149            buf.append("value=\"").append(controller.getTargetPort()).append("\" ");
     150        else
     151            buf.append("value=\"80\" ");
     152        buf.append(" /><br />\n");
     153       
     154        buf.append("<b>Website hostname:</b> <input type=\"text\" size=\"16\" name=\"spoofedHost\" ");
     155        if ( (controller != null) && (controller.getSpoofedHost() != null) )
     156            buf.append("value=\"").append(controller.getSpoofedHost()).append("\" ");
     157        else
     158            buf.append("value=\"mysite.i2p\" ");
    114159        buf.append(" /><br />\n");
    115160       
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/WebEditPageHelper.java

    rec11ea4 r1756997  
    3939    private String _targetHost;
    4040    private String _targetPort;
     41    private String _spoofedHost;
    4142    private String _privKeyFile;
    4243    private boolean _startOnLoad;
     
    139140    public void setTargetPort(String port) {
    140141        _targetPort = (port != null ? port.trim() : null);
     142    }
     143    /** What host does this http server tunnel spoof */
     144    public void setSpoofedHost(String host) {
     145        _spoofedHost = (host != null ? host.trim() : null);
    141146    }
    142147    /** What filename is this server tunnel's private keys stored in */
     
    321326            if (_privKeyFile != null)
    322327                config.setProperty("privKeyFile", _privKeyFile);
     328        } else if ("httpserver".equals(_type)) {
     329            if (_targetHost != null)
     330                config.setProperty("targetHost", _targetHost);
     331            if (_targetPort != null)
     332                config.setProperty("targetPort", _targetPort);
     333            if (_privKeyFile != null)
     334                config.setProperty("privKeyFile", _privKeyFile);
     335            if (_spoofedHost != null)
     336                config.setProperty("spoofedHost", _spoofedHost);
    323337        } else {
    324338            return null;
  • apps/i2ptunnel/jsp/index.jsp

    rec11ea4 r1756997  
    2626  <option value="client">Client tunnel</option>
    2727  <option value="server">Server tunnel</option>
     28  <option value="httpserver">HTTP server tunnel</option>
    2829 </select> <input type="submit" value="GO" />
    2930</form>
  • core/java/src/net/i2p/data/DataHelper.java

    rec11ea4 r1756997  
    681681    public static String readLine(InputStream in) throws IOException {
    682682        StringBuffer buf = new StringBuffer(128);
    683 
     683        boolean ok = readLine(in, buf);
     684        if (ok)
     685            return buf.toString();
     686        else
     687            return null;
     688    }
     689    /**
     690     * Read in a line, placing it into the buffer (excluding the newline).
     691     *
     692     * @return true if the line was read, false if eof was reached before a
     693     *              newline was found
     694     */
     695    public static boolean readLine(InputStream in, StringBuffer buf) throws IOException {
    684696        int c = -1;
    685697        while ( (c = in.read()) != -1) {
     
    689701        }
    690702        if (c == -1)
    691             return null;
     703            return false;
    692704        else
    693             return buf.toString();
     705            return true;
    694706    }
    695707   
  • history.txt

    rec11ea4 r1756997  
    1 $Id: history.txt,v 1.111 2004/12/17 23:07:13 jrandom Exp $
     1$Id: history.txt,v 1.112 2004/12/19 01:25:27 scintilla Exp $
     2
     32004-12-19  jrandom
     4    * Added a new i2ptunnel type: 'httpserver', allowing you to specify what
     5      hostname should be sent to the webserver.  By default, new installs will
     6      have an httpserver pointing at their jetty instance with the spoofed
     7      name 'mysite.i2p' (editable on the /i2ptunnel/edit.jsp page).
    28
    392004-12-19  scintilla
  • installer/resources/i2ptunnel.config

    rec11ea4 r1756997  
    4343tunnel.3.name=eepsite
    4444tunnel.3.description=My eepsite
    45 tunnel.3.type=server
     45tunnel.3.type=httpserver
    4646tunnel.3.targetHost=127.0.0.1
    4747tunnel.3.targetPort=7658
     48tunnel.3.spoofedHost=mysite.i2p
    4849tunnel.3.privKeyFile=eepsite/eepPriv.dat
    4950tunnel.3.i2cpHost=127.0.0.1
  • router/java/src/net/i2p/router/RouterVersion.java

    rec11ea4 r1756997  
    1616 */
    1717public class RouterVersion {
    18     public final static String ID = "$Revision: 1.116 $ $Date: 2004/12/17 23:07:13 $";
     18    public final static String ID = "$Revision: 1.117 $ $Date: 2004/12/19 01:25:27 $";
    1919    public final static String VERSION = "0.4.2.4";
    20     public final static long BUILD = 1;
     20    public final static long BUILD = 2;
    2121    public static void main(String args[]) {
    2222        System.out.println("I2P Router version: " + VERSION);
Note: See TracChangeset for help on using the changeset viewer.