Console: Support deleting blinded entries on /configkeyring

This commit is contained in:
zzz
2019-05-30 14:26:11 +00:00
parent 6b3896c1f8
commit f049319500
6 changed files with 94 additions and 19 deletions

View File

@ -21,12 +21,12 @@ public class ConfigKeyringHandler extends FormHandler {
private String _peer;
private String _key;
private String _secret;
private String[] _revokes;
private int _mode;
@Override
protected void processForm() {
boolean adding = _action.equals(_t("Add key"));
if (adding || _action.equals(_t("Delete key"))) {
if (_action.equals(_t("Add key"))) {
if (_peer == null) {
addFormError(_t("You must enter a destination"));
return;
@ -36,7 +36,7 @@ public class ConfigKeyringHandler extends FormHandler {
// don't wait for several seconds for b33 lookup
h = ConvertToHash.getHash(_peer);
}
if (adding) {
byte[] b = null;
if (_mode == 1 || _mode == 4 || _mode == 5) {
if (_key == null) {
@ -166,18 +166,37 @@ public class ConfigKeyringHandler extends FormHandler {
addFormError(_t("Invalid destination") + ": " + iae.getMessage());
}
}
} else { // Delete
if (h != null && h.getData() != null) {
if (_context.clientManager().isLocal(h)) {
// don't bother translating
addFormError("Cannot remove key for local destination. Disable encryption in the Hidden Services Manager.");
} else if (_context.keyRing().remove(h) != null) {
addFormNotice(_t("Key for {0} removed from keyring", h.toBase32()));
} else {
addFormNotice(_t("Key for {0} not found in keyring", h.toBase32()));
} else if (_action.equals(_t("Delete key")) && _revokes != null) {
// these should all be b32s or b33s
for (String p : _revokes) {
boolean removed = false;
if (p.length() == 60) {
// don't wait for several seconds for b33 lookup
Hash h = ConvertToHash.getHash(p);
if (h != null) {
if (_context.clientManager().isLocal(h)) {
// don't bother translating
addFormError("Cannot remove key for local destination. Disable encryption in the Hidden Services Manager.");
} else if (_context.keyRing().remove(h) != null) {
removed = true;
}
}
} else if (p.length() > 60) {
try {
BlindData bd = Blinding.decode(_context, p);
if (bd != null) {
SigningPublicKey spk = bd.getUnblindedPubKey();
removed = _context.netDb().removeBlindData(spk);
}
} catch (IllegalArgumentException iae) {}
} else {
addFormError(_t("Invalid destination"));
addFormError(_t("Invalid destination") + ": " + p);
}
if (removed) {
addFormNotice(_t("Key for {0} removed from keyring", p));
} else {
addFormError(_t("Key for {0} not found in keyring", p));
}
}
} else {
@ -203,4 +222,7 @@ public class ConfigKeyringHandler extends FormHandler {
_mode = Integer.parseInt(m);
} catch (NumberFormatException nfe) {}
}
/** @since 0.9.41 */
public void setRevokeClient(String[] revokes) { _revokes = revokes; }
}

View File

@ -45,7 +45,10 @@ public class ConfigKeyringHelper extends HelperBase {
* @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"))
buf.append("\n<table class=\"configtable\"><tr>");
if (!local)
buf.append("<th align=\"left\">").append(_t("Delete"));
buf.append("<th align=\"left\">").append(_t("Destination"))
.append("<th align=\"left\">").append(_t("Name"));
if (!local)
buf.append("<th align=\"left\">").append(_t("Type"));
@ -59,7 +62,10 @@ public class ConfigKeyringHelper extends HelperBase {
if (local != _context.clientManager().isLocal(h))
continue;
buf.append("\n<tr><td>");
buf.append(h.toBase32());
String b32 = h.toBase32();
if (!local)
buf.append("<input value=\"").append(b32).append("\" type=\"checkbox\" name=\"revokeClient\" class=\"tickbox\"/></td><td>");
buf.append(b32);
buf.append("</td><td>");
Destination dest = _context.netDb().lookupDestinationLocally(h);
if (dest != null && local) {
@ -86,7 +92,10 @@ public class ConfigKeyringHelper extends HelperBase {
// TODO sort by hostname
for (BlindData bd : bdata) {
buf.append("\n<tr><td>");
buf.append(bd.toBase32());
String b32 = bd.toBase32();
if (!local)
buf.append("<input value=\"").append(b32).append("\" type=\"checkbox\" name=\"revokeClient\" class=\"tickbox\"/></td><td>");
buf.append(b32);
buf.append("</td><td>");
Hash h = bd.getDestHash();
if (h != null) {