/** * Dns lookup more efficient than the INetAddress.getHostName(ip) * * @param hostIp * @return * @throws IOException */ public String dnsLookup(final String hostIp) { try { final Name name = ReverseMap.fromAddress(hostIp); final int type = Type.PTR; final int dclass = DClass.IN; final Record rec = Record.newRecord(name, type, dclass); final Message query = Message.newQuery(rec); final Message response = _resolver.send(query); final Record[] answers = response.getSectionArray(Section.ANSWER); if (answers.length > 0) { String ret = answers[0].rdataToString(); if (ret.endsWith(".")) { ret = ret.substring(0, ret.length() - 1); } return ret; } } catch (final IOException e) { LOGGER.warn("Failed to resolve hostname for " + hostIp, e); } return UNKNOWN_HOST; }
private RRset makeDelegationSignerSet(DomainResource domain) { RRset signerSet = new RRset(); for (DelegationSignerData signerData : domain.getDsData()) { DSRecord dsRecord = new DSRecord( toAbsoluteName(domain.getFullyQualifiedDomainName()), DClass.IN, dnsDefaultDsTtl.getStandardSeconds(), signerData.getKeyTag(), signerData.getAlgorithm(), signerData.getDigestType(), signerData.getDigest()); signerSet.addRR(dsRecord); } return signerSet; }
@Test public void testSentMessageTooLongThrowsException() throws Exception { Update oversize = new Update(Name.fromString("tld", Name.root)); for (int i = 0; i < 2000; i++) { oversize.add( ARecord.newRecord( Name.fromString("test-extremely-long-name-" + i + ".tld", Name.root), Type.A, DClass.IN)); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); when(mockSocket.getOutputStream()).thenReturn(outputStream); IllegalArgumentException thrown = expectThrows(IllegalArgumentException.class, () -> resolver.send(oversize)); assertThat(thrown).hasMessageThat().contains("message larger than maximum"); }
/** * @param ip, like "192.168.1.1" * @return the complete DNS record for that IP. */ @Converter public static Record toRecord(String ip) throws IOException { Resolver res = new ExtendedResolver(); Name name = ReverseMap.fromAddress(ip); int type = Type.PTR; int dclass = DClass.IN; Record rec = Record.newRecord(name, type, dclass); Message query = Message.newQuery(rec); Message response = res.send(query); Record[] answers = response.getSectionArray(Section.ANSWER); if (answers.length == 0) { return null; } else { return answers[0]; } }
public static void main(String[] args) throws Exception { try (DatagramSocket socket = new DatagramSocket()) { Message message = new Message(); Header header = message.getHeader(); header.setOpcode(Opcode.QUERY); header.setID(1); header.setRcode(Rcode.NOERROR); header.setFlag(Flags.RD); message.addRecord(Record.newRecord(new Name("www.xqbase.com."), Type.A, DClass.IN), Section.QUESTION); byte[] data = message.toWire(); DatagramPacket packet = new DatagramPacket(data, data.length, new InetSocketAddress("localhost", 53)); socket.send(packet); data = new byte[65536]; packet = new DatagramPacket(data, data.length); socket.setSoTimeout(2000); socket.receive(packet); Message response = new Message(Bytes.left(data, packet.getLength())); System.out.println(response); } }
private String[] findAddressesRecursive(Set<Name> stack, Name target) throws IOException { String[] ipv4Addresses = null; String[] ipv6Addresses = null; Message ipv4 = lookup(stack, getRoots(), Message.newQuery(Record.newRecord(target, Type.A, DClass.IN))); if (ipv4 != null) ipv4Addresses = findAddresses(target, ipv4.getSectionArray(Section.ANSWER)); Message ipv6 = lookup(stack, getRoots(), Message.newQuery(Record.newRecord(target, Type.AAAA, DClass.IN))); if (ipv6 != null) ipv6Addresses = findAddresses(target, ipv6.getSectionArray(Section.ANSWER)); String[] addresses = new String[0]; if (ipv4Addresses != null) addresses = ipv4Addresses; if (ipv6Addresses != null) { String[] concatAddresses = new String[addresses.length + ipv6Addresses.length]; System.arraycopy(addresses, 0, concatAddresses, 0, addresses.length); System.arraycopy(ipv6Addresses, 0, concatAddresses, addresses.length, ipv6Addresses.length); addresses = concatAddresses; } if (addresses.length == 0) return null; return addresses; }
/** * Given an SRRset that is signed by a DNSKEY found in the key_rrset, verify * it. This will return the status (either BOGUS or SECURE) and set that * status in rrset. * * @param rrset The SRRset to verify. * @param keyRrset The set of keys to verify against. * @return The status (BOGUS or SECURE). */ public SecurityStatus verifySRRset(SRRset rrset, SRRset keyRrset) { String rrsetName = rrset.getName() + "/" + Type.string(rrset.getType()) + "/" + DClass.string(rrset.getDClass()); if (rrset.getSecurityStatus() == SecurityStatus.SECURE) { logger.trace("verifySRRset: rrset <" + rrsetName + "> previously found to be SECURE"); return SecurityStatus.SECURE; } SecurityStatus status = this.verifier.verify(rrset, keyRrset); if (status != SecurityStatus.SECURE) { logger.debug("verifySRRset: rrset <" + rrsetName + "> found to be BAD"); status = SecurityStatus.BOGUS; } else { logger.trace("verifySRRset: rrset <" + rrsetName + "> found to be SECURE"); } rrset.setSecurityStatus(status); return status; }
@Test public void testUnsignedThatMustBeSigned() throws IOException { Name query = Name.fromString("www.ingotronic.ch."); // prepare a faked, unsigned response message that must have a signature // to be valid Message message = new Message(); message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION); message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER); add("www.ingotronic.ch./A", message); Message response = resolver.send(createMessage("www.ingotronic.ch./A")); assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD)); assertEquals(Rcode.SERVFAIL, response.getRcode()); assertEquals("validate.bogus.missingsig", getReason(response)); }
@Test public void testModifiedSignature() throws IOException { Name query = Name.fromString("www.ingotronic.ch."); // prepare a faked, unsigned response message that must have a signature // to be valid Message message = new Message(); message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION); message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER); message.addRecord(new RRSIGRecord(query, DClass.IN, 0, Type.A, Algorithm.RSASHA256, 5, new Date(System.currentTimeMillis() + 5000), new Date(System.currentTimeMillis() - 5000), 1234, Name.fromString("ingotronic.ch."), new byte[] { 1, 2, 3 }), Section.ANSWER); add("www.ingotronic.ch./A", message); Message response = resolver.send(createMessage("www.ingotronic.ch./A")); assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD)); assertEquals(Rcode.SERVFAIL, response.getRcode()); assertTrue(getReason(response).startsWith("failed.answer.positive:{ www.ingotronic.ch.")); }
protected void setUp() throws Exception { dnsServer = new TestableDNSServer(); DefaultConfigurationBuilder db = new DefaultConfigurationBuilder(); db.load(new ByteArrayInputStream("<dnsserver><autodiscover>true</autodiscover><authoritative>false</authoritative></dnsserver>".getBytes())); dnsServer.setLog(LoggerFactory.getLogger("MockLog")); dnsServer.configure(db); dnsServer.init(); defaultCache = Lookup.getDefaultCache(DClass.IN); defaultResolver = Lookup.getDefaultResolver(); defaultSearchPaths = Lookup.getDefaultSearchPath(); Lookup.setDefaultCache(null, DClass.IN); Lookup.setDefaultResolver(null); Lookup.setDefaultSearchPath(new Name[] {}); }
private static String reverseDnsLookupUsingDnsJavaSimpleResolver(long ipAddress) throws IOException { String result = null; byte[] address = convertLongAddressToBuf(ipAddress); Name name = ReverseMap.fromAddress(InetAddress.getByAddress(address)); Record record = Record.newRecord(name, Type.PTR, DClass.IN); Message query = Message.newQuery(record); Message response = simpleResolver.send(query); Record[] answers = response.getSectionArray(Section.ANSWER); if (answers.length != 0) { // If PTR-record exists this will be at index 1 or above (more than one PTR-record may exist) Record answer = (answers.length > 1) ? answers[1] : answers[0]; result = answer.rdataToString(); // remove trailing "." result = result.endsWith(".") ? result.substring(0, result.length() - 1) : result; } else { throw new IOException("Empty DNS response."); } return result; }
public static synchronized Message makeQuery(String nameString, int id) throws TextParseException { Name name = Name.fromString(nameString, Name.root); Record question = Record.newRecord(name, Type.A, DClass.ANY); Message query = Message.newQuery(question); query.getHeader().setID(id); return query; }
private RRset makeNameServerSet(DomainResource domain) { RRset nameServerSet = new RRset(); for (String hostName : domain.loadNameserverFullyQualifiedHostNames()) { NSRecord record = new NSRecord( toAbsoluteName(domain.getFullyQualifiedDomainName()), DClass.IN, dnsDefaultNsTtl.getStandardSeconds(), toAbsoluteName(hostName)); nameServerSet.addRR(record); } return nameServerSet; }
private RRset makeAddressSet(HostResource host) { RRset addressSet = new RRset(); for (InetAddress address : host.getInetAddresses()) { if (address instanceof Inet4Address) { ARecord record = new ARecord( toAbsoluteName(host.getFullyQualifiedHostName()), DClass.IN, dnsDefaultATtl.getStandardSeconds(), address); addressSet.addRR(record); } } return addressSet; }
private RRset makeV6AddressSet(HostResource host) { RRset addressSet = new RRset(); for (InetAddress address : host.getInetAddresses()) { if (address instanceof Inet6Address) { AAAARecord record = new AAAARecord( toAbsoluteName(host.getFullyQualifiedHostName()), DClass.IN, dnsDefaultATtl.getStandardSeconds(), address); addressSet.addRR(record); } } return addressSet; }
@Before public void before() throws Exception { simpleQuery = Message.newQuery(Record.newRecord(Name.fromString("example.com."), Type.A, DClass.IN)); expectedResponse = responseMessageWithCode(simpleQuery, Rcode.NOERROR); when(mockFactory.createSocket(InetAddress.getByName(UPDATE_HOST), DnsMessageTransport.DNS_PORT)) .thenReturn(mockSocket); resolver = new DnsMessageTransport(mockFactory, UPDATE_HOST, Duration.ZERO); }
@Override public void process(Exchange exchange) throws Exception { String dnsName = exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class); ObjectHelper.notEmpty(dnsName, "Header " + DnsConstants.DNS_NAME); Object type = exchange.getIn().getHeader(DnsConstants.DNS_TYPE); Integer dnsType = null; if (type != null) { dnsType = Type.value(String.valueOf(type)); } Object dclass = exchange.getIn().getHeader(DnsConstants.DNS_CLASS); Integer dnsClass = null; if (dclass != null) { dnsClass = DClass.value(String.valueOf(dclass)); } Lookup lookup = (dnsClass == null) ? (dnsType == null ? new Lookup(dnsName) : new Lookup(dnsName, dnsType)) : new Lookup(dnsName, dnsType, dnsClass); lookup.run(); if (lookup.getAnswers() != null) { exchange.getIn().setBody(lookup.getAnswers()); } else { throw new CamelException(lookup.getErrorString()); } }
@Override public void process(Exchange exchange) throws Exception { String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class); SimpleResolver resolver = new SimpleResolver(server); int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class)); if (type == -1) { // default: if unparsable value given, use A. type = Type.A; } String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class); if (dclassValue == null) { dclassValue = ""; } int dclass = DClass.value(dclassValue); if (dclass == -1) { // by default, value is IN. dclass = DClass.IN; } Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class), Name.root); Record rec = Record.newRecord(name, type, dclass); Message query = Message.newQuery(rec); Message response = resolver.send(query); exchange.getIn().setBody(response); }
@Override public void process(Exchange exchange) throws Exception { SimpleResolver resolver = new SimpleResolver(); int type = Type.TXT; Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root); Record rec = Record.newRecord(name, type, DClass.IN); Message query = Message.newQuery(rec); Message response = resolver.send(query); Record[] records = response.getSectionArray(Section.ANSWER); if (records.length > 0) { exchange.getIn().setBody(records[0].rdataToString()); } else { exchange.getIn().setBody(null); } }
/** * Overloaded constructor taking as argument Cache size and TTL. * * @param cacheSize Unsigned <code>int</code> defining the Cache size * @param cacheTTL Unsigned <code>int</code> defining the Cache TTL */ public DnsServicesDiscovery(int cacheSize, int cacheTTL) { this.anyClassCache = new Cache(DClass.ANY); this.anyClassCache.setMaxEntries(cacheSize); this.anyClassCache.setMaxNCache(cacheTTL); this.helper = this.new ServicesLookupHelper(); this.errorsTrace = new ThreadLocal<Map<String, StatusCode>>() { @Override protected Map<String, StatusCode> initialValue() { return new LinkedHashMap<>(); } }; }
@Override public Lookup forName(String fqdn) { try { return new Lookup(fqdn, Type.SRV, DClass.IN); } catch (TextParseException e) { throw new DnsException("unable to create lookup for name: " + fqdn, e); } }
private Message messageWithRCode(String query, int rcode) throws TextParseException { Name queryName = Name.fromString(query); Record question = Record.newRecord(queryName, Type.SRV, DClass.IN); Message queryMessage = Message.newQuery(question); Message result = new Message(); result.setHeader(queryMessage.getHeader()); result.addRecord(question, Section.QUESTION); result.getHeader().setRcode(rcode); return result; }
private Message messageWithNodes(String query, Iterable<String> names) throws TextParseException { Name queryName = Name.fromString(query); Record question = Record.newRecord(queryName, Type.SRV, DClass.IN); Message queryMessage = Message.newQuery(question); Message result = new Message(); result.setHeader(queryMessage.getHeader()); result.addRecord(question, Section.QUESTION); for (String name1 : names){ result.addRecord(new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER); } return result; }
private static void updateRecords(Map<String, Record[]> records, String host, String value, int ttl) throws IOException { if (value == null) { records.remove(host); return; } Name origin = new Name((host.endsWith(".") ? host : host + ".").replace('_', '-')); ArrayList<Record> recordList = new ArrayList<>(); for (String s : value.split("[,;]")) { if (s.matches(".*[A-Z|a-z].*")) { CNAMERecord record = new CNAMERecord(origin, DClass.IN, ttl, new Name(s.endsWith(".") ? s : s + ".")); recordList.add(record); continue; } String[] ss = s.split("\\."); if (ss.length < 4) { continue; } byte[] ip = new byte[4]; for (int i = 0; i < 4; i ++) { ip[i] = (byte) Numbers.parseInt(ss[i]); } recordList.add(new ARecord(origin, DClass.IN, ttl, InetAddress.getByAddress(ip))); } records.put(host, recordList.toArray(EMPTY_RECORDS)); }
public boolean sendAdd() throws TextParseException, IOException { boolean rc = false; Resolver res = createResolver(); String revIp = buildReverseIpString(); Name owner = new Name(revIp.toString()); PTRRecord ptr = new PTRRecord(owner, DClass.IN, ttl, new Name(fqdn)); Name _zone = buildZoneName(revIp); Update update = new Update(_zone); update.delete(owner); update.add(ptr); if (log.isDebugEnabled()) { log.debug("Sending reverse DDNS update (replace) to server=" + server + ":\n" + update.toString()); } else if (log.isInfoEnabled()) { log.info("Sending reverse DDNS update (replace): " + ptr.toString()); } Message response = res.send(update); if (response.getRcode() == Rcode.NOERROR) { log.info("Reverse DDNS update (replace) succeeded: " + ptr.toString()); rc = true; } else { log.error("Reverse DDNS update (replace) failed (rcode=" + Rcode.string(response.getRcode()) + "): " + ptr.toString()); } return rc; }
public boolean sendDelete() throws TextParseException, IOException { boolean rc = false; Resolver res = createResolver(); String revIp = buildReverseIpString(); Name owner = new Name(revIp); PTRRecord ptr = new PTRRecord(owner, DClass.IN, 0, new Name(fqdn)); Name _zone = buildZoneName(revIp); Update update = new Update(_zone); update.delete(ptr); if (log.isDebugEnabled()) { log.debug("Sending reverse DDNS update (delete) to server=" + server + ":\n" + update.toString()); } else if (log.isInfoEnabled()) { log.info("Sending reverse DDNS update (delete): " + ptr.toString()); } Message response = res.send(update); if (response.getRcode() == Rcode.NOERROR) { log.info("Reverse DDNS update (delete) succeeded: " + ptr.toString()); rc = true; } else { log.error("Reverse DDNS update (delete) failed (rcode=" + Rcode.string(response.getRcode()) + "): " + ptr.toString()); } return rc; }
@Test public void canResolveRecord() throws Exception { AcceptanceTestRunner runner = new AcceptanceTestRunner(); runner.runUngarded(new AcceptanceScenario() { public void run(WebDriver driver, String deployedURL) throws Exception { int id = new SecureRandom().nextInt(); final String systemTestBase = "system-tests.onomate.test"; final String soaBase = "soa-" + id +"."+ systemTestBase; final String ns = "ns." + soaBase; final String contactName = "admin." + soaBase; final String aTestRecordHost = "record."+soaBase; final String aTestRecordNS = "ns.test"; OnomateAssembly assembly = new OnomateAssembly(driver, deployedURL); OnomateAssembly.Dashboard board = assembly.gotoLanding().authenticate().newAuthority(soaBase, ns, contactName); board.authorityByZone(soaBase).details().createRecord(aTestRecordHost, OnomateAssembly.RecordType.NS, aTestRecordNS); Options.set("verbose"); SimpleResolver resolver = new SimpleResolver(); resolver.setAddress(InetAddress.getLocalHost()); resolver.setPort(9101); Record query = Record.newRecord(Name.fromString(aTestRecordHost + "."), Type.NS, DClass.IN); Message question = Message.newQuery(query); Message response = resolver.send(question); Record responses[] = response.getSectionArray(Section.AUTHORITY); NSRecord record = ((NSRecord) responses[0]); assertEquals(record.getName().toString(), aTestRecordHost+ "."); assertEquals(record.getTarget().toString(), aTestRecordNS + "."); } }); }
@Test public void canResolveRecord() throws Exception { AcceptanceTestRunner runner = new AcceptanceTestRunner(); runner.runUngarded(new AcceptanceScenario() { public void run(WebDriver driver, String deployedURL) throws Exception { int id = new SecureRandom().nextInt(); final String systemTestBase = "system-tests.onomate.test"; final String soaBase = "soa-" + id +"."+ systemTestBase; final String ns = "ns." + soaBase; final String contactName = "admin." + soaBase; final String aTestRecordHost = "record."+soaBase; final String aRealTestRecord = soaBase; OnomateAssembly assembly = new OnomateAssembly(driver, deployedURL); OnomateAssembly.Dashboard board = assembly.gotoLanding().authenticate().newAuthority(soaBase, ns, contactName); board.authorityByZone(soaBase).details().createRecord(aTestRecordHost, OnomateAssembly.RecordType.CNAME, aRealTestRecord); Options.set("verbose"); SimpleResolver resolver = new SimpleResolver(); resolver.setAddress(InetAddress.getLocalHost()); resolver.setPort(9101); Record query = Record.newRecord(Name.fromString(aTestRecordHost + "."), Type.CNAME, DClass.IN); Message question = Message.newQuery(query); Message response = resolver.send(question); Record responses[] = response.getSectionArray(Section.ANSWER); CNAMERecord record = ((CNAMERecord) responses[0]); assertEquals(record.getName().toString(), aTestRecordHost+ "."); assertEquals(record.getTarget().toString(), aRealTestRecord + "."); } }); }
@Test public void testHasSignedNsecsWithoutSignedSigsReturnsFalse() { Message m = new Message(); m.addRecord(new NSECRecord(Name.root, DClass.IN, 0, Name.root, new int[] { Type.A }), Section.AUTHORITY); SMessage sm = new SMessage(m); boolean result = new ValUtils().hasSignedNsecs(sm); assertFalse(result); }
private Record parseQuestion(String line) throws TextParseException { String[] temp = line.replaceAll("\\s+", " ").split(" "); if (Type.value(temp[2]) == -1) { System.out.println(temp[2]); } return Record.newRecord(Name.fromString(temp[0]), Type.value(temp[2]), DClass.value(temp[1])); }
@Test() public void testGetSectionByType() throws UnknownHostException { Message m = new Message(); Record r1 = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0})); m.addRecord(r1, Section.ANSWER); Record r2 = new AAAARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1})); m.addRecord(r2, Section.ANSWER); SMessage sm = new SMessage(m); SRRset[] result = sm.getSectionRRsets(Section.ANSWER, Type.A); assertEquals(1, result.length); assertEquals(Type.A, result[0].getType()); }
@Test() public void testRecordCountForIsValid() throws UnknownHostException { Message m = new Message(); m.addRecord(new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0})), Section.ANSWER); SMessage sm = new SMessage(m); int count = sm.getCount(Section.ANSWER); assertEquals(1, count); }
@Test() public void testAnswerSectionSearchFound() throws UnknownHostException { Message m = new Message(); Record r = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0})); m.addRecord(r, Section.ANSWER); SMessage sm = new SMessage(m); SRRset result = sm.findAnswerRRset(Name.root, Type.A, DClass.IN); assertEquals(r, result.first()); }
@Test() public void testAnswerSectionSearchNotFoundDifferentClass() throws UnknownHostException { Message m = new Message(); Record r = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0})); m.addRecord(r, Section.ANSWER); SMessage sm = new SMessage(m); SRRset result = sm.findAnswerRRset(Name.root, Type.A, DClass.CH); assertNull(result); }
@Test() public void testAnswerSectionSearchNotFoundDifferentType() throws UnknownHostException { Message m = new Message(); Record r = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0})); m.addRecord(r, Section.ANSWER); SMessage sm = new SMessage(m); SRRset result = sm.findAnswerRRset(Name.root, Type.MX, DClass.IN); assertNull(result); }
@Test() public void testAnswerSectionSearchNotFoundDifferentName() throws UnknownHostException, TextParseException { Message m = new Message(); Record r = new ARecord(Name.fromString("asdf."), DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0})); m.addRecord(r, Section.ANSWER); SMessage sm = new SMessage(m); SRRset result = sm.findAnswerRRset(Name.root, Type.MX, DClass.IN); assertNull(result); }
@SuppressWarnings("unchecked") @Test public void testDNameInNsecIsUnderstood_Rfc6672_5_3_4_1() throws IOException { Message nsecs = resolver.send(createMessage("alias.ingotronic.ch./NS")); RRset nsecSet = null; for (RRset set : nsecs.getSectionRRsets(Section.AUTHORITY)) { if (set.getName().equals(Name.fromString("alias.ingotronic.ch."))) { nsecSet = set; break; } } Message message = new Message(); message.getHeader().setRcode(Rcode.NXDOMAIN); message.addRecord(Record.newRecord(Name.fromString("www.alias.ingotronic.ch."), Type.A, DClass.IN), Section.QUESTION); Iterator<Record> rrs = nsecSet.rrs(); while (rrs.hasNext()) { message.addRecord(rrs.next(), Section.AUTHORITY); } Iterator<Record> sigs = nsecSet.sigs(); while (sigs.hasNext()) { message.addRecord(sigs.next(), Section.AUTHORITY); } add("www.alias.ingotronic.ch./A", message); Message response = resolver.send(createMessage("www.alias.ingotronic.ch./A")); assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD)); assertEquals(Rcode.SERVFAIL, response.getRcode()); assertEquals("failed.nxdomain.exists:www.alias.ingotronic.ch.", getReason(response)); }
@Test public void testDnskeyPrimeResponseWithEmptyAnswerIsBad() throws IOException { Message message = new Message(); message.addRecord(Record.newRecord(Name.root, Type.DNSKEY, DClass.IN), Section.QUESTION); add("./DNSKEY", message); Message response = resolver.send(createMessage("www.ingotronic.ch./A")); assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD)); assertEquals(Rcode.SERVFAIL, response.getRcode()); assertEquals("validate.bogus.badkey:.:dnskey.no_rrset:.", getReason(response)); }
@Test public void testRootDnskeyPrimeResponseWithNxDomainIsBad() throws IOException { Message message = new Message(); message.addRecord(Record.newRecord(Name.root, Type.DNSKEY, DClass.IN), Section.QUESTION); message.getHeader().setRcode(Rcode.NXDOMAIN); add("./DNSKEY", message); Message response = resolver.send(createMessage("www.ingotronic.ch./A")); assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD)); assertEquals(Rcode.SERVFAIL, response.getRcode()); assertEquals("validate.bogus.badkey:.:dnskey.no_rrset:.", getReason(response)); }
@Test public void testDsPrimeResponseWithEmptyAnswerIsBad() throws IOException { Message message = new Message(); message.addRecord(Record.newRecord(Name.fromString("ch."), Type.DS, DClass.IN), Section.QUESTION); add("ch./DS", message); Message response = resolver.send(createMessage("www.ingotronic.ch./A")); assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD)); assertEquals(Rcode.SERVFAIL, response.getRcode()); assertEquals("validate.bogus.badkey:ch.:failed.ds.nonsec:ch.", getReason(response)); }