Search in sources :

Example 6 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class IndexBean method start.

private String start() {
    if (_tunnel < 0)
        return "Invalid tunnel";
    List<TunnelController> controllers = _group.getControllers();
    if (_tunnel >= controllers.size())
        return "Invalid tunnel";
    TunnelController controller = controllers.get(_tunnel);
    controller.startTunnelBackground();
    // give the messages a chance to make it to the window
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
    }
    // FIXME name will be HTML escaped twice
    return _t("Starting tunnel") + ' ' + getTunnelName(_tunnel) + "...";
}
Also used : TunnelController(net.i2p.i2ptunnel.TunnelController)

Example 7 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class IndexBean method stop.

private String stop() {
    if (_tunnel < 0)
        return "Invalid tunnel";
    List<TunnelController> controllers = _group.getControllers();
    if (_tunnel >= controllers.size())
        return "Invalid tunnel";
    TunnelController controller = controllers.get(_tunnel);
    controller.stopTunnel();
    // give the messages a chance to make it to the window
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
    }
    // FIXME name will be HTML escaped twice
    return _t("Stopping tunnel") + ' ' + getTunnelName(_tunnel) + "...";
}
Also used : TunnelController(net.i2p.i2ptunnel.TunnelController)

Example 8 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class IndexBean method modifyDestination.

/**
 * Modify or create a destination
 */
private String modifyDestination() {
    String privKeyFile = _config.getPrivKeyFile();
    if (privKeyFile == null)
        return "Private Key File not specified";
    TunnelController tun = getController(_tunnel);
    Properties config = getConfig();
    if (tun == null) {
        // creating new
        tun = new TunnelController(config, "", true);
        _group.addController(tun);
        saveChanges();
    } else if (tun.getIsRunning() || tun.getIsStarting()) {
        return "Tunnel must be stopped before modifying destination";
    }
    File keyFile = new File(privKeyFile);
    if (!keyFile.isAbsolute())
        keyFile = new File(_context.getConfigDir(), privKeyFile);
    PrivateKeyFile pkf = new PrivateKeyFile(keyFile);
    try {
        pkf.createIfAbsent();
    } catch (I2PException e) {
        return "Create private key file failed: " + e;
    } catch (IOException e) {
        return "Create private key file failed: " + e;
    }
    switch(_certType) {
        case Certificate.CERTIFICATE_TYPE_NULL:
        case Certificate.CERTIFICATE_TYPE_HIDDEN:
            pkf.setCertType(_certType);
            break;
        case Certificate.CERTIFICATE_TYPE_HASHCASH:
            pkf.setHashCashCert(_hashCashValue);
            break;
        case Certificate.CERTIFICATE_TYPE_SIGNED:
            if (_certSigner == null || _certSigner.trim().length() <= 0)
                return "No signing destination specified";
            // find the signer's key file...
            String signerPKF = null;
            for (int i = 0; i < getTunnelCount(); i++) {
                TunnelController c = getController(i);
                if (_certSigner.equals(c.getConfig("").getProperty(TunnelController.PROP_NAME)) || _certSigner.equals(c.getConfig("").getProperty(TunnelController.PROP_SPOOFED_HOST))) {
                    signerPKF = c.getConfig("").getProperty(TunnelController.PROP_FILE);
                    break;
                }
            }
            if (signerPKF == null || signerPKF.length() <= 0)
                return "Signing destination " + _certSigner + " not found";
            if (privKeyFile.equals(signerPKF))
                return "Self-signed destinations not allowed";
            Certificate c = pkf.setSignedCert(new PrivateKeyFile(signerPKF));
            if (c == null)
                return "Signing failed - does signer destination exist?";
            break;
        default:
            return "Unknown certificate type";
    }
    Destination newdest;
    try {
        pkf.write();
        newdest = pkf.getDestination();
    } catch (I2PException e) {
        return "Modification failed: " + e;
    } catch (IOException e) {
        return "Modification failed: " + e;
    }
    return "Destination modified - " + "New Base32 is " + newdest.toBase32() + "New Destination is " + newdest.toBase64();
}
Also used : I2PException(net.i2p.I2PException) Destination(net.i2p.data.Destination) TunnelController(net.i2p.i2ptunnel.TunnelController) PrivateKeyFile(net.i2p.data.PrivateKeyFile) IOException(java.io.IOException) Properties(java.util.Properties) PrivateKeyFile(net.i2p.data.PrivateKeyFile) File(java.io.File) Certificate(net.i2p.data.Certificate)

