use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.
the class DNSSECClient method queryDnssec.
public DNSSECMessage queryDnssec(CharSequence name, TYPE type) throws IOException {
Question q = new Question(name, type, CLASS.IN);
DNSMessage dnsMessage = super.query(q);
DNSSECMessage dnssecMessage = performVerification(q, dnsMessage);
return dnssecMessage;
}
use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.
the class DNSSECClient method verifyNsec.
private Set<UnverifiedReason> verifyNsec(DNSMessage dnsMessage) throws IOException {
Set<UnverifiedReason> result = new HashSet<>();
Question q = dnsMessage.questions.get(0);
boolean validNsec = false;
boolean nsecPresent = false;
DNSName zone = null;
List<Record<? extends Data>> nameserverRecords = dnsMessage.authoritySection;
for (Record<? extends Data> nameserverRecord : nameserverRecords) {
if (nameserverRecord.type == TYPE.SOA)
zone = nameserverRecord.name;
}
if (zone == null)
throw new DNSSECValidationFailedException(q, "NSECs must always match to a SOA");
for (Record<? extends Data> record : nameserverRecords) {
UnverifiedReason reason;
switch(record.type) {
case NSEC:
nsecPresent = true;
reason = verifier.verifyNsec(record, q);
break;
case NSEC3:
nsecPresent = true;
reason = verifier.verifyNsec3(zone, record, q);
break;
default:
continue;
}
if (reason != null) {
result.add(reason);
} else {
validNsec = true;
}
}
if (nsecPresent && !validNsec) {
throw new DNSSECValidationFailedException(q, "Invalid NSEC!");
}
List<Record<? extends Data>> toBeVerified = dnsMessage.copyAuthority();
VerifySignaturesResult verifiedSignatures = verifySignatures(q, nameserverRecords, toBeVerified);
if (validNsec && verifiedSignatures.reasons.isEmpty()) {
result.clear();
} else {
result.addAll(verifiedSignatures.reasons);
}
if (!toBeVerified.isEmpty() && toBeVerified.size() != nameserverRecords.size()) {
throw new DNSSECValidationFailedException(q, "Only some nameserver records are signed!");
}
return result;
}
use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.
the class ResolverApi method resolve.
public final <D extends Data> ResolverResult<D> resolve(DNSName name, Class<D> type) throws IOException {
TYPE t = TYPE.getType(type);
Question q = new Question(name, t);
return resolve(q);
}
use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.
the class ResolutionState method recurse.
void recurse(InetAddress address, DNSMessage query) throws LoopDetected, MaxIterativeStepsReached {
Question question = query.getQuestion();
if (!map.containsKey(address)) {
map.put(address, new HashSet<Question>());
} else if (map.get(address).contains(question)) {
throw new IterativeClientException.LoopDetected();
}
if (++steps > recursiveDnsClient.maxSteps) {
throw new IterativeClientException.MaxIterativeStepsReached();
}
boolean isNew = map.get(address).add(question);
assert (isNew);
}
use of org.minidns.dnsmessage.Question in project minidns by MiniDNS.
the class DNSWorld method applyStubRecords.
@SuppressWarnings("unchecked")
public static DNSWorld applyStubRecords(AbstractDNSClient client, Record<Data>... records) {
DNSWorld world = new DNSWorld();
client.setDataSource(world);
for (Record<? extends Data> record : records) {
DNSMessage.Builder request = client.buildMessage(new Question(record.name, record.type, record.clazz, record.unicastQuery));
request.setRecursionDesired(true);
DNSMessage.Builder response = DNSMessage.builder();
response.addAnswer(record);
response.setRecursionAvailable(true);
world.addPreparedResponse(new AnswerResponse(request.build(), response.build()));
}
return world;
}
Aggregations