diff options
author | genofire <geno+dev@fireorbit.de> | 2020-02-10 02:14:15 +0100 |
---|---|---|
committer | genofire <geno+dev@fireorbit.de> | 2020-02-10 02:38:37 +0100 |
commit | ea063e8a7606813c993ebb64c5bf4619d923dea6 (patch) | |
tree | a10c2f575dfa79cdad96599ff56d79779711bc8c /src/main | |
parent | 470cc533b2031651fda18adac5474fba2db1b790 (diff) |
[BUGFIX] Resolver: fallback for invalid SRV CNAME entries
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/Resolver.java | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java index ff2dce039..250a6f097 100644 --- a/src/main/java/de/pixart/messenger/utils/Resolver.java +++ b/src/main/java/de/pixart/messenger/utils/Resolver.java @@ -177,6 +177,10 @@ public class Resolver { ResolverResult<SRV> result = resolveWithFallback(dnsName, SRV.class); final List<Result> results = new ArrayList<>(); final List<Thread> threads = new ArrayList<>(); + + final List<Result> fallbackResults = new ArrayList<>(); + final List<Thread> fallbackThreads = new ArrayList<>(); + for (SRV record : result.getAnswersOrEmptySet()) { if (record.name.length() == 0) { continue; @@ -193,6 +197,22 @@ public class Resolver { results.addAll(ipv4s); } })); + fallbackThreads.add(new Thread(() -> { + try { + for (CNAME cname : resolveWithFallback(record.name, CNAME.class, result.isAuthenticData()).getAnswersOrEmptySet()) { + final List<Result> ipv6s = resolveIp(record, cname.name, AAAA.class, result.isAuthenticData(), directTls); + synchronized (fallbackResults) { + fallbackResults.addAll(ipv6s); + } + final List<Result> ipv4s = resolveIp(record, cname.name, A.class, result.isAuthenticData(), directTls); + synchronized (results) { + fallbackResults.addAll(ipv4s); + } + } + } catch (Throwable throwable) { + Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving srv cname-fallback records", throwable); + } + })); } for (Thread thread : threads) { thread.start(); @@ -205,13 +225,30 @@ public class Resolver { return Collections.emptyList(); } } - return results; + if (results.size() > 0) { + return results; + } + for (Thread thread : fallbackThreads) { + thread.start(); + } + for (Thread thread : fallbackThreads) { + try { + thread.join(); + } catch (InterruptedException e) { + return Collections.emptyList(); + } + } + return fallbackResults; } private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) { + return resolveIp(srv, srv.name, type, authenticated, directTls); + } + + private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, DNSName hostname, Class<D> type, boolean authenticated, boolean directTls) { List<Result> list = new ArrayList<>(); try { - ResolverResult<D> results = resolveWithFallback(srv.name, type, authenticated); + ResolverResult<D> results = resolveWithFallback(hostname, type, authenticated); for (D record : results.getAnswersOrEmptySet()) { Result resolverResult = Result.fromRecord(srv, directTls); resolverResult.authenticated = results.isAuthenticData() && authenticated; |