Search in sources :

Example 21 with DnsMessage

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

the class DNSSECClientTest method testSignatureInFuture.

@SuppressWarnings("unchecked")
@Test
public void testSignatureInFuture() throws IOException {
    Date signatureExpiration = new Date(System.currentTimeMillis() + 28L * 24L * 60L * 60L * 1000L);
    Date signatureInception = new Date(System.currentTimeMillis() + 14 * 24 * 60 * 60 * 1000);
    RRSIG outOfDateSig = rrsig(Record.TYPE.A, algorithm, 2, 3600, signatureExpiration, signatureInception, comZSK.getKeyTag(), "com", new byte[0]);
    applyZones(client, signedRootZone(sign(rootKSK, "", rootPrivateKSK, algorithm, record("", rootKSK), record("", rootZSK)), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ds("com", digestType, comKSK))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ns("ns.com"))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("ns.com", a("1.1.1.1")))), signedZone("com", "ns.com", "1.1.1.1", sign(comKSK, "com", comPrivateKSK, algorithm, record("com", comKSK), record("com", comZSK)), sign(comPrivateZSK, outOfDateSig, record("example.com", a("1.1.1.2")))));
    DNSMessage message = client.query("example.com", Record.TYPE.A);
    assertNotNull(message);
    assertFalse(message.authenticData);
    checkCorrectExampleMessage(message);
}
Also used : RRSIG(org.minidns.record.RRSIG) Date(java.util.Date) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 22 with DnsMessage

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

the class DNSSECClientTest method testValidNSEC.

@SuppressWarnings("unchecked")
@Test
public void testValidNSEC() throws Exception {
    DNSWorld world = applyZones(client, signedRootZone(sign(rootKSK, "", rootPrivateKSK, algorithm, record("", rootKSK), record("", rootZSK)), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ds("com", digestType, comKSK))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ns("ns.com"))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("ns.com", a("1.1.1.1")))), signedZone("com", "ns.com", "1.1.1.1", sign(comKSK, "com", comPrivateKSK, algorithm, record("com", comKSK), record("com", comZSK)), sign(comZSK, "com", comPrivateZSK, algorithm, record("example.com", a("1.1.1.2")))));
    DNSMessage.Builder nsecMessage = DNSMessage.builder();
    List<Record<? extends Data>> records = DNSSECWorld.merge(sign(comZSK, "com", comPrivateZSK, algorithm, record("example.com", nsec("www.example.com", Record.TYPE.A))), sign(comZSK, "com", comPrivateZSK, algorithm, record("example.com", soa("sns.dns.icann.org", "noc.dns.icann.org", 2015081265, 7200, 3600, 1209600, 3600))));
    nsecMessage.setNameserverRecords(records);
    nsecMessage.setAuthoritativeAnswer(true);
    world.addPreparedResponse(new DNSSECWorld.AddressedNsecResponse(InetAddress.getByAddress("ns.com", new byte[] { 1, 1, 1, 1 }), nsecMessage.build()));
    DNSMessage message = client.query("nsec.example.com", Record.TYPE.A);
    client.setStripSignatureRecords(false);
    assertNotNull(message);
    assertEquals(0, message.answerSection.size());
    assertTrue(message.authenticData);
}
Also used : DNSSECWorld.rrsigRecord(org.minidns.dnssec.DNSSECWorld.rrsigRecord) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSWorld(org.minidns.DNSWorld) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 23 with DnsMessage

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

the class DNSSECClientTest method testBasicValid.

@SuppressWarnings("unchecked")
@Test
public void testBasicValid() throws IOException {
    applyZones(client, signedRootZone(sign(rootKSK, "", rootPrivateKSK, algorithm, record("", rootKSK), record("", rootZSK)), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ds("com", digestType, comKSK))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ns("ns.com"))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("ns.com", a("1.1.1.1")))), signedZone("com", "ns.com", "1.1.1.1", sign(comKSK, "com", comPrivateKSK, algorithm, record("com", comKSK), record("com", comZSK)), sign(comZSK, "com", comPrivateZSK, algorithm, record("example.com", a("1.1.1.2")))));
    DNSMessage message = client.query("example.com", Record.TYPE.A);
    assertNotNull(message);
    assertTrue(message.authenticData);
    checkCorrectExampleMessage(message);
}
Also used : DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 24 with DnsMessage

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

the class DNSMessageTest method testTXTLookup.

@Test
public void testTXTLookup() throws Exception {
    DNSMessage m = getMessageFromResource("codinghorror-txt");
    HashSet<String> txtToBeFound = new HashSet<>();
    txtToBeFound.add("google-site-verification=2oV3cW79A6icpGf-JbLGY4rP4_omL4FOKTqRxb-Dyl4");
    txtToBeFound.add("keybase-site-verification=dKxf6T30x5EbNIUpeJcbWxUABJEnVWzQ3Z3hCumnk10");
    txtToBeFound.add("v=spf1 include:spf.mandrillapp.com ~all");
    List<Record<? extends Data>> answers = m.answerSection;
    for (Record<? extends Data> r : answers) {
        assertCsEquals("codinghorror.com", r.name);
        Data d = r.getPayload();
        assertTrue(d instanceof TXT);
        assertEquals(TYPE.TXT, d.getType());
        TXT txt = (TXT) d;
        assertTrue(txtToBeFound.contains(txt.getText()));
        txtToBeFound.remove(txt.getText());
    }
    assertEquals(txtToBeFound.size(), 0);
}
Also used : TXT(org.minidns.record.TXT) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with DnsMessage

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

the class DNSMessageTest method testMessageSelfEasyAnswersReconstruction.

@Test
public void testMessageSelfEasyAnswersReconstruction() throws Exception {
    DNSMessage.Builder dmb = DNSMessage.builder();
    dmb.addAnswer(record("www.example.com", a("127.0.0.1"))).addAnswer(record("www.example.com", ns("example.com")));
    dmb.setRecursionAvailable(true);
    dmb.setCheckingDisabled(true);
    dmb.setQrFlag(false);
    dmb.setId(43);
    DNSMessage message = new DNSMessage(dmb.build().toArray());
    assertEquals(0, message.questions.size());
    assertEquals(2, message.answerSection.size());
    assertEquals(0, message.additionalSection.size());
    assertEquals(0, message.authoritySection.size());
    assertTrue(message.recursionAvailable);
    assertFalse(message.authenticData);
    assertTrue(message.checkingDisabled);
    assertFalse(message.qr);
    assertEquals(43, message.id);
    assertCsEquals("www.example.com", message.answerSection.get(0).name);
    assertEquals(TYPE.A, message.answerSection.get(0).type);
    assertCsEquals("127.0.0.1", message.answerSection.get(0).payloadData.toString());
    assertCsEquals("www.example.com", message.answerSection.get(1).name);
    assertEquals(TYPE.NS, message.answerSection.get(1).type);
    assertCsEquals("example.com.", message.answerSection.get(1).payloadData.toString());
}
Also used : DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

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