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.StringWriter;
import java.util.List;
import java.util.Map;
import net.i2p.data.BlindData;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.data.PrivateKey;
import net.i2p.data.SessionKey;
import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.web.HelperBase;
@ -39,12 +42,18 @@ public class ConfigKeyringHelper extends HelperBase {
/**
* @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) {
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("Encryption Key"))
.append("</tr>");
.append("<th align=\"left\">").append(_t("Name"));
if (!local)
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()) {
Hash h = e.getKey();
if (local != _context.clientManager().isLocal(h))
@ -63,10 +72,64 @@ public class ConfigKeyringHelper extends HelperBase {
buf.append(host);
}
buf.append("</td><td>");
if (!local)
buf.append(_t("Encrypted")).append("</td><td>");
SessionKey sk = e.getValue();
buf.append(sk.toBase64());
if (!local)
buf.append("</td><td>");
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");
}
}