Console: Start rework of /configkeyring for LS2

Not hooked up yet - WIP
This commit is contained in:
zzz
2019-05-27 15:44:51 +00:00
parent 90e6458428
commit 73b00eb206
4 changed files with 110 additions and 5 deletions

View File

@ -2,10 +2,13 @@ package net.i2p.router.web.helpers;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.i2p.data.BlindData;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.PrivateKey;
import net.i2p.data.SessionKey; import net.i2p.data.SessionKey;
import net.i2p.router.TunnelPoolSettings; import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.web.HelperBase; import net.i2p.router.web.HelperBase;
@ -39,12 +42,18 @@ public class ConfigKeyringHelper extends HelperBase {
/** /**
* @since 0.9.33 moved from PersistentKeyRing * @since 0.9.33 moved from PersistentKeyRing
* @param local true for local (Enc. LS1 only), false for remote (all types)
*/ */
private void render(StringBuilder buf, boolean local) { private void render(StringBuilder buf, boolean local) {
buf.append("\n<table class=\"configtable\"><tr><th align=\"left\">").append(_t("Destination")) buf.append("\n<table class=\"configtable\"><tr><th align=\"left\">").append(_t("Destination"))
.append("<th align=\"left\">").append(_t("Name")) .append("<th align=\"left\">").append(_t("Name"));
.append("<th align=\"left\">").append(_t("Encryption Key")) if (!local)
.append("</tr>"); buf.append("<th align=\"left\">").append(_t("Type"));
buf.append("<th align=\"left\">").append(_t("Encryption Key"));
if (!local)
buf.append("<th align=\"left\">").append(_t("Lookup Password"));
buf.append("</tr>");
// Enc. LS1
for (Map.Entry<Hash, SessionKey> e : _context.keyRing().entrySet()) { for (Map.Entry<Hash, SessionKey> e : _context.keyRing().entrySet()) {
Hash h = e.getKey(); Hash h = e.getKey();
if (local != _context.clientManager().isLocal(h)) if (local != _context.clientManager().isLocal(h))
@ -63,10 +72,64 @@ public class ConfigKeyringHelper extends HelperBase {
buf.append(host); buf.append(host);
} }
buf.append("</td><td>"); buf.append("</td><td>");
if (!local)
buf.append(_t("Encrypted")).append("</td><td>");
SessionKey sk = e.getValue(); SessionKey sk = e.getValue();
buf.append(sk.toBase64()); buf.append(sk.toBase64());
if (!local)
buf.append("</td><td>");
buf.append("</td>\n"); buf.append("</td>\n");
} }
// LS2
if (!local) {
List<BlindData> bdata = _context.netDb().getBlindData();
// TODO sort by hostname
for (BlindData bd : bdata) {
Hash h = bd.getDestHash();
if (h == null)
continue;
buf.append("\n<tr><td>");
buf.append(h.toBase32());
buf.append("</td><td>");
String host = _context.namingService().reverseLookup(h);
if (host != null)
buf.append(host);
buf.append("</td><td>");
int type = bd.getAuthType();
PrivateKey pk = bd.getAuthPrivKey();
String secret = bd.getSecret();
String s;
if (type == BlindData.AUTH_DH) {
if (secret != null)
s = _t("Blinded with lookup password and per-user key");
else
s = _t("Blinded with per-user key");
} else if (type == BlindData.AUTH_PSK) {
if (secret != null)
s = _t("Blinded with lookup password and shared key");
else
s = _t("Blinded with shared key");
} else {
if (secret != null)
s = _t("Blinded with lookup password");
else
s = _t("Blinded");
}
buf.append(s);
buf.append("</td><td>");
if (pk != null) {
// display pubkey for DH for sharing with server
if (type == BlindData.AUTH_DH)
buf.append(pk.toPublic().toBase64());
else
buf.append(pk.toBase64());
}
buf.append("</td><td>");
if (secret != null)
buf.append(secret);
buf.append("</td><tr>");
}
}
buf.append("</table>\n"); buf.append("</table>\n");
} }
} }

View File

@ -38,10 +38,31 @@
</td> </td>
</tr><tr> </tr><tr>
<td align="right"><b><%=intl._t("Full destination, name, base 32, or hash")%>:</b></td> <td align="right"><b><%=intl._t("Full destination, name, base 32, or hash")%>:</b></td>
<td><textarea name="peer" cols="44" rows="1" style="height: 3em;" wrap="off" spellcheck="false"></textarea></td> <td><input type="text" name="peer" size="55"></td>
</tr><tr>
<td align="right"><b><%=intl._t("Type")%>:</b></td>
<td><select id="encryptMode" name="encryptMode" class="selectbox">
<option title="<%=intl._t("Only clients with the encryption key will be able to connect")%>" value="1">
<%=intl._t("Encrypted")%></option>
<option title="<%=intl._t("Prevents server discovery by floodfills")%>" value="2">
<%=intl._t("Blinded")%></option>
<option title="<%=intl._t("Only clients with the password will be able to connect")%>" value="3">
<%=intl._t("Blinded with lookup password")%></option>
<option title="<%=intl._t("Only clients with the encryption key will be able to connect")%>" value="4">
<%=intl._t("Blinded with shared key")%></option>
<option title="<%=intl._t("Only clients with the password and key will be able to connect")%>" value="5">
<%=intl._t("Blinded with lookup password and shared key")%></option>
<option title="<%=intl._t("Only clients with the encryption key will be able to connect")%>" value="8">
<%=intl._t("Blinded with per-user key")%> (DH)</option>
<option title="<%=intl._t("Only clients with the password and key will be able to connect")%>" value="9">
<%=intl._t("Blinded with lookup password and per-user key")%> (DH)</option>
</select></td>
</tr><tr> </tr><tr>
<td align="right"><b><%=intl._t("Encryption Key")%>:</b></td> <td align="right"><b><%=intl._t("Encryption Key")%>:</b></td>
<td><input type="text" size="55" name="key" ></td> <td><input type="text" size="55" name="key" title="<%=intl._t("Leave blank for DH, will be generated automatically")%>"></td>
</tr><tr>
<td align="right"><b><%=intl._t("Optional lookup password")%>:</b></td>
<td><input type="password" name="nofilter_blindedPassword" title="<%=intl._t("Set password required to access this service")%>" class="freetext password" /></td>
</tr><tr> </tr><tr>
<td align="right" colspan="2"> <td align="right" colspan="2">
<input type="reset" class="cancel" value="<%=intl._t("Cancel")%>" > <input type="reset" class="cancel" value="<%=intl._t("Cancel")%>" >

View File

@ -8,6 +8,8 @@ import java.io.InputStreamReader;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.i2p.crypto.Blinding; import net.i2p.crypto.Blinding;
@ -225,6 +227,16 @@ class BlindCache {
} }
} }
/**
* For console ConfigKeyringHelper
* @since 0.9.41
*/
public synchronized List<BlindData> getData() {
List<BlindData> rv = new ArrayList<BlindData>(_cache.size());
rv.addAll(_cache.values());
return rv;
}
/** /**
* Load from file. * Load from file.
* Format: * Format:

View File

@ -16,6 +16,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -493,6 +494,14 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
_blindCache.addToCache(bd); _blindCache.addToCache(bd);
} }
/**
* For console ConfigKeyringHelper
* @since 0.9.41
*/
public List<BlindData> getBlindData() {
return _blindCache.getData();
}
/** /**
* @return RouterInfo, LeaseSet, or null, validated * @return RouterInfo, LeaseSet, or null, validated
* @since 0.8.3 * @since 0.8.3