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