Search in sources :

Example 46 with DnsMessage

use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.

the class DNSMessageTest method testRootDnskeyLookup.

@Test
public void testRootDnskeyLookup() throws Exception {
    DNSMessage m = getMessageFromResource("root-dnskey");
    assertFalse(m.authoritativeAnswer);
    assertTrue(m.recursionDesired);
    assertTrue(m.recursionAvailable);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(3, answers.size());
    for (int i = 0; i < answers.size(); i++) {
        Record<? extends Data> answer = answers.get(i);
        assertCsEquals(".", answer.name);
        assertEquals(19593, answer.getTtl());
        assertEquals(TYPE.DNSKEY, answer.type);
        assertEquals(TYPE.DNSKEY, answer.getPayload().getType());
        DNSKEY dnskey = (DNSKEY) answer.getPayload();
        assertEquals(3, dnskey.protocol);
        assertEquals(SignatureAlgorithm.RSASHA256, dnskey.algorithm);
        assertTrue((dnskey.flags & DNSKEY.FLAG_ZONE) > 0);
        assertEquals(dnskey.getKeyTag(), dnskey.getKeyTag());
        switch(i) {
            case 0:
                assertTrue((dnskey.flags & DNSKEY.FLAG_SECURE_ENTRY_POINT) > 0);
                assertEquals(260, dnskey.getKeyLength());
                assertEquals(19036, dnskey.getKeyTag());
                break;
            case 1:
                assertEquals(DNSKEY.FLAG_ZONE, dnskey.flags);
                assertEquals(132, dnskey.getKeyLength());
                assertEquals(48613, dnskey.getKeyTag());
                break;
            case 2:
                assertEquals(DNSKEY.FLAG_ZONE, dnskey.flags);
                assertEquals(132, dnskey.getKeyLength());
                assertEquals(1518, dnskey.getKeyTag());
                break;
        }
    }
    List<Record<? extends Data>> arr = m.additionalSection;
    assertEquals(1, arr.size());
    Record<? extends Data> opt = arr.get(0);
    EDNS edns = EDNS.fromRecord(opt);
    assertEquals(512, edns.udpPayloadSize);
    assertEquals(0, edns.version);
}
Also used : EDNS(org.minidns.edns.EDNS) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSKEY(org.minidns.record.DNSKEY) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 47 with DnsMessage

use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.

the class DNSMessageTest method testMessageSelfQuestionReconstruction.

@Test
public void testMessageSelfQuestionReconstruction() throws Exception {
    DNSMessage.Builder dmb = DNSMessage.builder();
    dmb.setQuestion(new Question("www.example.com", TYPE.A));
    dmb.setRecursionDesired(true);
    dmb.setId(42);
    dmb.setQrFlag(true);
    DNSMessage message = new DNSMessage(dmb.build().toArray());
    assertEquals(1, message.questions.size());
    assertEquals(0, message.answerSection.size());
    assertEquals(0, message.additionalSection.size());
    assertEquals(0, message.authoritySection.size());
    assertTrue(message.recursionDesired);
    assertTrue(message.qr);
    assertEquals(42, message.id);
    assertCsEquals("www.example.com", message.questions.get(0).name);
    assertEquals(TYPE.A, message.questions.get(0).type);
}
Also used : Question(org.minidns.dnsmessage.Question) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 48 with DnsMessage

use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.

the class DNSMessageTest method testMXLookup.

