[tor-commits] [onionoo/master] Fix searching by hashed fingerprint.
karsten at torproject.org
karsten at torproject.org
Thu Apr 25 06:56:58 UTC 2013
commit b30bb951cb3e1d9b1bc3cfc479ef4aadf8bca834
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Thu Apr 25 08:49:05 2013 +0200
Fix searching by hashed fingerprint.
We support searches for relays by hashed fingerprint and for bridges by
hashed hashed fingerprint. The reason is that applications should always
hash full fingerprints in order not to accidentally leak non-hashed bridge
fingerprints.
However, the spec is vague about searching for beginnings of hashed relay
fingerprints and hashed hashed bridge fingerprints. The current code did
not support those, but it should. This commit changes that.
---
src/org/torproject/onionoo/ResourceServlet.java | 24 ++++++++--------------
1 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index 5854cb7..8c0b625 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -606,15 +606,7 @@ public class ResourceServlet extends HttpServlet {
private void filterBySearchTerms(Map<String, String> filteredRelays,
Map<String, String> filteredBridges, String[] searchTerms) {
for (String searchTerm : searchTerms) {
- if (searchTerm.startsWith("$") && searchTerm.length() == 41) {
- this.filterByFingerprint(filteredRelays, filteredBridges,
- searchTerm.substring(1).toUpperCase());
- } else if (!searchTerm.startsWith("$") && searchTerm.length() == 40) {
- this.filterByFingerprint(filteredRelays, filteredBridges,
- searchTerm.toUpperCase());
- } else {
- filterBySearchTerm(filteredRelays, filteredBridges, searchTerm);
- }
+ filterBySearchTerm(filteredRelays, filteredBridges, searchTerm);
}
}
@@ -622,6 +614,7 @@ public class ResourceServlet extends HttpServlet {
Map<String, String> filteredBridges, String searchTerm) {
Set<String> removeRelays = new HashSet<String>();
for (Map.Entry<String, String> e : filteredRelays.entrySet()) {
+ String fingerprint = e.getKey();
String line = e.getValue();
boolean lineMatches = false;
String nickname = "unnamed";
@@ -631,15 +624,15 @@ public class ResourceServlet extends HttpServlet {
}
if (searchTerm.startsWith("$")) {
/* Search is for $-prefixed fingerprint. */
- if (line.contains("\"f\":\""
- + searchTerm.substring(1).toUpperCase())) {
+ if (fingerprint.startsWith(
+ searchTerm.substring(1).toUpperCase())) {
/* $-prefixed fingerprint matches. */
lineMatches = true;
}
} else if (nickname.contains(searchTerm.toLowerCase())) {
/* Nickname matches. */
lineMatches = true;
- } else if (line.contains("\"f\":\"" + searchTerm.toUpperCase())) {
+ } else if (fingerprint.startsWith(searchTerm.toUpperCase())) {
/* Non-$-prefixed fingerprint matches. */
lineMatches = true;
} else if (line.substring(line.indexOf("\"a\":[")).contains("\""
@@ -656,6 +649,7 @@ public class ResourceServlet extends HttpServlet {
}
Set<String> removeBridges = new HashSet<String>();
for (Map.Entry<String, String> e : filteredBridges.entrySet()) {
+ String hashedFingerprint = e.getKey();
String line = e.getValue();
boolean lineMatches = false;
String nickname = "unnamed";
@@ -665,15 +659,15 @@ public class ResourceServlet extends HttpServlet {
}
if (searchTerm.startsWith("$")) {
/* Search is for $-prefixed hashed fingerprint. */
- if (line.contains("\"h\":\""
- + searchTerm.substring(1).toUpperCase())) {
+ if (hashedFingerprint.startsWith(
+ searchTerm.substring(1).toUpperCase())) {
/* $-prefixed hashed fingerprint matches. */
lineMatches = true;
}
} else if (nickname.contains(searchTerm.toLowerCase())) {
/* Nickname matches. */
lineMatches = true;
- } else if (line.contains("\"h\":\"" + searchTerm.toUpperCase())) {
+ } else if (hashedFingerprint.startsWith(searchTerm.toUpperCase())) {
/* Non-$-prefixed hashed fingerprint matches. */
lineMatches = true;
}
More information about the tor-commits
mailing list