use of org.minidns.dnsname.DNSName in project minidns by MiniDNS.
the class DNSNameTest method getLabelsTest.
@Test
public void getLabelsTest() {
final String tldLabelString = "tld";
final String secondLevelString = "second-level-domain";
final String thirdLevelString = "third-level-domain";
final String dnsNameString = thirdLevelString + '.' + secondLevelString + '.' + tldLabelString;
final DNSName dnsName = DNSName.from(dnsNameString);
DNSLabel[] labels = dnsName.getLabels();
assertEquals(tldLabelString, labels[0].label);
assertEquals(secondLevelString, labels[1].label);
assertEquals(thirdLevelString, labels[2].label);
}
use of org.minidns.dnsname.DNSName in project minidns by MiniDNS.
the class Verifier method combine.
static byte[] combine(RRSIG rrsig, List<Record<? extends Data>> records) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
// Write RRSIG without signature
try {
rrsig.writePartialSignature(dos);
DNSName sigName = records.get(0).name;
if (!sigName.isRootLabel()) {
if (sigName.getLabelCount() < rrsig.labels) {
throw new DNSSECValidationFailedException("Invalid RRsig record");
}
if (sigName.getLabelCount() > rrsig.labels) {
// Expand wildcards
sigName = DNSName.from("*." + sigName.stripToLabels(rrsig.labels));
}
}
List<byte[]> recordBytes = new ArrayList<>();
for (Record<? extends Data> record : records) {
Record<Data> ref = new Record<>(sigName, record.type, record.clazzValue, rrsig.originalTtl, (Data) record.payloadData);
recordBytes.add(ref.toByteArray());
}
// Sort correctly (cause they might be ordered randomly)
// Where the RDATA begins
final int offset = sigName.size() + 10;
Collections.sort(recordBytes, new Comparator<byte[]>() {
@Override
public int compare(byte[] b1, byte[] b2) {
for (int i = offset; i < b1.length && i < b2.length; i++) {
if (b1[i] != b2[i]) {
return (b1[i] & 0xFF) - (b2[i] & 0xFF);
}
}
return b1.length - b2.length;
}
});
for (byte[] recordByte : recordBytes) {
dos.write(recordByte);
}
dos.flush();
} catch (IOException e) {
// Never happens
throw new RuntimeException(e);
}
return bos.toByteArray();
}
use of org.minidns.dnsname.DNSName in project minidns by MiniDNS.
the class InetAddressUtilTest method testReverseInet4Address.
@Test
public void testReverseInet4Address() {
Inet4Address inet4Address = InetAddressUtil.ipv4From(VALID_IPV4[0]);
DNSName reversedIpv4Address = InetAddressUtil.reverseIpAddressOf(inet4Address);
assertEquals(DNSName.from("1.0.168.192"), reversedIpv4Address);
}
use of org.minidns.dnsname.DNSName in project minidns by MiniDNS.
the class MX method parse.
public static MX parse(DataInputStream dis, byte[] data) throws IOException {
int priority = dis.readUnsignedShort();
DNSName name = DNSName.parse(dis, data);
return new MX(priority, name);
}
use of org.minidns.dnsname.DNSName in project minidns by MiniDNS.
the class SOA method parse.
public static SOA parse(DataInputStream dis, byte[] data) throws IOException {
DNSName mname = DNSName.parse(dis, data);
DNSName rname = DNSName.parse(dis, data);
long serial = dis.readInt() & 0xFFFFFFFFL;
int refresh = dis.readInt();
int retry = dis.readInt();
int expire = dis.readInt();
long minimum = dis.readInt() & 0xFFFFFFFFL;
return new SOA(mname, rname, serial, refresh, retry, expire, minimum);
}
Aggregations