use ResolverApi.reliable(..)

This commit is contained in:
Daniel Gultsch 2017-06-25 19:30:03 +02:00
parent 2c5250a82c
commit 4faf0f2ec9

View File

@ -12,15 +12,10 @@ import java.util.List;
import de.measite.minidns.DNSClient; import de.measite.minidns.DNSClient;
import de.measite.minidns.DNSName; import de.measite.minidns.DNSName;
import de.measite.minidns.Question;
import de.measite.minidns.Record;
import de.measite.minidns.dnssec.DNSSECValidationFailedException;
import de.measite.minidns.hla.DnssecResolverApi; import de.measite.minidns.hla.DnssecResolverApi;
import de.measite.minidns.hla.ResolverApi;
import de.measite.minidns.hla.ResolverResult; import de.measite.minidns.hla.ResolverResult;
import de.measite.minidns.record.A; import de.measite.minidns.record.A;
import de.measite.minidns.record.AAAA; import de.measite.minidns.record.AAAA;
import de.measite.minidns.record.Data;
import de.measite.minidns.record.InternetAddressRR; import de.measite.minidns.record.InternetAddressRR;
import de.measite.minidns.record.SRV; import de.measite.minidns.record.SRV;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -57,25 +52,16 @@ public class Resolver {
} }
private static List<Result> resolveSrv(String domain, final boolean directTls) throws IOException { private static List<Result> resolveSrv(String domain, final boolean directTls) throws IOException {
Question question = new Question((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE)+"._tcp."+domain,Record.TYPE.SRV); DNSName dnsName = DNSName.from((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE)+"._tcp."+domain);
ResolverResult<Data> result; ResolverResult<SRV> result = DnssecResolverApi.INSTANCE.resolveDnssecReliable(dnsName,SRV.class);
try {
result = DnssecResolverApi.INSTANCE.resolve(question);
} catch (DNSSECValidationFailedException e) {
Log.d(Config.LOGTAG,Resolver.class.getSimpleName()+": error resolving SRV record with DNSSEC. Trying DNS instead "+e.getMessage());
result = ResolverApi.INSTANCE.resolve(question);
}
List<Result> results = new ArrayList<>(); List<Result> results = new ArrayList<>();
for(Data record : result.getAnswersOrEmptySet()) { for(SRV record : result.getAnswersOrEmptySet()) {
if (record instanceof SRV) { boolean added = results.addAll(resolveIp(record,A.class,result.isAuthenticData(),directTls));
SRV srvRecord = (SRV) record; added |= results.addAll(resolveIp(record,AAAA.class,result.isAuthenticData(),directTls));
boolean added = results.addAll(resolveIp(srvRecord,A.class,result.isAuthenticData(),directTls)); if (!added) {
added |= results.addAll(resolveIp(srvRecord,AAAA.class,result.isAuthenticData(),directTls)); Result resolverResult = Result.fromRecord(record, directTls);
if (!added) { resolverResult.authenticated = resolverResult.isAuthenticated();
Result resolverResult = Result.fromRecord(srvRecord, directTls); results.add(resolverResult);
resolverResult.authenticated = resolverResult.isAuthenticated();
results.add(resolverResult);
}
} }
} }
return results; return results;
@ -84,13 +70,7 @@ public class Resolver {
private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) { private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) {
List<Result> list = new ArrayList<>(); List<Result> list = new ArrayList<>();
try { try {
ResolverResult<D> results; ResolverResult<D> results = DnssecResolverApi.INSTANCE.resolveDnssecReliable(srv.name, type);
try {
results = DnssecResolverApi.INSTANCE.resolve(srv.name, type);
} catch (DNSSECValidationFailedException e) {
Log.d(Config.LOGTAG,Resolver.class.getSimpleName()+": error resolving "+type.getSimpleName()+" with DNSSEC. Trying DNS instead "+e.getMessage());
results = ResolverApi.INSTANCE.resolve(srv.name,type);
}
for (D record : results.getAnswersOrEmptySet()) { for (D record : results.getAnswersOrEmptySet()) {
Result resolverResult = Result.fromRecord(srv, directTls); Result resolverResult = Result.fromRecord(srv, directTls);
resolverResult.authenticated = results.isAuthenticData() && authenticated; resolverResult.authenticated = results.isAuthenticData() && authenticated;
@ -134,7 +114,7 @@ public class Resolver {
@Override @Override
public String toString() { public String toString() {
return "Result{" + return "Result{" +
"ip='" + ip + '\'' + "ip='" + (ip==null?null:ip.getHostAddress()) + '\'' +
", hostame='" + hostname.toString() + '\'' + ", hostame='" + hostname.toString() + '\'' +
", port=" + port + ", port=" + port +
", directTls=" + directTls + ", directTls=" + directTls +