Search in sources :

Example 36 with DnsMessage

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

the class DNSSECClientTest method testUnknownAlgorithm.

@SuppressWarnings("unchecked")
@Test
public void testUnknownAlgorithm() throws IOException {
    Date signatureExpiration = new Date(System.currentTimeMillis() + 14 * 24 * 60 * 60 * 1000);
    Date signatureInception = new Date(System.currentTimeMillis() - 14 * 24 * 60 * 60 * 1000);
    RRSIG unknownRrsig = rrsig(Record.TYPE.A, 213, 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")))), zone("com", "ns.com", "1.1.1.1", record("com", comKSK), record("com", comZSK), record("example.com", a("1.1.1.2")), record("example.com", unknownRrsig)));
    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 37 with DnsMessage

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

the class DNSSECClientTest method testUnsignedZone.

@SuppressWarnings("unchecked")
@Test
public void testUnsignedZone() 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")))), zone("com", "ns.com", "1.1.1.1", 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 : DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 38 with DnsMessage

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

the class DNSMessageTest method testComDsAndRrsigLookup.

@Test
public void testComDsAndRrsigLookup() throws Exception {
    DNSMessage m = getMessageFromResource("com-ds-rrsig");
    assertFalse(m.authoritativeAnswer);
    assertTrue(m.recursionDesired);
    assertTrue(m.recursionAvailable);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(2, answers.size());
    assertEquals(TYPE.DS, answers.get(0).type);
    assertEquals(TYPE.DS, answers.get(0).payloadData.getType());
    DS ds = (DS) answers.get(0).payloadData;
    assertEquals(30909, ds.keyTag);
    assertEquals(SignatureAlgorithm.RSASHA256, ds.algorithm);
    assertEquals(DigestAlgorithm.SHA256, ds.digestType);
    assertCsEquals("E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CFC41A5766", ds.getDigestHex());
    assertEquals(TYPE.RRSIG, answers.get(1).type);
    assertEquals(TYPE.RRSIG, answers.get(1).payloadData.getType());
    RRSIG rrsig = (RRSIG) answers.get(1).payloadData;
    assertEquals(TYPE.DS, rrsig.typeCovered);
    assertEquals(SignatureAlgorithm.RSASHA256, rrsig.algorithm);
    assertEquals(1, rrsig.labels);
    assertEquals(86400, rrsig.originalTtl);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    assertCsEquals("20150629170000", dateFormat.format(rrsig.signatureExpiration));
    assertCsEquals("20150619160000", dateFormat.format(rrsig.signatureInception));
    assertEquals(48613, rrsig.keyTag);
    assertCsEquals(".", rrsig.signerName);
    assertEquals(128, rrsig.signature.length);
    List<Record<? extends Data>> arr = m.additionalSection;
    assertEquals(1, arr.size());
    assertEquals(TYPE.OPT, arr.get(0).getPayload().getType());
    Record<? extends Data> opt = arr.get(0);
    EDNS edns = EDNS.fromRecord(opt);
    assertEquals(512, edns.udpPayloadSize);
    assertEquals(0, edns.version);
    assertTrue(edns.dnssecOk);
}
Also used : EDNS(org.minidns.edns.EDNS) Record(org.minidns.record.Record) Data(org.minidns.record.Data) RRSIG(org.minidns.record.RRSIG) SimpleDateFormat(java.text.SimpleDateFormat) DNSMessage(org.minidns.dnsmessage.DNSMessage) DS(org.minidns.record.DS) Test(org.junit.Test)

Example 39 with DnsMessage

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

the class DNSMessageTest method testAAAALookup.

@Test
public void testAAAALookup() throws Exception {
    DNSMessage m = getMessageFromResource("google-aaaa");
    assertFalse(m.authoritativeAnswer);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(1, answers.size());
    Record<? extends Data> answer = answers.get(0);
    assertCsEquals("google.com", answer.name);
    assertTrue(answer.getPayload() instanceof AAAA);
    assertEquals(TYPE.AAAA, answer.getPayload().getType());
    assertCsEquals("2a00:1450:400c:c02:0:0:0:8a", answer.getPayload().toString());
}
Also used : Record(org.minidns.record.Record) Data(org.minidns.record.Data) AAAA(org.minidns.record.AAAA) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 40 with DnsMessage

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

the class DNSMessageTest method getMessageFromResource.

DNSMessage getMessageFromResource(final String resourceFileName) throws Exception {
    InputStream inputStream = getClass().getResourceAsStream(resourceFileName);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (int readBytes = inputStream.read(); readBytes >= 0; readBytes = inputStream.read()) outputStream.write(readBytes);
    DNSMessage result = new DNSMessage(outputStream.toByteArray());
    inputStream.close();
    outputStream.close();
    assertNotNull(result);
    return result;
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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