From 4996c053619c5796df18af956475b42d0914ae31 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 5 May 2020 14:38:04 +0000 Subject: [PATCH] i2ptunnel: Add ECIES persistent key support Fix changing enc type on servers --- .../net/i2p/i2ptunnel/TunnelController.java | 10 +++++-- .../net/i2p/i2ptunnel/ui/TunnelConfig.java | 30 ++++++++++++++++--- history.txt | 18 +++++++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index 1c5a133f51..50c8d26247 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -1056,8 +1056,14 @@ public class TunnelController implements Logging { public String getListenPort() { return _config.getProperty(PROP_LISTEN_PORT); } public String getTargetDestination() { return _config.getProperty(PROP_DEST); } public String getProxyList() { return _config.getProperty(PROP_PROXIES); } - /** default true */ - public String getSharedClient() { return _config.getProperty(PROP_SHARED, "true"); } + + /** default true for clients, always false for servers */ + public String getSharedClient() { + if (!isClient()) + return "false"; + return _config.getProperty(PROP_SHARED, "true"); + } + /** default true */ public boolean getStartOnLoad() { return Boolean.parseBoolean(_config.getProperty(PROP_START, "true")); } public boolean getPersistentClientKey() { return Boolean.parseBoolean(_config.getProperty(OPT_PERSISTENT)); } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java index fb072c1296..7583f2e3f3 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java @@ -15,7 +15,9 @@ import java.util.concurrent.ConcurrentHashMap; import net.i2p.I2PAppContext; import net.i2p.client.I2PClient; +import net.i2p.crypto.EncType; import net.i2p.crypto.KeyGenerator; +import net.i2p.crypto.KeyPair; import net.i2p.crypto.SigType; import net.i2p.data.Base64; import net.i2p.data.DataHelper; @@ -847,14 +849,34 @@ public class TunnelConfig { SigType type = _dest.getSigType(); SimpleDataStructure keys[] = KeyGenerator.getInstance().generateSigningKeys(type); config.setProperty(p, type.name() + ':' + keys[1].toBase64()); - p = OPT + "i2cp.leaseSetPrivateKey"; - keys = KeyGenerator.getInstance().generatePKIKeys(); - config.setProperty(p, "ELGAMAL_2048:" + keys[1].toBase64()); - // TODO ECIES key } catch (GeneralSecurityException gse) { // so much for that } } + // persistent LS encryption keys + // multiple types as of 0.9.46, add missing ones + p = OPT + "i2cp.leaseSetPrivateKey"; + String skeys = config.getProperty(p); + // normalize it first to make the code below easier + if (skeys != null && skeys.length() > 0 && !skeys.contains(":")) + config.setProperty(p, "ELGAMAL_2048:" + skeys); + String senc = config.getProperty(OPT + "i2cp.leaseSetEncType", "0"); + String[] senca = DataHelper.split(senc, ","); + // for each configured enc type, generate a key if we don't have it + for (int i = 0; i < senca.length; i++) { + EncType type = EncType.parseEncType(senca[i]); + if (type != null && type.isAvailable()) { + String stype = type.toString(); + skeys = config.getProperty(p, ""); + if (!skeys.contains(stype + ':')) { + KeyPair keys = KeyGenerator.getInstance().generatePKIKeys(type); + if (skeys.length() > 0) + config.setProperty(p, skeys + ',' + stype + ':' + keys.getPrivate().toBase64()); + else + config.setProperty(p, stype + ':' + keys.getPrivate().toBase64()); + } + } + } } return config; diff --git a/history.txt b/history.txt index 9f30c55c56..d43b1cf673 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,21 @@ +2020-05-05 zzz + * Build: Use --java2 for msgfmt + * i2ptunnel: + - Add ECIES persistent key support + - Fix changing enc type on servers + - Remove experts label from dual-key option + * Ratchet: Add padding based on optimal message size + +2020-05-04 zzz + * Console: Add log clear buttons (ticket #2449) + * i2ptunnel: Copy over all relevant options to other shared clients + when saving, not just tunnel quantity and length (ticket #1545) + +2020-05-02 zzz + * eepsite: Fix RTL issues on Arabic help page (ticket #2731) + * i2ptunnel: Disable I2CP gzip for HTTP server tunnels + * i2psnark: Disable I2CP gzip + 2020-05-01 zzz * Ratchet: Fix NPE ratcheting IB NSR tagset diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index ea17ad55f3..e1f87e077d 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 15; + public final static long BUILD = 16; /** for example "-test" */ public final static String EXTRA = "";