Search in sources :

Example 6 with TYPE

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

the class Verifier method verifyNsec3.

public UnverifiedReason verifyNsec3(DNSName zone, Record<? extends Data> nsec3record, Question q) {
    NSEC3 nsec3 = (NSEC3) nsec3record.payloadData;
    DigestCalculator digestCalculator = algorithmMap.getNsecDigestCalculator(nsec3.hashAlgorithm);
    if (digestCalculator == null) {
        return new AlgorithmNotSupportedReason(nsec3.hashAlgorithmByte, nsec3.getType(), nsec3record);
    }
    byte[] bytes = nsec3hash(digestCalculator, nsec3.salt, q.name.getBytes(), nsec3.iterations);
    String s = Base32.encodeToString(bytes);
    DNSName computedNsec3Record = DNSName.from(s + "." + zone);
    if (nsec3record.name.equals(computedNsec3Record)) {
        for (TYPE type : nsec3.types) {
            if (type.equals(q.type)) {
                return new NSECDoesNotMatchReason(q, nsec3record);
            }
        }
        return null;
    }
    if (nsecMatches(s, nsec3record.name.getHostpart(), Base32.encodeToString(nsec3.nextHashed))) {
        return null;
    }
    return new NSECDoesNotMatchReason(q, nsec3record);
}
Also used : NSEC3(org.minidns.record.NSEC3) AlgorithmNotSupportedReason(org.minidns.dnssec.UnverifiedReason.AlgorithmNotSupportedReason) NSECDoesNotMatchReason(org.minidns.dnssec.UnverifiedReason.NSECDoesNotMatchReason) DNSName(org.minidns.dnsname.DNSName) TYPE(org.minidns.record.Record.TYPE)

Example 7 with TYPE

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

the class RRSIG method parse.

public static RRSIG parse(DataInputStream dis, byte[] data, int length) throws IOException {
    TYPE typeCovered = TYPE.getType(dis.readUnsignedShort());
    byte algorithm = dis.readByte();
    byte labels = dis.readByte();
    long originalTtl = dis.readInt() & 0xFFFFFFFFL;
    Date signatureExpiration = new Date((dis.readInt() & 0xFFFFFFFFL) * 1000);
    Date signatureInception = new Date((dis.readInt() & 0xFFFFFFFFL) * 1000);
    int keyTag = dis.readUnsignedShort();
    DNSName signerName = DNSName.parse(dis, data);
    int sigSize = length - signerName.size() - 18;
    byte[] signature = new byte[sigSize];
    if (dis.read(signature) != signature.length)
        throw new IOException();
    return new RRSIG(typeCovered, null, algorithm, labels, originalTtl, signatureExpiration, signatureInception, keyTag, signerName, signature);
}
Also used : IOException(java.io.IOException) DNSName(org.minidns.dnsname.DNSName) TYPE(org.minidns.record.Record.TYPE) Date(java.util.Date)

Example 8 with TYPE

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

the class ResolverApi method resolve.

public final <D extends Data> ResolverResult<D> resolve(DNSName name, Class<D> type) throws IOException {
    TYPE t = TYPE.getType(type);
    Question q = new Question(name, t);
    return resolve(q);
}
Also used : Question(org.minidns.dnsmessage.Question) TYPE(org.minidns.record.Record.TYPE)

Example 9 with TYPE

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

the class NSEC method parse.

public static NSEC parse(DataInputStream dis, byte[] data, int length) throws IOException {
    DNSName next = DNSName.parse(dis, data);
    byte[] typeBitmap = new byte[length - next.size()];
    if (dis.read(typeBitmap) != typeBitmap.length)
        throw new IOException();
    TYPE[] types = readTypeBitMap(typeBitmap);
    return new NSEC(next, types);
}
Also used : IOException(java.io.IOException) DNSName(org.minidns.dnsname.DNSName) TYPE(org.minidns.record.Record.TYPE)

Example 10 with TYPE

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

the class NSEC method createTypeBitMap.

static byte[] createTypeBitMap(TYPE[] types) {
    List<Integer> typeList = new ArrayList<Integer>();
    for (TYPE type : types) {
        typeList.add(type.getValue());
    }
    Collections.sort(typeList);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    try {
        int windowBlock = -1;
        byte[] bitmap = null;
        for (Integer type : typeList) {
            if (windowBlock == -1 || (type >> 8) != windowBlock) {
                if (windowBlock != -1)
                    writeOutBlock(bitmap, dos);
                windowBlock = (type >> 8);
                dos.writeByte(windowBlock);
                bitmap = new byte[32];
            }
            int a = (type >> 3) % 32;
            int b = type % 8;
            bitmap[a] |= (128 >> b);
        }
        if (windowBlock != -1)
            writeOutBlock(bitmap, dos);
    } catch (IOException e) {
        // Should never happen.
        throw new RuntimeException(e);
    }
    return baos.toByteArray();
}
Also used : DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TYPE(org.minidns.record.Record.TYPE)

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