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);
}
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()]);
}
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);
}
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());
}
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);
}
Aggregations