From 9b3449f033d5bf86a055bba7c9bcb1ca97c7d8b6 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 8 Jan 2022 19:43:26 +0100 Subject: [PATCH] TLS local --- FAQ.md | 3 +-- .../java/eu/faircode/email/ConnectionHelper.java | 4 +++- .../java/eu/faircode/email/MessageHelper.java | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/FAQ.md b/FAQ.md index b96acb6306..18d02b2443 100644 --- a/FAQ.md +++ b/FAQ.md @@ -4483,8 +4483,7 @@ A message will be consired safely transported if *every* [Received](https://data * has a *with* with the value 'HTTP', 'HTTPS', or 'HTTPREST' * has a *with* with the value '[xMTPSx](https://datatracker.ietf.org/doc/html/rfc3848)' ('xMTPAx' is considered insecure) -A local address is a local host address, a site local address -or a non-numeric address which isn't [a domain name](https://developer.android.com/reference/androidx/core/util/PatternsCompat#DOMAIN_NAME). +A local address is a local host address, a site local address or a link local address. Example: diff --git a/app/src/main/java/eu/faircode/email/ConnectionHelper.java b/app/src/main/java/eu/faircode/email/ConnectionHelper.java index 462b111a60..2c15b1a7fb 100644 --- a/app/src/main/java/eu/faircode/email/ConnectionHelper.java +++ b/app/src/main/java/eu/faircode/email/ConnectionHelper.java @@ -509,7 +509,9 @@ public class ConnectionHelper { static boolean isLocalAddress(String host) { try { InetAddress addr = ConnectionHelper.from6to4(InetAddress.getByName(host)); - return (addr.isSiteLocalAddress() || addr.isLinkLocalAddress()); + return (addr.isLoopbackAddress() || + addr.isSiteLocalAddress() || + addr.isLinkLocalAddress()); } catch (UnknownHostException ex) { Log.e(ex); return false; diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 42d06240d1..416432efb0 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -2202,18 +2202,26 @@ public class MessageHelper { private static boolean isLocal(String value) { if (value.contains("localhost") || - value.contains("[127.0.0.1]") || + value.contains("127.0.0.1") || value.contains("[::1]")) return true; + + int s = value.indexOf('['); + int e = value.indexOf(']', s + 1); + if (s >= 0 && e > 0) { + String ip = value.substring(s + 1, e); + if (ConnectionHelper.isNumericAddress(ip) && + ConnectionHelper.isLocalAddress(ip)) + return true; + } + int f = value.indexOf(' '); String host = (f < 0 ? value : value.substring(0, f)); if (ConnectionHelper.isNumericAddress(host)) { if (ConnectionHelper.isLocalAddress(host)) return true; - } else { - if (!PatternsCompat.DOMAIN_NAME.matcher(host).matches()) - return true; } + return false; }