Search in sources :

Example 1 with TYPE

use of org.minidns.record.Record.TYPE in project minidns by MiniDNS.

the class DnssecResolverApi method resolveDnssecReliable.

/**
 * Resolve the given name and type which is expected to yield DNSSEC authenticated results.
 *
 * @param name the DNS name to resolve.
 * @param type the class of the RR type to resolve.
 * @param <D> the RR type to resolve.
 * @return the resolver result.
 * @throws IOException in case an exception happens while resolving.
 * @see #resolveDnssecReliable(Question)
 */
public <D extends Data> ResolverResult<D> resolveDnssecReliable(DNSName name, Class<D> type) throws IOException {
    TYPE t = TYPE.getType(type);
    Question q = new Question(name, t);
    return resolveDnssecReliable(q);
}
Also used : Question(org.minidns.dnsmessage.Question) TYPE(org.minidns.record.Record.TYPE)

Example 2 with TYPE

use of org.minidns.record.Record.TYPE in project minidns by MiniDNS.

the class NSEC method readTypeBitMap.

static TYPE[] readTypeBitMap(byte[] typeBitmap) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(typeBitmap));
    int read = 0;
    ArrayList<TYPE> typeList = new ArrayList<TYPE>();
    while (typeBitmap.length > read) {
        int windowBlock = dis.readUnsignedByte();
        int bitmapLength = dis.readUnsignedByte();
        for (int i = 0; i < bitmapLength; i++) {
            int b = dis.readUnsignedByte();
            for (int j = 0; j < 8; j++) {
                if (((b >> j) & 0x1) > 0) {
                    typeList.add(TYPE.getType((windowBlock << 8) + (i * 8) + (7 - j)));
                }
            }
        }
        read += bitmapLength + 2;
    }
    return typeList.toArray(new TYPE[typeList.size()]);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataInputStream(java.io.DataInputStream) TYPE(org.minidns.record.Record.TYPE)

Example 3 with TYPE

use of org.minidns.record.Record.TYPE in project minidns by MiniDNS.

the class NSEC3 method parse.

public static NSEC3 parse(DataInputStream dis, int length) throws IOException {
    byte hashAlgorithm = dis.readByte();
    byte flags = dis.readByte();
    int iterations = dis.readUnsignedShort();
    int saltLength = dis.readUnsignedByte();
    byte[] salt = new byte[saltLength];
    if (dis.read(salt) != salt.length)
        throw new IOException();
    int hashLength = dis.readUnsignedByte();
    byte[] nextHashed = new byte[hashLength];
    if (dis.read(nextHashed) != nextHashed.length)
        throw new IOException();
    byte[] typeBitmap = new byte[length - (6 + saltLength + hashLength)];
    if (dis.read(typeBitmap) != typeBitmap.length)
        throw new IOException();
    TYPE[] types = NSEC.readTypeBitMap(typeBitmap);
    return new NSEC3(hashAlgorithm, flags, iterations, salt, nextHashed, types);
}
Also used : IOException(java.io.IOException) TYPE(org.minidns.record.Record.TYPE)

Example 4 with TYPE

use of org.minidns.record.Record.TYPE 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 5 with TYPE

use of org.minidns.record.Record.TYPE in project minidns by MiniDNS.

the class RecordsTest method testNsecRecord.

@Test
public void testNsecRecord() throws Exception {
    NSEC nsec = new NSEC("example.com", new TYPE[] { TYPE.A, TYPE.RRSIG, TYPE.DLV });
    assertEquals("example.com. A RRSIG DLV", nsec.toString());
    assertEquals(TYPE.NSEC, nsec.getType());
    byte[] nsecb = nsec.toByteArray();
    nsec = NSEC.parse(new DataInputStream(new ByteArrayInputStream(nsecb)), nsecb, nsecb.length);
    assertCsEquals("example.com", nsec.next);
    assertArrayEquals(new TYPE[] { TYPE.A, TYPE.RRSIG, TYPE.DLV }, nsec.types);
    assertEquals(0, NSEC.readTypeBitMap(NSEC.createTypeBitMap(new TYPE[0])).length);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) TYPE(org.minidns.record.Record.TYPE) Test(org.junit.Test)

Aggregations

TYPE (org.minidns.record.Record.TYPE)10 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 DNSName (org.minidns.dnsname.DNSName)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 Test (org.junit.Test)2 Question (org.minidns.dnsmessage.Question)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 Date (java.util.Date)1 DNSMessage (org.minidns.dnsmessage.DNSMessage)1 AlgorithmNotSupportedReason (org.minidns.dnssec.UnverifiedReason.AlgorithmNotSupportedReason)1 NSECDoesNotMatchReason (org.minidns.dnssec.UnverifiedReason.NSECDoesNotMatchReason)1 Data (org.minidns.record.Data)1 NSEC (org.minidns.record.NSEC)1 NSEC3 (org.minidns.record.NSEC3)1 Record (org.minidns.record.Record)1