diff --git a/build.xml b/build.xml index f462cdf1a..ac4e37006 100644 --- a/build.xml +++ b/build.xml @@ -888,7 +888,8 @@ + prefix="net/java/sip/communicator/util"> + + + + + + + + + + domain is not a valid domain name. + * @throws DnssecException when a DNSSEC validation failure occurred. */ public static SRVRecord[] getSRVRecords(String domain) - throws ParseException + throws ParseException, DnssecException { Record[] records = null; try @@ -596,6 +609,10 @@ public static SRVRecord[] getSRVRecords(String domain) logger.error("Failed to parse domain=" + domain, tpe); throw new ParseException(tpe.getMessage(), 0); } + catch(DnssecRuntimeException e) + { + throw new DnssecException(e); + } if (records == null) { return null; @@ -644,11 +661,12 @@ public int compare(SRVRecord obj1, SRVRecord obj2) * @return the first InetSocketAddress containing records returned by the * DNS server - address and port . * @throws ParseException if domain is not a valid domain name. + * @throws DnssecException when a DNSSEC validation failure occurred. */ public static SRVRecord getSRVRecord(String service, String proto, String domain) - throws ParseException + throws ParseException, DnssecException { SRVRecord[] records = getSRVRecords("_" + service + "._" + proto @@ -672,11 +690,12 @@ public static SRVRecord getSRVRecord(String service, * @return the InetSocketAddress[] containing records returned by the * DNS server - address and port . * @throws ParseException if domain is not a valid domain name. + * @throws DnssecException when a DNSSEC validation failure occurred. */ public static SRVRecord[] getSRVRecords(String service, String proto, String domain) - throws ParseException + throws ParseException, DnssecException { SRVRecord[] records = getSRVRecords("_" + service + "._" + proto @@ -698,9 +717,10 @@ public static SRVRecord[] getSRVRecords(String service, * @return an array with the values or null if no records found. * * @throws ParseException if domain is not a valid domain name. + * @throws DnssecException when a DNSSEC validation failure occurred. */ public static String[][] getNAPTRRecords(String domain) - throws ParseException + throws ParseException, DnssecException { Record[] records = null; try @@ -713,6 +733,10 @@ public static String[][] getNAPTRRecords(String domain) logger.error("Failed to parse domain="+domain, tpe); throw new ParseException(tpe.getMessage(), 0); } + catch(DnssecRuntimeException e) + { + throw new DnssecException(e); + } if (records == null) { @@ -849,9 +873,10 @@ public static InetAddress getInetAddress(String hostAddress) * @return an array of InetSocketAddress containing records returned by the * DNS server - address and port . * @throws ParseException if domain is not a valid domain name. + * @throws DnssecException when a DNSSEC validation failure occurred. */ public static InetSocketAddress[] getAandAAAARecords(String domain, int port) - throws ParseException + throws ParseException, DnssecException { byte[] address = null; if((address = strToIPv4(domain)) != null @@ -889,7 +914,15 @@ public static InetSocketAddress[] getAandAAAARecords(String domain, int port) logger.error("Failed to parse domain <" + domain + ">", tpe); throw new ParseException(tpe.getMessage(), 0); } - Record[] records = lookup.run(); + Record[] records = null; + try + { + records = lookup.run(); + } + catch(DnssecRuntimeException e) + { + throw new DnssecException(e); + } if(records != null) { for(Record r : records) @@ -931,9 +964,10 @@ public static InetSocketAddress[] getAandAAAARecords(String domain, int port) * @return an array of InetSocketAddress containing records returned by the * DNS server - address and port . * @throws ParseException if domain is not a valid domain name. + * @throws DnssecException when a DNSSEC validation failure occurred. */ public static InetSocketAddress getARecord(String domain, int port) - throws ParseException + throws ParseException, DnssecException { byte[] address; if((address = strToIPv4(domain)) != null) @@ -967,14 +1001,26 @@ public static InetSocketAddress getARecord(String domain, int port) logger.error("Failed to parse domain="+domain, tpe); throw new ParseException(tpe.getMessage(), 0); } + catch(DnssecRuntimeException e) + { + throw new DnssecException(e); + } if (records != null && records.length > 0) { if(logger.isTraceEnabled()) logger.trace("A record for " + domain + "=" + ((ARecord)records[0]).getAddress()); - return new InetSocketAddress( - ((ARecord)records[0]).getAddress(), - port); + try + { + return new InetSocketAddress( + InetAddress.getByAddress(domain, + ((ARecord)records[0]).getAddress().getAddress()), + port); + } + catch (UnknownHostException e) + { + return null; + } } else { @@ -992,9 +1038,10 @@ public static InetSocketAddress getARecord(String domain, int port) * @return an array of InetSocketAddress containing records returned by the * DNS server - address and port . * @throws ParseException if domain is not a valid domain name. + * @throws DnssecException */ public static InetSocketAddress getAAAARecord(String domain, int port) - throws ParseException + throws ParseException, DnssecException { byte[] address; if((address = strToIPv6(domain)) != null) @@ -1028,14 +1075,26 @@ public static InetSocketAddress getAAAARecord(String domain, int port) logger.error("Failed to parse domain="+domain, tpe); throw new ParseException(tpe.getMessage(), 0); } + catch(DnssecRuntimeException e) + { + throw new DnssecException(e); + } if (records != null && records.length > 0) { if(logger.isTraceEnabled()) logger.trace("AAAA record for " + domain + "=" + ((AAAARecord)records[0]).getAddress()); - return new InetSocketAddress( - ((AAAARecord)records[0]).getAddress(), - port); + try + { + return new InetSocketAddress( + InetAddress.getByAddress(domain, + ((AAAARecord)records[0]).getAddress().getAddress()), + port); + } + catch (UnknownHostException e) + { + return null; + } } else { @@ -1155,7 +1214,7 @@ private static boolean isMappedIPv4Addr(byte[] address) /** * Creates a new {@link Lookup} instance using our own {@link - * ParallelResolver}. + * ParallelResolver} if it is enabled and DNSSEC is not active. * * @param domain the domain we will be resolving * @param type the type of the record we will be trying to obtain. @@ -1178,6 +1237,15 @@ private static Lookup createLookup(String domain, int type) .addNetworkConfigurationChangeListener(netListener); } + // make domain name absolute if requested + if(UtilActivator.getConfigurationService().getBoolean( + PNAME_DNS_ALWAYS_ABSOLUTE, + PDEFAULT_DNS_ALWAYS_ABSOLUTE)) + { + if(!Name.fromString(domain).isAbsolute()) + domain = domain + "."; + } + Lookup lookup = new Lookup(domain, type); if(logger.isTraceEnabled()) @@ -1194,8 +1262,14 @@ private static Lookup createLookup(String domain, int type) if(!UtilActivator.getConfigurationService() .getBoolean(PNAME_BACKUP_RESOLVER_ENABLED, - PDEFAULT_BACKUP_RESOLVER_ENABLED)) + PDEFAULT_BACKUP_RESOLVER_ENABLED) + || UtilActivator.getConfigurationService().getBoolean( + DnsUtilActivator.PNAME_DNSSEC_RESOLVER_ENABLED, + DnsUtilActivator.PDEFAULT_DNSSEC_RESOLVER_ENABLED + )) + { return lookup; + } //Initiate our global parallel resolver if this is our first ever //DNS query. The lock here is heavy but necessary as a) the config @@ -1340,7 +1414,7 @@ public static void reloadDnsResolverConfig() { // reread system dns configuration ResolverConfig.refresh(); - Lookup.refreshDefault(); + DnsUtilActivator.refreshResolver(); if(parallelResolver instanceof ParallelResolver) { //needs a separate lock object because the parallelResolver could diff --git a/src/net/java/sip/communicator/util/util.manifest.mf b/src/net/java/sip/communicator/util/util.manifest.mf index 352c02b6b..1c73e3e39 100644 --- a/src/net/java/sip/communicator/util/util.manifest.mf +++ b/src/net/java/sip/communicator/util/util.manifest.mf @@ -29,6 +29,7 @@ Import-Package: org.xml.sax, javax.security.auth.x500, net.java.sip.communicator.util.xml, net.java.sip.communicator.util, + net.java.sip.communicator.util.dns, net.java.sip.communicator.service.resources, net.java.sip.communicator.service.keybindings, net.java.sip.communicator.service.netaddr, @@ -47,6 +48,5 @@ Export-Package: net.java.sip.communicator.util.xml, net.java.sip.communicator.util.swing.transparent, net.java.sip.communicator.util.swing.border, net.java.sip.communicator.util, - net.java.sip.communicator.util.dns, net.java.sip.communicator.util.skin, net.java.sip.communicator.util.launchutils diff --git a/test/net/java/sip/communicator/slick/protocol/sip/TestAutoProxyDetection.java b/test/net/java/sip/communicator/slick/protocol/sip/TestAutoProxyDetection.java index 3b1b76f18..9469f5c28 100644 --- a/test/net/java/sip/communicator/slick/protocol/sip/TestAutoProxyDetection.java +++ b/test/net/java/sip/communicator/slick/protocol/sip/TestAutoProxyDetection.java @@ -16,6 +16,7 @@ import net.java.sip.communicator.impl.protocol.sip.SipAccountID; import net.java.sip.communicator.impl.protocol.sip.net.AutoProxyConnection; import net.java.sip.communicator.util.SRVRecord; +import net.java.sip.communicator.util.dns.DnssecException; import static net.java.sip.communicator.service.protocol.ProtocolProviderFactory.*; import junit.framework.TestCase; @@ -103,7 +104,7 @@ public void setUp() a4 = new InetSocketAddress(ia4, 5063); } - private void prepareOneNaptrOneSrv() throws ParseException + private void prepareOneNaptrOneSrv() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{ {"0", "udp", "_sip._udp." + DOMAIN} @@ -112,7 +113,7 @@ private void prepareOneNaptrOneSrv() throws ParseException .andReturn(new SRVRecord[]{ srv1 }); } - private void prepareOneNaptrTwoSrv() throws ParseException + private void prepareOneNaptrTwoSrv() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{ {"0", "udp", "_sip._udp." + DOMAIN} @@ -121,7 +122,7 @@ private void prepareOneNaptrTwoSrv() throws ParseException .andReturn(new SRVRecord[]{ srv1, srv2 }); } - public void testOneNaptrNoSrv() throws ParseException + public void testOneNaptrNoSrv() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{ {"0", "udp", "_sip._udp." + DOMAIN} @@ -133,7 +134,7 @@ public void testOneNaptrNoSrv() throws ParseException verify(account, nu); } - public void testOneNaptrOneSrvOneA() throws ParseException + public void testOneNaptrOneSrvOneA() throws ParseException, DnssecException { prepareOneNaptrOneSrv(); expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060)) @@ -147,7 +148,7 @@ public void testOneNaptrOneSrvOneA() throws ParseException verify(account, nu, srv1); } - public void testOneNaptrOneSrvTwoA() throws ParseException + public void testOneNaptrOneSrvTwoA() throws ParseException, DnssecException { prepareOneNaptrOneSrv(); expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060)) @@ -166,7 +167,7 @@ public void testOneNaptrOneSrvTwoA() throws ParseException //----------------------- - public void testOneNaptrTwoSrvOneA() throws ParseException + public void testOneNaptrTwoSrvOneA() throws ParseException, DnssecException { prepareOneNaptrTwoSrv(); expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060)) @@ -185,7 +186,7 @@ public void testOneNaptrTwoSrvOneA() throws ParseException verify(account, nu, srv1, srv2); } - public void testOneNaptrTwoSrvTwoA() throws ParseException + public void testOneNaptrTwoSrvTwoA() throws ParseException, DnssecException { prepareOneNaptrTwoSrv(); expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060)) @@ -215,7 +216,9 @@ public void testOneNaptrTwoSrvTwoA() throws ParseException //------------------- - public void testThreeNaptrOneSrvEachOneAEach() throws ParseException + public void testThreeNaptrOneSrvEachOneAEach() + throws ParseException, + DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{ {"0", "udp", "_sip._udp." + DOMAIN}, @@ -254,7 +257,7 @@ public void testThreeNaptrOneSrvEachOneAEach() throws ParseException //----------------------- - public void testNoSrvOneA() throws ParseException + public void testNoSrvOneA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null); @@ -272,7 +275,7 @@ public void testNoSrvOneA() throws ParseException verify(account, nu); } - public void testOneSrvOneA() throws ParseException + public void testOneSrvOneA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null); @@ -291,7 +294,7 @@ public void testOneSrvOneA() throws ParseException verify(account, nu, srv1); } - public void testOneSrvTwoA() throws ParseException + public void testOneSrvTwoA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null); @@ -314,7 +317,7 @@ public void testOneSrvTwoA() throws ParseException verify(account, nu, srv1); } - public void testTwoSrvOneA() throws ParseException + public void testTwoSrvOneA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)) @@ -342,7 +345,7 @@ public void testTwoSrvOneA() throws ParseException //---------------------- - public void testNoA() throws ParseException + public void testNoA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null); @@ -357,7 +360,7 @@ public void testNoA() throws ParseException verify(account, nu); } - public void testOneA() throws ParseException + public void testOneA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null); @@ -375,7 +378,7 @@ public void testOneA() throws ParseException verify(account, nu); } - public void testTwoA() throws ParseException + public void testTwoA() throws ParseException, DnssecException { expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{}); expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null); @@ -397,7 +400,9 @@ public void testTwoA() throws ParseException verify(account, nu); } - public void testNotReturningSameAddressTwice() throws ParseException + public void testNotReturningSameAddressTwice() + throws ParseException, + DnssecException { expect(srv1.getTarget()).andReturn("proxy1."+DOMAIN); expect(srv1.getPort()).andReturn(5060);