Skip to content

Commit

Permalink
Naming: lookup fixes
Browse files Browse the repository at this point in the history
- Don't lookup b33 in BFNS
- Fail immediately on bad b32
- Fix stripping .alt in ConvertToHash
- Strip URLs to hostname in ConvertToHash, for convenience
  • Loading branch information
zzzi2p committed Aug 17, 2024
1 parent 12ff0e7 commit 8ca34cd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ private Destination lookup2(String hostname, Properties lookupOptions, Propertie
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p"))
if (hostname.length() >= BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p"))
return null;
}

Expand Down Expand Up @@ -848,7 +848,7 @@ private Destination lookup2(String hostname, Properties lookupOptions, Propertie
*/
private List<Destination> lookupAll2(String hostname, Properties lookupOptions, List<Properties> storedOptions) {
// only use cache for b32
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
if (hostname.length() >= BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
Destination d = super.lookup(hostname, null, null);
if (d != null) {
if (storedOptions != null)
Expand Down
13 changes: 12 additions & 1 deletion core/java/src/net/i2p/util/ConvertToHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ public static Hash getHash(String peer) {
if (peer == null)
return null;
String peerLC = peer.toLowerCase(Locale.US);
if (peerLC.startsWith("http://")) {
peer = peer.substring(7);
peerLC = peerLC.substring(7);
} else if (peerLC.startsWith("https://")) {
peer = peer.substring(8);
peerLC = peerLC.substring(8);
}
if (peer.endsWith("/")) {
peer = peer.substring(0, peer.length() - 1);
peerLC = peerLC.substring(0, peerLC.length() - 1);
}
if (peerLC.endsWith(".i2p.alt")) {
peer = peer.substring(0, peer.length() - 4);
peerLC = peerLC.substring(0, peer.length() - 4);
peerLC = peerLC.substring(0, peerLC.length() - 4);
}
// b64 hash
if (peer.length() == 44 && !peerLC.endsWith(".i2p")) {
Expand Down
3 changes: 3 additions & 0 deletions router/java/src/net/i2p/router/client/LookupDestJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public LookupDestJob(RouterContext context, ClientConnectionRunner runner,
// h and name both null, runJob will fail immediately
}
}
} else {
// base32 decode fail
name = null;
}
}
}
Expand Down

0 comments on commit 8ca34cd

Please sign in to comment.