From 726adaf2bb1f1954de80fd0566524d2bb413ca2e Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 22 Jan 2016 22:26:46 +0000 Subject: [PATCH] Add identicons to i2ptunnel address helper conflict page. Clean up text on the conflict page for readability. --- .../i2p/i2ptunnel/I2PTunnelHTTPClient.java | 47 ++++++++++++++++++- .../proxy/ahelper-conflict-header.ht | 4 +- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 557b81bc3f..836d769554 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -34,6 +34,7 @@ import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.data.Hash; import net.i2p.i2ptunnel.localServer.LocalHTTPServer; +import net.i2p.util.ConvertToHash; import net.i2p.util.EventDispatcher; import net.i2p.util.Log; import net.i2p.util.PortMapper; @@ -706,9 +707,51 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn String conflictURL = conflictURI.toASCIIString(); String header = getErrorPage("ahelper-conflict", ERR_AHELPER_CONFLICT); out.write(header.getBytes("UTF-8")); - out.write(_t("To visit the destination in your host database, click <a href=\"{0}\">here</a>. To visit the conflicting addresshelper destination, click <a href=\"{1}\">here</a>.", + out.write("<p>".getBytes("UTF-8")); + out.write(_t("To visit the destination in your address book, click <a href=\"{0}\">here</a>. To visit the conflicting addresshelper destination, click <a href=\"{1}\">here</a>.", trustedURL, conflictURL).getBytes("UTF-8")); - out.write("</p></div>".getBytes("UTF-8")); + out.write("</p>".getBytes("UTF-8")); + Hash h1 = ConvertToHash.getHash(requestURI.getHost()); + Hash h2 = ConvertToHash.getHash(ahelperKey); + if (h1 != null && h2 != null) { + // Do we need to replace http://127.0.0.1:7657 + // Get the registered host and port from the PortMapper. + final String unset = "*unset*"; + final String httpHost = _context.portMapper().getActualHost(PortMapper.SVC_CONSOLE, unset); + final String httpsHost = _context.portMapper().getActualHost(PortMapper.SVC_HTTPS_CONSOLE, unset); + final int httpPort = _context.portMapper().getPort(PortMapper.SVC_CONSOLE, 7657); + final int httpsPort = _context.portMapper().getPort(PortMapper.SVC_HTTPS_CONSOLE, -1); + final boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset); + final int cport = httpsOnly ? httpsPort : httpPort; + String chost = httpsOnly ? httpsHost : httpHost; + if (chost.equals(unset)) + chost = "127.0.0.1"; + String chostport; + if (httpsOnly || cport != 7657 || !chost.equals("127.0.0.1")) + chostport = (httpsOnly ? "https://" : "http://") + chost + ':' + cport; + else + chostport = "http://127.0.0.1:7657"; + out.write(("\n<table class=\"conflict\"><tr><th align=\"center\">" + + "<a href=\"" + trustedURL + "\">").getBytes("UTF-8")); + out.write(_t("Destination for {0} in address book", requestURI.getHost()).getBytes("UTF-8")); + out.write(("</a></th>\n<th align=\"center\">" + + "<a href=\"" + conflictURL + "\">").getBytes("UTF-8")); + out.write(_t("Conflicting address helper destination").getBytes("UTF-8")); + out.write(("</a></th></tr>\n<tr><td align=\"center\">" + + "<a href=\"" + trustedURL + "\">" + + "<img src=\"" + + chostport + "/imagegen/id?s=160&c=" + + h1.toBase64().replace("=", "%3d") + + "\" width=\"160\" height=\"160\"></a>\n").getBytes("UTF-8")); + out.write(("</td>\n<td align=\"center\">" + + "<a href=\"" + conflictURL + "\">" + + "<img src=\"" + + chostport + "/imagegen/id?s=160&c=" + + h2.toBase64().replace("=", "%3d") + + "\" width=\"160\" height=\"160\"></a>\n").getBytes("UTF-8")); + out.write("</td></tr></table>".getBytes("UTF-8")); + } + out.write("</div>".getBytes("UTF-8")); writeFooter(out); } reader.drain(); diff --git a/installer/resources/proxy/ahelper-conflict-header.ht b/installer/resources/proxy/ahelper-conflict-header.ht index 3222013748..02dbac2ae2 100644 --- a/installer/resources/proxy/ahelper-conflict-header.ht +++ b/installer/resources/proxy/ahelper-conflict-header.ht @@ -18,9 +18,9 @@ Proxy-Connection: close <div class="warning" id="warning"> <h3>_("Warning: Destination Key Conflict")</h3> <p> -_("The addresshelper link you followed specifies a different destination key than a host entry in your host database.") +_("The address helper link you followed specifies a different destination key than the entry in your address book.") _("Someone could be trying to impersonate another website, or people have given two websites identical names.") </p> <p> -_("You can resolve the conflict by considering which key you trust, and either discarding the addresshelper link, discarding the host entry from your host database, or naming one of them differently.") +_("Resolve the conflict by deciding which key you trust, and then either ignore the address helper link, or delete the host entry from your address book and click the address helper link again.") </p> -- GitLab