Search in sources :

Example 6 with DnsName

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);
}
Also used : DNSName(org.minidns.dnsname.DNSName) DNSLabel(org.minidns.dnslabel.DNSLabel) Test(org.junit.Test)

Example 7 with DnsName

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();
}
Also used : DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) Data(org.minidns.record.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DNSName(org.minidns.dnsname.DNSName) Record(org.minidns.record.Record)

Example 8 with DnsName

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);
}
Also used : Inet4Address(java.net.Inet4Address) DNSName(org.minidns.dnsname.DNSName) Test(org.junit.Test)

Example 9 with DnsName

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);
}
Also used : DNSName(org.minidns.dnsname.DNSName)

Example 10 with DnsName

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);
}
Also used : DNSName(org.minidns.dnsname.DNSName)

Aggregations

DNSName (org.minidns.dnsname.DNSName)22 Test (org.junit.Test)8 IOException (java.io.IOException)6 DnsName (org.minidns.dnsname.DnsName)5 InetAddress (java.net.InetAddress)4 ArrayList (java.util.ArrayList)4 Data (org.minidns.record.Data)4 Record (org.minidns.record.Record)4 LinkedList (java.util.LinkedList)3 DNSMessage (org.minidns.dnsmessage.DNSMessage)3 Question (org.minidns.dnsmessage.Question)3 TYPE (org.minidns.record.Record.TYPE)3 UInt16 (org.jivesoftware.smack.datatypes.UInt16)2 RemoteConnectionEndpointLookupFailure (org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure)2 InternetAddressRR (org.minidns.record.InternetAddressRR)2 SRV (org.minidns.record.SRV)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1