Example 9 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class GeneralHelper method getCustomOptionsString.

public String getCustomOptionsString(int tunnel) {
    TunnelController tun = getController(tunnel);
    if (tun != null) {
        Properties opts = tun.getClientOptionProps();
        if (opts == null)
            return "";
        boolean isMD5Proxy = TunnelController.TYPE_HTTP_CLIENT.equals(tun.getType()) || TunnelController.TYPE_CONNECT.equals(tun.getType());
        Map<String, String> sorted = new TreeMap<String, String>();
        for (Map.Entry<Object, Object> e : opts.entrySet()) {
            String key = (String) e.getKey();
            if (TunnelConfig._noShowSet.contains(key))
                continue;
            // hide for SOCKS until migrated to MD5
            if ((!isMD5Proxy) && TunnelConfig._nonProxyNoShowSet.contains(key))
                continue;
            sorted.put(key, (String) e.getValue());
        }
        if (sorted.isEmpty())
            return "";
        StringBuilder buf = new StringBuilder(64);
        boolean space = false;
        for (Map.Entry<String, String> e : sorted.entrySet()) {
            if (space)
                buf.append(' ');
            else
                space = true;
            buf.append(e.getKey()).append('=').append(e.getValue());
        }
        return DataHelper.escapeHTML(buf.toString());
    } else {
        return "";
    }
}
Also used : TunnelController(net.i2p.i2ptunnel.TunnelController) Properties(java.util.Properties) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 10 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class GeneralHelper method getPrivateKeyFile.

/**
 *  @return path, non-null, non-empty
 */
public String getPrivateKeyFile(TunnelControllerGroup tcg, int tunnel) {
    TunnelController tun = getController(tcg, tunnel);
    if (tun != null) {
        String rv = tun.getPrivKeyFile();
        if (rv != null)
            return rv;
    }
    if (tunnel < 0)
        tunnel = tcg == null ? 999 : tcg.getControllers().size();
    String rv = "i2ptunnel" + tunnel + "-privKeys.dat";
    // Don't default to a file that already exists,
    // which could happen after other tunnels are deleted.
    int i = 0;
    while ((new File(_context.getConfigDir(), rv)).exists()) {
        rv = "i2ptunnel" + tunnel + '.' + (++i) + "-privKeys.dat";
    }
    return rv;
}
Also used : TunnelController(net.i2p.i2ptunnel.TunnelController) SecureFile(net.i2p.util.SecureFile) PrivateKeyFile(net.i2p.data.PrivateKeyFile) File(java.io.File)

Aggregations

TunnelController (net.i2p.i2ptunnel.TunnelController)14 File (java.io.File)5 PrivateKeyFile (net.i2p.data.PrivateKeyFile)5 Properties (java.util.Properties)4 IOException (java.io.IOException)3 SecureFile (net.i2p.util.SecureFile)3 I2PException (net.i2p.I2PException)2 Destination (net.i2p.data.Destination)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Certificate (net.i2p.data.Certificate)1 Hash (net.i2p.data.Hash)1 SessionKey (net.i2p.data.SessionKey)1 TunnelControllerGroup (net.i2p.i2ptunnel.TunnelControllerGroup)1 ConvertToHash (net.i2p.util.ConvertToHash)1