DnsServicesDiscovery extends Configurable implements DnsDiscovery { @Override public boolean isDnsSecValid(Fqdn name) throws LookupException, ConfigurationException { try { ValidatorUtil.isValidDomainName(name); } catch(IllegalArgumentException exception) { throw new LookupException(StatusCode.ILLEGAL_FQDN, name.fqdn()); } validatedConf(); if (name == null || name.fqdn().isEmpty()) { name = new Fqdn(this.dnsSecDomain); } Map<String, Resolver> resolvers = retrieveResolvers(true); Iterator<String> itrResolvers = resolvers.keySet().iterator(); boolean validated = false; String server = null; do { server = itrResolvers.next(); statusChange(FormattingUtil.server(server)); statusChange(FormattingUtil.query(name, "", "SOA")); try { validated = DnsUtil.checkDnsSec(name, resolvers.get(server), Type.SOA); if (validated) { statusChange(FormattingUtil.response(FormattingUtil.authenticData(name.fqdn()))); } else { statusChange(FormattingUtil.response(FormattingUtil.networkError(name.fqdn()))); } } catch (LookupException le) { if (le.dnsError() == StatusCode.RESOURCE_LOOKUP_ERROR) { statusChange(FormattingUtil.response(FormattingUtil.unableToResolve(name.fqdn()))); } else { statusChange(FormattingUtil.response(FormattingUtil.unableToValidate(name.fqdn()))); } if (le.dnsError() == StatusCode.RESOURCE_INSECURE_ERROR) { throw ExceptionsUtil.build(StatusCode.DNSSEC_STATUS_ERROR, "DNSSEC Validation Failed", new LinkedHashMap<String, StatusCode>()); } throw le; } } while (itrResolvers.hasNext() && !validated); return validated; } DnsServicesDiscovery();  DnsServicesDiscovery(int cacheSize, int cacheTTL); @Override Set<String> listServiceTypes(Fqdn browsingDomain, boolean secValidation); @Override Set<ServiceInstance> listServiceInstances(Fqdn browsingDomain, CompoundLabel type, boolean secValidation); @Override Set<TextRecord> listTextRecords(Fqdn browsingDomain, String label, boolean secValidation); @Override Set<CertRecord> listTLSARecords(Fqdn browsingDomain, DnsCertPrefix tlsaPrefix,
                                                    boolean secValidation); @Override boolean isDnsSecValid(Fqdn name);  }
@Test public void checkDnsSec() { try { this.discovery = new DnsServicesDiscovery(); this.discovery.dnsSecDomain(Constants.DEFAULT_DNSSEC_DOMAIN) .trustAnchorDefault(Constants.DEFAULT_TRUST_ANCHOR) .dnsServer(InetAddress.getByName(DNS_RESOLVER)) .introspected(true) .observer(this) .checkConfiguration(true); this.discovery.isDnsSecValid(new Fqdn(SERVICE_NAME)); } catch (ConfigurationException ex) { Assert.fail("Expected correct configuration, not " + ex.toString()); } catch (UnknownHostException ex) { Assert.fail("Expected correct retrieval of localhost, not " + ex.toString()); } catch (LookupException ex) { Assert.fail("Expected correct validation, not " + ex.toString()); } }
@Test public void checkDnsSecInvalid() { try { this.discovery = new DnsServicesDiscovery(); this.discovery.dnsSecDomain(Constants.DEFAULT_DNSSEC_DOMAIN) .trustAnchorDefault(Constants.DEFAULT_TRUST_ANCHOR) .dnsServer(InetAddress.getByName("1.2.3.4")) .introspected(true) .observer(this) .checkConfiguration(true); this.discovery.isDnsSecValid(new Fqdn("google.coma")); Assert.fail("Expected a Lookup Error: non-existing Resolver"); } catch (ConfigurationException ex) { Assert.fail("Expected correct configuration, not " + ex.toString()); } catch (UnknownHostException ex) { Assert.fail("Expected correct retrieval of localhost, not " + ex.toString()); } catch (LookupException ex) { Assert.assertTrue(true); } }
@Test public void checkDnsSecError() { try { this.discovery = new DnsServicesDiscovery(); this.discovery.dnsSecDomain(Constants.DEFAULT_DNSSEC_DOMAIN) .trustAnchorDefault(Constants.DEFAULT_TRUST_ANCHOR) .dnsServer(InetAddress.getByName(DNS_RESOLVER)) .introspected(true) .observer(this) .checkConfiguration(true); this.discovery.isDnsSecValid(new Fqdn(BAD_SERVICE_DOMAIN)); Assert.fail("Expected DNSSEC validation failure"); } catch (ConfigurationException ex) { Assert.fail("Expected correct configuration, not " + ex.toString()); } catch (UnknownHostException ex) { Assert.fail("Expected correct retrieval of localhost, not " + ex.toString()); } catch (LookupException ex) { Assert.assertTrue(true); } }
@Test public void checkDnsSecErrorNonExistentDNS() { try { this.discovery = new DnsServicesDiscovery(); this.discovery.dnsSecDomain(Constants.DEFAULT_DNSSEC_DOMAIN) .trustAnchorDefault(Constants.DEFAULT_TRUST_ANCHOR) .dnsServer(InetAddress.getByName("127.1.1.1")) .introspected(true) .observer(this) .checkConfiguration(true); this.discovery.isDnsSecValid(new Fqdn("google.com")); Assert.fail("Expected DNSSEC validation failure"); } catch (ConfigurationException ex) { Assert.fail("Expected correct configuration, not " + ex.toString()); } catch (UnknownHostException ex) { Assert.fail("Expected correct retrieval of localhost, not " + ex.toString()); } catch (LookupException ex) { Assert.assertTrue(true); } }