diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java b/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java index 16deec8cd8..98bc28fdb8 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java @@ -461,7 +461,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase { ibInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Uri uri = Uri.parse("https://en.wikipedia.org/wiki/WHOIS"); + Uri uri = Uri.parse(Whois.WHOIS_INFO); Helper.view(v.getContext(), uri, true); } }); diff --git a/app/src/main/java/eu/faircode/email/Whois.java b/app/src/main/java/eu/faircode/email/Whois.java index 4e69be3ded..ff4f4fa302 100644 --- a/app/src/main/java/eu/faircode/email/Whois.java +++ b/app/src/main/java/eu/faircode/email/Whois.java @@ -23,11 +23,15 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; public class Whois { - // https://datatracker.ietf.org/doc/html/rfc812 + // https://datatracker.ietf.org/doc/html/rfc3912 + static final String WHOIS_INFO = "https://en.wikipedia.org/wiki/WHOIS"; private static final int WHOIS_PORT = 43; private static final int WHOIS_TIMEOUT = 15 * 1000; // milliseconds + private static final String WHOIS_IANA = "whois.iana.org"; + private static final String WHOIS_PREFIX = "whois:"; static String get(String domain) throws IOException { return get(domain, getServer(domain), WHOIS_PORT); @@ -41,19 +45,21 @@ public class Whois { Socket socket = new Socket(); socket.connect(new InetSocketAddress(host, port), WHOIS_TIMEOUT); try { - socket.getOutputStream().write((domain + "\r\n").getBytes()); - return host + ":" + port + "\n" + Helper.readStream(socket.getInputStream()); + byte[] request = (domain + "\r\n").getBytes(StandardCharsets.ISO_8859_1); + socket.getOutputStream().write(request); + String response = Helper.readStream(socket.getInputStream(), StandardCharsets.ISO_8859_1); + return host + ":" + port + "\n" + response; } finally { socket.close(); } } private static String getServer(String domain) throws IOException { - String who = get(domain, "whois.iana.org"); - for (String w : who.split("\\r?\\n")) - if (w.startsWith("whois:")) - return w.substring(6).trim(); - Log.w(who); + String iana = get(domain, WHOIS_IANA); + for (String line : iana.split("\\r?\\n")) + if (line.startsWith(WHOIS_PREFIX)) + return line.substring(WHOIS_PREFIX.length()).trim(); + Log.w(iana); throw new UnknownHostException("whois server unknown " + domain); } }