DNS error handling

pull/214/head
M66B 2 years ago
parent 5c4d5b6670
commit 9311953dd3

@ -101,7 +101,7 @@ public class DnsHelper {
String domain = UriHelper.getEmailDomain(email);
if (domain == null)
continue;
DnsRecord[] records = _lookup(context, domain, "mx", CHECK_TIMEOUT, false);
DnsRecord[] records = _lookup(context, domain, "mx", CHECK_TIMEOUT);
if (records.length == 0)
throw new UnknownHostException(domain);
}
@ -109,11 +109,25 @@ public class DnsHelper {
@NonNull
static DnsRecord[] lookup(Context context, String name, String type) {
return _lookup(context, name, type, LOOKUP_TIMEOUT, false);
return _lookup(context, name, type, LOOKUP_TIMEOUT);
}
@NonNull
private static DnsRecord[] _lookup(Context context, String name, String type, int timeout, boolean dnssec) {
private static DnsRecord[] _lookup(Context context, String name, String type, int timeout) {
try {
return _lookup(context, name, type, timeout, false);
} catch (Throwable ex) {
if (ex instanceof MultipleIoException ||
ex instanceof ResolutionUnsuccessfulException)
Log.i(ex);
else
Log.e(ex);
return new DnsRecord[0];
}
}
@NonNull
private static DnsRecord[] _lookup(Context context, String name, String type, int timeout, boolean dnssec) throws IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean dns_custom = prefs.getBoolean("dns_custom", false);
@ -148,7 +162,6 @@ public class DnsHelper {
throw new IllegalArgumentException(type);
}
try {
ResolverApi resolver = DnssecResolverApi.INSTANCE;
AbstractDnsClient client = resolver.getClient();
@ -273,16 +286,6 @@ public class DnsHelper {
});
return result.toArray(new DnsRecord[0]);
} catch (Throwable ex) {
if (ex instanceof MultipleIoException ||
ex instanceof ResolutionUnsuccessfulException ||
ex instanceof DnssecValidationFailedException ||
ex instanceof DnssecResultNotAuthenticException)
Log.i(ex);
else
Log.e(ex);
return new DnsRecord[0];
}
}
static InetAddress getByName(Context context, String host) throws UnknownHostException {
@ -316,7 +319,7 @@ public class DnsHelper {
List<InetAddress> result = new ArrayList<>();
boolean[] has46 = ConnectionHelper.has46(context);
try {
if (has46[0])
for (DnsRecord a : _lookup(context, host, "a", LOOKUP_TIMEOUT, dnssec))
result.add(a.address);
@ -329,6 +332,9 @@ public class DnsHelper {
throw new UnknownHostException(host);
return result.toArray(new InetAddress[0]);
} catch (IOException ex) {
throw new UnknownHostException(ex.getMessage());
}
}
static void verifyDane(X509Certificate[] chain, String server, int port) throws CertificateException {

Loading…
Cancel
Save