Search in sources :

Example 16 with Question

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;
}
Also used : Question(org.minidns.dnsmessage.Question) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 17 with Question

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;
}
Also used : Question(org.minidns.dnsmessage.Question) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSName(org.minidns.dnsname.DNSName) HashSet(java.util.HashSet)

Example 18 with Question

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);
}
Also used : Question(org.minidns.dnsmessage.Question) TYPE(org.minidns.record.Record.TYPE)

Example 19 with Question

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);
}
Also used : LoopDetected(org.minidns.iterative.IterativeClientException.LoopDetected) Question(org.minidns.dnsmessage.Question) MaxIterativeStepsReached(org.minidns.iterative.IterativeClientException.MaxIterativeStepsReached)

Example 20 with Question

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;
}
Also used : Question(org.minidns.dnsmessage.Question) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Aggregations

Question (org.minidns.dnsmessage.Question)25 DNSMessage (org.minidns.dnsmessage.DNSMessage)15 Test (org.junit.Test)6 IOException (java.io.IOException)4 InetAddress (java.net.InetAddress)4 DNSName (org.minidns.dnsname.DNSName)3 Data (org.minidns.record.Data)3 Record (org.minidns.record.Record)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Level (java.util.logging.Level)2 DnsMessage (org.minidns.dnsmessage.DnsMessage)2 TYPE (org.minidns.record.Record.TYPE)2 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)1 DnsOverXmppManager (org.jivesoftware.smackx.dox.DnsOverXmppManager)1 Test (org.junit.jupiter.api.Test)1 Jid (org.jxmpp.jid.Jid)1 DNSClient (org.minidns.DNSClient)1 DnsClient (org.minidns.DnsClient)1 Builder (org.minidns.dnsmessage.DNSMessage.Builder)1