i2ptunnel: Add encrytion type selection to form

This commit is contained in:
zzz
2019-10-23 11:57:22 +00:00
parent b12e7214c8
commit db37745a1c
6 changed files with 116 additions and 10 deletions

View File

@ -55,10 +55,16 @@ public class GeneralHelper {
private final I2PAppContext _context;
protected final TunnelControllerGroup _group;
/**
* @param tcg may be null ???
*/
public GeneralHelper(TunnelControllerGroup tcg) {
this(I2PAppContext.getGlobalContext(), tcg);
}
/**
* @param tcg may be null ???
*/
public GeneralHelper(I2PAppContext context, TunnelControllerGroup tcg) {
_context = context;
_group = tcg;
@ -68,6 +74,10 @@ public class GeneralHelper {
return getController(_group, tunnel);
}
/**
* @param tcg may be null
* @return null if not found or tcg is null
*/
public static TunnelController getController(TunnelControllerGroup tcg, int tunnel) {
if (tunnel < 0) return null;
if (tcg == null) return null;
@ -696,6 +706,21 @@ public class GeneralHelper {
return type.getCode();
}
/**
* @param encType code
* @since 0.9.44
*/
public boolean hasEncType(int tunnel, int encType) {
String senc = getProperty(tunnel, "i2cp.leaseSetEncType", "0");
String[] senca = DataHelper.split(senc, ",");
String se = Integer.toString(encType);
for (int i = 0; i < senca.length; i++) {
if (se.equals(senca[i]))
return true;
}
return false;
}
/**
* Random keys
*/

View File

@ -632,6 +632,19 @@ public class TunnelConfig {
_otherOptions.put(I2PClient.PROP_SIGTYPE, val.trim());
}
/**
* Adds to existing, comma separated
* @since 0.9.44
*/
public void setEncType(String val) {
if (val != null) {
String p = _otherOptions.get("i2cp.leaseSetEncType");
if (p != null)
val = p + ',' + val;
_otherOptions.put("i2cp.leaseSetEncType", val);
}
}
/**
* Random keys
*/
@ -837,6 +850,7 @@ public class TunnelConfig {
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
}
@ -1062,7 +1076,8 @@ public class TunnelConfig {
I2PClient.PROP_SIGTYPE,
I2PTunnelHTTPClient.PROP_SSL_OUTPROXIES,
// following are mostly server but could also be persistent client
"inbound.randomKey", "outbound.randomKey", "i2cp.leaseSetSigningPrivateKey", "i2cp.leaseSetPrivateKey"
"inbound.randomKey", "outbound.randomKey", "i2cp.leaseSetSigningPrivateKey", "i2cp.leaseSetPrivateKey",
"i2cp.leaseSetEncType"
};
private static final String _otherServerOpts[] = {
"i2cp.reduceIdleTime", "i2cp.reduceQuantity", "i2cp.leaseSetKey", "i2cp.accessList",
@ -1071,7 +1086,8 @@ public class TunnelConfig {
PROP_MAX_STREAMS, I2PClient.PROP_SIGTYPE,
"inbound.randomKey", "outbound.randomKey", "i2cp.leaseSetSigningPrivateKey", "i2cp.leaseSetPrivateKey",
I2PTunnelServer.PROP_ALT_PKF,
"i2cp.leaseSetSecret", "i2cp.leaseSetType", "i2cp.leaseSetAuthType", "i2cp.leaseSetPrivKey"
"i2cp.leaseSetSecret", "i2cp.leaseSetType", "i2cp.leaseSetAuthType", "i2cp.leaseSetPrivKey",
"i2cp.leaseSetEncType"
};
private static final String _httpServerOpts[] = {
I2PTunnelHTTPServer.OPT_POST_WINDOW,

View File

@ -259,6 +259,14 @@ public class EditBean extends IndexBean {
return getTunnelStatus(tunnel) == GeneralHelper.NOT_RUNNING;
}
/**
* @param encType code
* @since 0.9.44
*/
public boolean hasEncType(int tunnel, int encType) {
return _helper.hasEncType(tunnel, encType);
}
/**
* Random keys, hidden in forms
* @since 0.9.18

View File

@ -1239,6 +1239,14 @@ public class IndexBean {
// Otherwise this only works on a new tunnel...
}
/**
* Adds to existing, comma separated
* @since 0.9.44
*/
public void setEncType(String s) {
_config.setEncType(s);
}
/**
* Random keys, hidden in forms
* @since 0.9.18

View File

@ -487,13 +487,12 @@
<%
} // if httpclient
if (true /* editBean.isAdvanced() */ ) {
int currentSigType = editBean.getSigType(curTunnel, tunnelType);
String disabled = editBean.canChangeSigType(curTunnel) ? "" : " disabled=\"disabled\" ";
int currentSigType = editBean.getSigType(curTunnel, tunnelType);
String disabled = editBean.canChangeSigType(curTunnel) ? "" : " disabled=\"disabled\" ";
%>
<tr>
<th colspan="2">
<%=intl._t("Signature type")%> <%-- (<%=intl._t("Experts only!")%>) --%>
<%=intl._t("Signature type")%>
</th>
</tr><tr>
<td colspan="2">
@ -529,6 +528,31 @@
</select>
</td>
</tr>
<%
if (editBean.isAdvanced()) {
boolean has0 = editBean.hasEncType(curTunnel, 0);
boolean has4 = editBean.hasEncType(curTunnel, 4);
%>
<tr>
<th colspan="2">
<%=intl._t("Encryption types")%>
</th>
</tr><tr>
<td colspan="2">
<span class="multiOption">
<label><input value="0" type="radio" id="startOnLoad" name="encType" <%=(has0 ? " checked=\"checked\"" : "")%> class="tickbox" />
ElGamal-2048</label>
</span>
<span class="multiOption">
<label><input value="4" type="radio" id="startOnLoad" name="encType" <%=(has4 ? " checked=\"checked\"" : "")%> class="tickbox" />
ECIES-X25519 (<%=intl._t("Experts only!")%>)</label>
</span>
<span class="multiOption">
<label><input value="0,4" type="radio" id="startOnLoad" name="encType" <%=((has0 && has4) ? " checked=\"checked\"" : "")%> class="tickbox" />
<%=intl._t("Both")%> (<%=intl._t("Experts only!")%>)</label>
</span>
</td>
</tr>
<%
} // isAdvanced

View File

@ -802,12 +802,11 @@
<%
**********************/
int currentSigType = editBean.getSigType(curTunnel, tunnelType);
if (true /* editBean.isAdvanced() */ ) {
String disabled = editBean.canChangeSigType(curTunnel) ? "" : " disabled=\"disabled\" ";
String disabled = editBean.canChangeSigType(curTunnel) ? "" : " disabled=\"disabled\" ";
%>
<tr>
<th colspan="2">
<%=intl._t("Signature type")%> <%-- (<%=intl._t("Experts only! Changes B32!")%>) --%>
<%=intl._t("Signature type")%>
</th>
</tr><tr>
<td colspan="2">
@ -838,7 +837,33 @@
</select>
</td>
</tr>
<% } // isAdvanced
<%
if (editBean.isAdvanced()) {
boolean has0 = editBean.hasEncType(curTunnel, 0);
boolean has4 = editBean.hasEncType(curTunnel, 4);
%>
<tr>
<th colspan="2">
<%=intl._t("Encryption types")%>
</th>
</tr><tr>
<td colspan="2">
<span class="multiOption">
<label><input value="0" type="radio" id="startOnLoad" name="encType" <%=(has0 ? " checked=\"checked\"" : "")%> class="tickbox" />
ElGamal-2048</label>
</span>
<span class="multiOption">
<label><input value="4" type="radio" id="startOnLoad" name="encType" <%=(has4 ? " checked=\"checked\"" : "")%> class="tickbox" />
ECIES-X25519 (<%=intl._t("Experts only!")%>)</label>
</span>
<span class="multiOption">
<label><input value="0,4" type="radio" id="startOnLoad" name="encType" <%=((has0 && has4) ? " checked=\"checked\"" : "")%> class="tickbox" />
<%=intl._t("Both")%> (<%=intl._t("Experts only!")%>)</label>
</span>
</td>
</tr>
<%
} // isAdvanced
/* alternate dest, only if current dest is set and is DSA_SHA1 */