@Test
public void testMXLookup() throws Exception {
    DNSMessage m = getMessageFromResource("gmail-mx");
    assertFalse(m.authoritativeAnswer);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(5, answers.size());
    Map<Integer, DNSName> mxes = new TreeMap<>();
    for (Record<? extends Data> r : answers) {
        assertCsEquals("gmail.com", r.name);
        Data d = r.getPayload();
        assertTrue(d instanceof MX);
        assertEquals(TYPE.MX, d.getType());
        mxes.put(((MX) d).priority, ((MX) d).target);
    }
    assertCsEquals("gmail-smtp-in.l.google.com", mxes.get(5));
    assertCsEquals("alt1.gmail-smtp-in.l.google.com", mxes.get(10));
    assertCsEquals("alt2.gmail-smtp-in.l.google.com", mxes.get(20));
    assertCsEquals("alt3.gmail-smtp-in.l.google.com", mxes.get(30));
    assertCsEquals("alt4.gmail-smtp-in.l.google.com", mxes.get(40));
}
Also used : Record(org.minidns.record.Record) Data(org.minidns.record.Data) MX(org.minidns.record.MX) DNSName(org.minidns.dnsname.DNSName) TreeMap(java.util.TreeMap) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 49 with DnsMessage

use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.

the class DNSMessageTest method testExampleNsecLookup.

@Test
public void testExampleNsecLookup() throws Exception {
    DNSMessage m = getMessageFromResource("example-nsec");
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(1, answers.size());
    assertEquals(TYPE.NSEC, answers.get(0).type);
    assertEquals(TYPE.NSEC, answers.get(0).payloadData.getType());
    NSEC nsec = (NSEC) answers.get(0).getPayload();
    assertCsEquals("www.example.com", nsec.next);
    ArrayList<TYPE> types = new ArrayList<>(Arrays.asList(TYPE.A, TYPE.NS, TYPE.SOA, TYPE.TXT, TYPE.AAAA, TYPE.RRSIG, TYPE.NSEC, TYPE.DNSKEY));
    for (TYPE type : nsec.types) {
        assertTrue(types.remove(type));
    }
    assertTrue(types.isEmpty());
}
Also used : NSEC(org.minidns.record.NSEC) ArrayList(java.util.ArrayList) Record(org.minidns.record.Record) Data(org.minidns.record.Data) TYPE(org.minidns.record.Record.TYPE) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 50 with DnsMessage

use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.

the class NSIDTest method testNsidLRoot.

@IntegrationTest
public static NSID testNsidLRoot() {
    DNSClient client = new DNSClient(null) {

        @Override
        protected Builder newQuestion(Builder message) {
            message.getEdnsBuilder().addEdnsOption(NSID.REQUEST);
            return super.newQuestion(message);
        }
    };
    DNSMessage response = null;
    Question q = new Question("de", TYPE.NS);
    for (InetAddress lRoot : IterativeDNSClient.getRootServer('l')) {
        try {
            response = client.query(q, lRoot);
        } catch (IOException e) {
            continue;
        }
        break;
    }
    NSID nsid = response.getEdns().getEdnsOption(OptionCode.NSID);
    assertNotNull(nsid);
    return nsid;
}
Also used : IterativeDNSClient(org.minidns.iterative.IterativeDNSClient) DNSClient(org.minidns.DNSClient) NSID(org.minidns.edns.NSID) Builder(org.minidns.dnsmessage.DNSMessage.Builder) Question(org.minidns.dnsmessage.Question) IOException(java.io.IOException) InetAddress(java.net.InetAddress) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Aggregations

DNSMessage (org.minidns.dnsmessage.DNSMessage)67 Test (org.junit.Test)35 Data (org.minidns.record.Data)16 Record (org.minidns.record.Record)16 IOException (java.io.IOException)15 Question (org.minidns.dnsmessage.Question)14 InetAddress (java.net.InetAddress)6 LRUCache (org.minidns.cache.LRUCache)6 ArrayList (java.util.ArrayList)5 DNSClient (org.minidns.DNSClient)5 LinkedList (java.util.LinkedList)4 EDNS (org.minidns.edns.EDNS)4 RRSIG (org.minidns.record.RRSIG)4 Date (java.util.Date)3 Level (java.util.logging.Level)3 InternalMiniDnsFuture (org.minidns.MiniDnsFuture.InternalMiniDnsFuture)3 DNSName (org.minidns.dnsname.DNSName)3 DNSKEY (org.minidns.record.DNSKEY)3 DatagramSocket (java.net.DatagramSocket)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2