diff --git a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
index 91301d9f4..6c3526a3f 100644
--- a/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
+++ b/apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
@@ -28,6 +28,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
@@ -259,11 +261,44 @@ public class AddressbookBean extends BaseBean
message = _t("Host name {0} is already in address book with a different destination. Click \"Replace\" to overwrite.", displayHost);
} else {
boolean valid = true;
+ boolean wasB32 = false;
try {
- // just to check validity
- new Destination(destination);
+ if (destination.length() >= 516) {
+ // just to check validity
+ new Destination(destination);
+ } else if (destination.contains(".b32.i2p")) {
+ wasB32 = true;
+ Destination dest;
+ if (destination.startsWith("http://") ||
+ destination.startsWith("https://")) {
+ // do them a favor, pull b32 out of pasted URL
+ try {
+ URI uri = new URI(destination);
+ String b32 = uri.getHost();
+ if (b32 == null || !b32.endsWith(".b32.i2p") || b32.length() < 60)
+ throw new DataFormatException("");
+ dest = _context.namingService().lookup(b32);
+ if (dest == null)
+ throw new DataFormatException(_t("Unable to resolve Base 32 address"));
+ } catch(URISyntaxException use) {
+ throw new DataFormatException("");
+ }
+ } else if (destination.endsWith(".b32.i2p") && destination.length() >= 60) {
+ dest = _context.namingService().lookup(destination);
+ if (dest == null)
+ throw new DataFormatException(_t("Unable to resolve Base 32 address"));
+ } else {
+ throw new DataFormatException("");
+ }
+ destination = dest.toBase64();
+ } else {
+ throw new DataFormatException("");
+ }
} catch (DataFormatException dfe) {
valid = false;
+ String msg = dfe.getMessage();
+ if (msg != null)
+ message = msg;
}
if (valid) {
addressbook.put( host, destination );
@@ -278,7 +313,12 @@ public class AddressbookBean extends BaseBean
hostname = null;
destination = null;
} else {
- message = _t("Invalid Base 64 destination.");
+ if (message.length() <= 0) {
+ if (wasB32)
+ message = _t("Invalid Base 32 host name.");
+ else
+ message = _t("Invalid Base 64 destination.");
+ }
}
}
} catch (IllegalArgumentException iae) {
diff --git a/apps/susidns/src/java/src/i2p/susi/dns/NamingServiceBean.java b/apps/susidns/src/java/src/i2p/susi/dns/NamingServiceBean.java
index 330b54795..51e05ed3b 100644
--- a/apps/susidns/src/java/src/i2p/susi/dns/NamingServiceBean.java
+++ b/apps/susidns/src/java/src/i2p/susi/dns/NamingServiceBean.java
@@ -27,6 +27,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
@@ -255,8 +257,37 @@ public class NamingServiceBean extends AddressbookBean
} else if (oldDest != null && action.equals(_t("Add"))) {
message = _t("Host name {0} is already in address book with a different destination. Click \"Replace\" to overwrite.", displayHost);
} else {
+ boolean wasB32 = false;
try {
- Destination dest = new Destination(destination);
+ Destination dest;
+ if (destination.length() >= 516) {
+ dest = new Destination(destination);
+ } else if (destination.contains(".b32.i2p")) {
+ wasB32 = true;
+ if (destination.startsWith("http://") ||
+ destination.startsWith("https://")) {
+ // do them a favor, pull b32 out of pasted URL
+ try {
+ URI uri = new URI(destination);
+ String b32 = uri.getHost();
+ if (b32 == null || !b32.endsWith(".b32.i2p") || b32.length() < 60)
+ throw new DataFormatException("");
+ dest = _context.namingService().lookup(b32);
+ if (dest == null)
+ throw new DataFormatException(_t("Unable to resolve Base 32 address"));
+ } catch(URISyntaxException use) {
+ throw new DataFormatException("");
+ }
+ } else if (destination.endsWith(".b32.i2p") && destination.length() >= 60) {
+ dest = _context.namingService().lookup(destination);
+ if (dest == null)
+ throw new DataFormatException(_t("Unable to resolve Base 32 address"));
+ } else {
+ throw new DataFormatException("");
+ }
+ } else {
+ throw new DataFormatException("");
+ }
if (oldDest != null) {
nsOptions.putAll(outProperties);
String now = Long.toString(_context.clock().now());
@@ -294,7 +325,13 @@ public class NamingServiceBean extends AddressbookBean
message = _t("Failed to add Destination for {0} to naming service {1}", displayHost, getNamingService().getName()) + "
";
}
} catch (DataFormatException dfe) {
- message = _t("Invalid Base 64 destination.");
+ String msg = dfe.getMessage();
+ if (msg != null && msg.length() > 0)
+ message = msg;
+ else if (wasB32)
+ message = _t("Invalid Base 32 host name.");
+ else
+ message = _t("Invalid Base 64 destination.");
}
}
} catch (IllegalArgumentException iae) {
diff --git a/apps/susidns/src/jsp/addressbook.jsp b/apps/susidns/src/jsp/addressbook.jsp
index bc35f641c..716461903 100644
--- a/apps/susidns/src/jsp/addressbook.jsp
+++ b/apps/susidns/src/jsp/addressbook.jsp
@@ -245,7 +245,7 @@ ${book.loadBookMessages}