diff --git a/.travis.yml b/.travis.yml
index 16d81cffc..330534561 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
language: android
android:
components:
- - android-8
+ - android-9
jdk:
- oraclejdk8
sudo: false
diff --git a/build.gradle b/build.gradle
index ac2428ed7..6ccc06ace 100644
--- a/build.gradle
+++ b/build.gradle
@@ -238,6 +238,7 @@ task javadocAll(type: Javadoc) {
options.links = [
"https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/",
"http://jxmpp.org/$jxmppVersion/javadoc/",
+ "https://minidns.org/releases/$miniDnsVersion/javadoc/",
] as String[]
}
@@ -430,7 +431,7 @@ subprojects {
configure (androidProjects) {
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
- signature "net.sf.androidscents.signature:android-api-level-${smackMinAndroidSdk}:2.2_r3@signature"
+ signature "net.sf.androidscents.signature:android-api-level-${smackMinAndroidSdk}:2.3.1_r2@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
diff --git a/smack-core/build.gradle b/smack-core/build.gradle
index 6d5c5267c..cb58736b2 100644
--- a/smack-core/build.gradle
+++ b/smack-core/build.gradle
@@ -10,6 +10,7 @@ dependencies {
compile 'xpp3:xpp3:1.1.4c'
compile "org.jxmpp:jxmpp-core:$jxmppVersion"
compile "org.jxmpp:jxmpp-jid:$jxmppVersion"
+ compile "org.minidns:minidns-core:$miniDnsVersion"
testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
testCompile "junit:junit:$junitVersion"
testCompile 'xmlunit:xmlunit:1.5'
@@ -45,4 +46,4 @@ jar {
manifest {
instruction 'DynamicImport-Package', '*'
}
-}
\ No newline at end of file
+}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
index b1b8fb208..302efbc93 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
@@ -93,6 +93,7 @@ import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.util.XmppStringUtils;
+import org.minidns.dnsname.DNSName;
import org.xmlpull.v1.XmlPullParser;
@@ -613,7 +614,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
} else {
// N.B.: Important to use config.serviceName and not AbstractXMPPConnection.serviceName
- hostAddresses = DNSUtil.resolveXMPPServiceDomain(config.getXMPPServiceDomain().toString(), failedAddresses, config.getDnssecMode());
+ DNSName dnsName = DNSName.from(config.getXMPPServiceDomain());
+ hostAddresses = DNSUtil.resolveXMPPServiceDomain(dnsName, failedAddresses, config.getDnssecMode());
}
// Either the populated host addresses are not empty *or* there must be at least one failed address.
assert (!hostAddresses.isEmpty() || !failedAddresses.isEmpty());
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
index da888e044..854bb812e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2003-2007 Jive Software, 2017 Florian Schmaus.
+ * Copyright 2003-2007 Jive Software, 2017-2018 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
+import org.minidns.dnsname.DNSName;
/**
* Configuration to use while establishing the connection to the server.
@@ -66,7 +67,7 @@ public abstract class ConnectionConfiguration {
protected final DomainBareJid xmppServiceDomain;
protected final InetAddress hostAddress;
- protected final String host;
+ protected final DNSName host;
protected final int port;
private final String keystorePath;
@@ -506,7 +507,7 @@ public abstract class ConnectionConfiguration {
private SocketFactory socketFactory;
private DomainBareJid xmppServiceDomain;
private InetAddress hostAddress;
- private String host;
+ private DNSName host;
private int port = 5222;
private boolean allowEmptyOrNullUsername = false;
private boolean saslMechanismsSealed;
@@ -624,6 +625,19 @@ public abstract class ConnectionConfiguration {
* @return a reference to this builder.
*/
public B setHost(String host) {
+ DNSName hostDnsName = DNSName.from(host);
+ return setHost(hostDnsName);
+ }
+
+ /**
+ * Set the name of the host providing the XMPP service. Note that this method does only allow DNS names and not
+ * IP addresses. Use {@link #setHostAddress(InetAddress)} if you want to explicitly set the Internet address of
+ * the host providing the XMPP service.
+ *
+ * @param host the DNS name of the host providing the XMPP service.
+ * @return a reference to this builder.
+ */
+ public B setHost(DNSName host) {
this.host = host;
return getThis();
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
index 98f53a7f8..084290536 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2003-2005 Jive Software, 2016 Florian Schmaus.
+ * Copyright 2003-2005 Jive Software, 2016-2018 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,8 @@ import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.util.dns.SRVRecord;
import org.jivesoftware.smack.util.dns.SmackDaneProvider;
+import org.minidns.dnsname.DNSName;
+
/**
* Utility class to perform DNS lookups for XMPP services.
*
@@ -39,27 +41,13 @@ import org.jivesoftware.smack.util.dns.SmackDaneProvider;
*/
public class DNSUtil {
+ public static final String XMPP_CLIENT_DNS_SRV_PREFIX = "_xmpp-client._tcp";
+ public static final String XMPP_SERVER_DNS_SRV_PREFIX = "_xmpp-server._tcp";
+
private static final Logger LOGGER = Logger.getLogger(DNSUtil.class.getName());
private static DNSResolver dnsResolver = null;
private static SmackDaneProvider daneProvider;
- /**
- * International Domain Name transformer.
- *
- * Used to transform Unicode representations of the Domain Name to ASCII in
- * order to perform a DNS request with the ASCII representation.
- * 'java.net.IDN' is available since Android API 9, but as long as Smack
- * requires API 8, we are going to need this. This part is going to get
- * removed once Smack depends on Android API 9 or higher.
- *
- */
- private static StringTransformer idnaTransformer = new StringTransformer() {
- @Override
- public String transform(String string) {
- return string;
- }
- };
-
/**
* Set the DNS resolver that should be used to perform DNS lookups.
*
@@ -96,24 +84,16 @@ public class DNSUtil {
return daneProvider;
}
- /**
- * Set the IDNA (Internationalizing Domain Names in Applications, RFC 3490) transformer.
- *
- * You usually want to wrap 'java.net.IDN.toASCII()' into a StringTransformer here.
- *
- * @param idnaTransformer
- */
- public static void setIdnaTransformer(StringTransformer idnaTransformer) {
- if (idnaTransformer == null) {
- throw new NullPointerException();
- }
- DNSUtil.idnaTransformer = idnaTransformer;
- }
-
- private enum DomainType {
- Server,
- Client,
+ @SuppressWarnings("ImmutableEnumChecker")
+ enum DomainType {
+ server(XMPP_SERVER_DNS_SRV_PREFIX),
+ client(XMPP_CLIENT_DNS_SRV_PREFIX),
;
+ public final DNSName srvPrefix;
+
+ DomainType(String srvPrefixString) {
+ srvPrefix = DNSName.from(srvPrefixString);
+ }
}
/**
@@ -131,10 +111,8 @@ public class DNSUtil {
* @return List of HostAddress, which encompasses the hostname and port that the
* XMPP server can be reached at for the specified domain.
*/
- public static List resolveXMPPServiceDomain(String domain, List failedAddresses, DnssecMode dnssecMode) {
- domain = idnaTransformer.transform(domain);
-
- return resolveDomain(domain, DomainType.Client, failedAddresses, dnssecMode);
+ public static List resolveXMPPServiceDomain(DNSName domain, List failedAddresses, DnssecMode dnssecMode) {
+ return resolveDomain(domain, DomainType.client, failedAddresses, dnssecMode);
}
/**
@@ -152,10 +130,8 @@ public class DNSUtil {
* @return List of HostAddress, which encompasses the hostname and port that the
* XMPP server can be reached at for the specified domain.
*/
- public static List resolveXMPPServerDomain(String domain, List failedAddresses, DnssecMode dnssecMode) {
- domain = idnaTransformer.transform(domain);
-
- return resolveDomain(domain, DomainType.Server, failedAddresses, dnssecMode);
+ public static List resolveXMPPServerDomain(DNSName domain, List failedAddresses, DnssecMode dnssecMode) {
+ return resolveDomain(domain, DomainType.server, failedAddresses, dnssecMode);
}
/**
@@ -165,7 +141,7 @@ public class DNSUtil {
* @param failedAddresses a list that will be populated with host addresses that failed to resolve.
* @return a list of resolver host addresses for this domain.
*/
- private static List resolveDomain(String domain, DomainType domainType,
+ private static List resolveDomain(DNSName domain, DomainType domainType,
List failedAddresses, DnssecMode dnssecMode) {
if (dnsResolver == null) {
throw new IllegalStateException("No DNS Resolver active in Smack");
@@ -174,17 +150,7 @@ public class DNSUtil {
List addresses = new ArrayList();
// Step one: Do SRV lookups
- String srvDomain;
- switch (domainType) {
- case Server:
- srvDomain = "_xmpp-server._tcp." + domain;
- break;
- case Client:
- srvDomain = "_xmpp-client._tcp." + domain;
- break;
- default:
- throw new AssertionError();
- }
+ DNSName srvDomain = DNSName.from(domainType.srvPrefix, domain);
List srvRecords = dnsResolver.lookupSRVRecords(srvDomain, failedAddresses, dnssecMode);
if (srvRecords != null && !srvRecords.isEmpty()) {
@@ -202,10 +168,10 @@ public class DNSUtil {
int defaultPort = -1;
switch (domainType) {
- case Client:
+ case client:
defaultPort = 5222;
break;
- case Server:
+ case server:
defaultPort = 5269;
break;
}
@@ -229,7 +195,7 @@ public class DNSUtil {
private static List sortSRVRecords(List records) {
// RFC 2782, Usage rules: "If there is precisely one SRV RR, and its Target is "."
// (the root domain), abort."
- if (records.size() == 1 && records.get(0).getFQDN().equals("."))
+ if (records.size() == 1 && records.get(0).getFQDN().isRootLabel())
return Collections.emptyList();
// sorting the records improves the performance of the bisection later
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/IpAddressUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/IpAddressUtil.java
deleted file mode 100644
index 8d1ad7b78..000000000
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/IpAddressUtil.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- *
- * Copyright 2015 Florian Schmaus
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jivesoftware.smack.util;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class IpAddressUtil {
-
- private static final Pattern IPV4_PATTERN = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$");
-
- public static boolean isIPv4LiteralAddress(String string) {
- Matcher matcher = IPV4_PATTERN.matcher(string);
- if (!matcher.matches()) {
- return false;
- }
-
- assert matcher.groupCount() == 4;
-
- for (int i = 1; i <= 4; i++) {
- String ipSegment = matcher.group(i);
- int ipSegmentInt;
- try {
- ipSegmentInt = Integer.valueOf(ipSegment);
- } catch (NumberFormatException e) {
- throw new AssertionError(e);
- }
- if (ipSegmentInt > 255) {
- return false;
- }
- }
- return true;
- }
-
- public static boolean isIPv6LiteralAddress(final String string) {
- final String[] octets = string.split(":");
- if (octets.length != 8) {
- return false;
- }
- // TODO handle compressed zeros and validate octets
- return true;
- }
-
- public static boolean isIpAddress(String string) {
- return isIPv4LiteralAddress(string) || isIPv6LiteralAddress(string);
- }
-}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
index 5fb73ff5f..0744d3f1d 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2013-2017 Florian Schmaus
+ * Copyright 2013-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode;
+import org.minidns.dnsname.DNSName;
+
/**
* Implementations of this interface define a class that is capable of resolving DNS addresses.
*
@@ -46,14 +48,14 @@ public abstract class DNSResolver {
* @param dnssecMode security mode.
* @return The list of SRV records mapped to the service name.
*/
- public final List lookupSRVRecords(String name, List failedAddresses, DnssecMode dnssecMode) {
+ public final List lookupSRVRecords(DNSName name, List failedAddresses, DnssecMode dnssecMode) {
checkIfDnssecRequestedAndSupported(dnssecMode);
return lookupSRVRecords0(name, failedAddresses, dnssecMode);
}
- protected abstract List lookupSRVRecords0(String name, List failedAddresses, DnssecMode dnssecMode);
+ protected abstract List lookupSRVRecords0(DNSName name, List failedAddresses, DnssecMode dnssecMode);
- public final HostAddress lookupHostAddress(String name, int port, List failedAddresses, DnssecMode dnssecMode) {
+ public final HostAddress lookupHostAddress(DNSName name, int port, List failedAddresses, DnssecMode dnssecMode) {
checkIfDnssecRequestedAndSupported(dnssecMode);
List inetAddresses = lookupHostAddress0(name, failedAddresses, dnssecMode);
if (inetAddresses == null || inetAddresses.isEmpty()) {
@@ -76,7 +78,7 @@ public abstract class DNSResolver {
* @param dnssecMode the selected DNSSEC mode
* @return A list, either empty or non-empty, or null
*/
- protected List lookupHostAddress0(String name, List failedAddresses, DnssecMode dnssecMode) {
+ protected List lookupHostAddress0(DNSName name, List failedAddresses, DnssecMode dnssecMode) {
// Default implementation of a DNS name lookup for A/AAAA records. It is assumed that this method does never
// support DNSSEC. Subclasses are free to override this method.
if (dnssecMode != DnssecMode.disabled) {
@@ -85,7 +87,7 @@ public abstract class DNSResolver {
InetAddress[] inetAddressArray;
try {
- inetAddressArray = InetAddress.getAllByName(name);
+ inetAddressArray = InetAddress.getAllByName(name.toString());
} catch (UnknownHostException e) {
failedAddresses.add(new HostAddress(name, e));
return null;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java
index 0c332ccc0..da528166e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright © 2013-2017 Florian Schmaus
+ * Copyright © 2013-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,11 @@ import java.util.Map;
import java.util.Map.Entry;
import org.jivesoftware.smack.SmackException.ConnectionException;
-import org.jivesoftware.smack.util.StringUtils;
+
+import org.minidns.dnsname.DNSName;
public class HostAddress {
- private final String fqdn;
+ private final DNSName fqdn;
private final int port;
private final Map exceptions = new LinkedHashMap<>();
private final List inetAddresses;
@@ -41,16 +42,11 @@ public class HostAddress {
* @param inetAddresses list of addresses.
* @throws IllegalArgumentException If the port is out of valid range (0 - 65535).
*/
- public HostAddress(String fqdn, int port, List inetAddresses) {
+ public HostAddress(DNSName fqdn, int port, List inetAddresses) {
if (port < 0 || port > 65535)
throw new IllegalArgumentException(
"Port must be a 16-bit unsigned integer (i.e. between 0-65535. Port was: " + port);
- if (StringUtils.isNotEmpty(fqdn) && fqdn.charAt(fqdn.length() - 1) == '.') {
- this.fqdn = fqdn.substring(0, fqdn.length() - 1);
- }
- else {
- this.fqdn = fqdn;
- }
+ this.fqdn = fqdn;
this.port = port;
if (inetAddresses.isEmpty()) {
throw new IllegalArgumentException("Must provide at least one InetAddress");
@@ -69,7 +65,7 @@ public class HostAddress {
* @param fqdn the domain name of the host.
* @param e the exception causing the failure.
*/
- public HostAddress(String fqdn, Exception e) {
+ public HostAddress(DNSName fqdn, Exception e) {
this.fqdn = fqdn;
this.port = 5222;
inetAddresses = Collections.emptyList();
@@ -78,7 +74,7 @@ public class HostAddress {
public String getHost() {
if (fqdn != null) {
- return fqdn;
+ return fqdn.toString();
}
// In this case, the HostAddress(int, InetAddress) constructor must been used. We have no FQDN. And
@@ -92,7 +88,7 @@ public class HostAddress {
*
* @return the fully qualified domain name or null
*/
- public String getFQDN() {
+ public DNSName getFQDN() {
return fqdn;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java
index d81aff018..c134570e2 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2013-2017 Florian Schmaus
+ * Copyright 2013-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import java.util.List;
import org.jivesoftware.smack.util.StringUtils;
+import org.minidns.dnsname.DNSName;
+
/**
* A DNS SRV RR.
*
@@ -44,7 +46,7 @@ public class SRVRecord extends HostAddress implements Comparable {
* @param inetAddresses list of addresses.
* @throws IllegalArgumentException fqdn is null or any other field is not in valid range (0-65535).
*/
- public SRVRecord(String fqdn, int port, int priority, int weight, List inetAddresses) {
+ public SRVRecord(DNSName fqdn, int port, int priority, int weight, List inetAddresses) {
super(fqdn, port, inetAddresses);
StringUtils.requireNotNullOrEmpty(fqdn, "The FQDN must not be null");
if (weight < 0 || weight > 65535)
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java b/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java
index d42770547..fb9c52a0a 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright © 2014 Florian Schmaus
+ * Copyright © 2014-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import org.jivesoftware.smack.SmackException.ConnectionException;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.junit.Test;
+import org.minidns.dnsname.DNSName;
public class SmackExceptionTest {
@@ -35,15 +36,15 @@ public class SmackExceptionTest {
public void testConnectionException() throws UnknownHostException {
List failedAddresses = new LinkedList();
- String host = "foo.bar.example";
- InetAddress inetAddress = InetAddress.getByAddress(host, new byte[] { 0, 0, 0, 0 });
+ DNSName host = DNSName.from("foo.bar.example");
+ InetAddress inetAddress = InetAddress.getByAddress(host.toString(), new byte[] { 0, 0, 0, 0 });
List inetAddresses = Collections.singletonList(inetAddress);
HostAddress hostAddress = new HostAddress(host, 1234, inetAddresses);
hostAddress.setException(new Exception("Failed for some reason"));
failedAddresses.add(hostAddress);
- host = "barz.example";
- inetAddress = InetAddress.getByAddress(host, new byte[] { 0, 0, 0, 0 });
+ host = DNSName.from("barz.example");
+ inetAddress = InetAddress.getByAddress(host.toString(), new byte[] { 0, 0, 0, 0 });
inetAddresses = Collections.singletonList(inetAddress);
hostAddress = new HostAddress(host, 5678, inetAddresses);
hostAddress.setException(new Exception("Failed for some other reason"));
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/DnsUtilTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/DnsUtilTest.java
new file mode 100644
index 000000000..7e7038118
--- /dev/null
+++ b/smack-core/src/test/java/org/jivesoftware/smack/util/DnsUtilTest.java
@@ -0,0 +1,36 @@
+/**
+ *
+ * Copyright 2018 Florian Schmaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smack.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jivesoftware.smack.util.DNSUtil.DomainType;
+
+import org.junit.Test;
+
+public class DnsUtilTest {
+
+ @Test
+ public void simpleDomainTypeTest() {
+ DomainType client = DomainType.client;
+ assertEquals(DNSUtil.XMPP_CLIENT_DNS_SRV_PREFIX, client.srvPrefix.ace);
+
+ DomainType server = DomainType.server;
+ assertEquals(DNSUtil.XMPP_SERVER_DNS_SRV_PREFIX, server.srvPrefix.ace);
+ }
+
+}
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/IpAddressUtilTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/IpAddressUtilTest.java
deleted file mode 100644
index 575c71714..000000000
--- a/smack-core/src/test/java/org/jivesoftware/smack/util/IpAddressUtilTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- *
- * Copyright 2017 Florian Schmaus
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jivesoftware.smack.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class IpAddressUtilTest {
-
- @Test
- public void isIpV4AddressTest() {
- String ipv4 = "122.20.221.11";
- boolean isIpV4 = IpAddressUtil.isIPv4LiteralAddress(ipv4);
- assertTrue(isIpV4);
- }
-
- @Test
- public void isInvalidIpV4AddressTest() {
- String ipv4 = "122.20.221.11.1";
- boolean isIpV4 = IpAddressUtil.isIPv4LiteralAddress(ipv4);
- assertFalse(isIpV4);
- }
-
- @Test
- public void isInvalidIpV4AddressTest2() {
- String ipv4 = "122.20.256.11";
- boolean isIpV4 = IpAddressUtil.isIPv4LiteralAddress(ipv4);
- assertFalse(isIpV4);
- }
-}
diff --git a/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java b/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java
index a3add870c..8fbb8c644 100644
--- a/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java
+++ b/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2014-2015 Florian Schmaus
+ * Copyright 2014-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@ import java.util.List;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.initializer.SmackInitializer;
-import org.jivesoftware.smack.util.DNSUtil;
-import org.jivesoftware.smack.util.StringTransformer;
import org.jivesoftware.smack.util.SystemUtil;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smack.util.stringencoder.Base64UrlSafeEncoder;
@@ -43,12 +41,6 @@ public class Java7SmackInitializer implements SmackInitializer {
SmackConfiguration.setDefaultHostnameVerifier(new XmppHostnameVerifier());
Base64.setEncoder(Java7Base64Encoder.getInstance());
Base64UrlSafeEncoder.setEncoder(Java7Base64UrlSafeEncoder.getInstance());
- DNSUtil.setIdnaTransformer(new StringTransformer() {
- @Override
- public String transform(String string) {
- return java.net.IDN.toASCII(string);
- }
- });
return null;
}
diff --git a/smack-java7/src/main/java/org/jivesoftware/smack/java7/XmppHostnameVerifier.java b/smack-java7/src/main/java/org/jivesoftware/smack/java7/XmppHostnameVerifier.java
index 34a5abd4f..6606bce04 100644
--- a/smack-java7/src/main/java/org/jivesoftware/smack/java7/XmppHostnameVerifier.java
+++ b/smack-java7/src/main/java/org/jivesoftware/smack/java7/XmppHostnameVerifier.java
@@ -38,7 +38,7 @@ import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.security.auth.kerberos.KerberosPrincipal;
-import org.jivesoftware.smack.util.IpAddressUtil;
+import org.minidns.util.InetAddressUtil;
/**
* HostnameVerifier implementation for XMPP. Verifies a given name, the 'hostname' argument, which
@@ -98,7 +98,7 @@ public class XmppHostnameVerifier implements HostnameVerifier {
}
private static void match(String name, X509Certificate cert) throws CertificateException {
- if (IpAddressUtil.isIpAddress(name)) {
+ if (InetAddressUtil.isIpAddress(name)) {
matchIp(name, cert);
}
else {
diff --git a/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java b/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java
index 6115a4aa3..aad3f4613 100644
--- a/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java
+++ b/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2013-2017 Florian Schmaus
+ * Copyright 2013-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.jivesoftware.smack.util.dns.DNSResolver;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.util.dns.SRVRecord;
+import org.minidns.dnsname.DNSName;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
@@ -49,12 +50,12 @@ public class DNSJavaResolver extends DNSResolver implements SmackInitializer {
}
@Override
- protected List lookupSRVRecords0(String name, List failedAddresses, DnssecMode dnssecMode) {
+ protected List lookupSRVRecords0(DNSName name, List failedAddresses, DnssecMode dnssecMode) {
List res = new ArrayList<>();
Lookup lookup;
try {
- lookup = new Lookup(name, Type.SRV);
+ lookup = new Lookup(name.ace, Type.SRV);
}
catch (TextParseException e) {
throw new IllegalStateException(e);
@@ -67,7 +68,7 @@ public class DNSJavaResolver extends DNSResolver implements SmackInitializer {
for (Record record : recs) {
org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
if (srvRecord != null && srvRecord.getTarget() != null) {
- String host = srvRecord.getTarget().toString();
+ DNSName host = DNSName.from(srvRecord.getTarget().toString());
int port = srvRecord.getPort();
int priority = srvRecord.getPriority();
int weight = srvRecord.getWeight();
diff --git a/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java b/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java
index 335333f5c..c0e23b403 100644
--- a/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java
+++ b/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2013-2017 Florian Schmaus
+ * Copyright 2013-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,8 @@ import org.jivesoftware.smack.util.dns.DNSResolver;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.util.dns.SRVRecord;
+import org.minidns.dnsname.DNSName;
+
/**
* A DNS resolver (mostly for SRV records), which makes use of the API provided in the javax.* namespace.
*
@@ -81,12 +83,12 @@ public class JavaxResolver extends DNSResolver implements SmackInitializer {
}
@Override
- protected List lookupSRVRecords0(String name, List failedAddresses, DnssecMode dnssecMode) {
+ protected List lookupSRVRecords0(DNSName name, List failedAddresses, DnssecMode dnssecMode) {
List res = null;
Attribute srvAttribute;
try {
- Attributes dnsLookup = dirContext.getAttributes(name, new String[] { "SRV" });
+ Attributes dnsLookup = dirContext.getAttributes(name.ace, new String[] { "SRV" });
srvAttribute = dnsLookup.get("SRV");
if (srvAttribute == null)
return null;
@@ -108,7 +110,14 @@ public class JavaxResolver extends DNSResolver implements SmackInitializer {
int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]);
int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 2]);
int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]);
- String host = srvRecordEntries[srvRecordEntries.length - 1];
+ String srvTarget = srvRecordEntries[srvRecordEntries.length - 1];
+ // Strip trailing '.' from srvTarget.
+ // Later MiniDNS version may do the right thing when DNSName.from() is called with a DNS name string
+ // having a trailing dot, so this can possibly be removed in future Smack versions.
+ if (srvTarget.length() > 0 && srvTarget.charAt(srvTarget.length() - 1) == '.') {
+ srvTarget = srvTarget.substring(0, srvTarget.length() - 1);
+ }
+ DNSName host = DNSName.from(srvTarget);
List hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode);
if (shouldContinue(name, host, hostAddresses)) {
diff --git a/smack-resolver-minidns/build.gradle b/smack-resolver-minidns/build.gradle
index a084e3171..627cb3f52 100644
--- a/smack-resolver-minidns/build.gradle
+++ b/smack-resolver-minidns/build.gradle
@@ -5,6 +5,6 @@ javax.naming API (e.g. Android)."""
dependencies {
compile project(path: ':smack-core')
- compile 'de.measite.minidns:minidns-hla:[0.2,0.3)'
+ compile "org.minidns:minidns-hla:$miniDnsVersion"
compile "org.jxmpp:jxmpp-util-cache:$jxmppVersion"
}
diff --git a/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsDaneVerifier.java b/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsDaneVerifier.java
index 5f757f52e..40058304c 100644
--- a/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsDaneVerifier.java
+++ b/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsDaneVerifier.java
@@ -31,8 +31,8 @@ import javax.net.ssl.X509TrustManager;
import org.jivesoftware.smack.util.dns.SmackDaneVerifier;
-import de.measite.minidns.dane.DaneVerifier;
-import de.measite.minidns.dane.ExpectingTrustManager;
+import org.minidns.dane.DaneVerifier;
+import org.minidns.dane.ExpectingTrustManager;
public class MiniDnsDaneVerifier implements SmackDaneVerifier {
private static final Logger LOGGER = Logger.getLogger(MiniDnsDaneVerifier.class.getName());
diff --git a/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java b/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java
index 3aec6ea36..4f13f91ed 100644
--- a/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java
+++ b/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java
@@ -32,15 +32,17 @@ import org.jivesoftware.smack.util.dns.DNSResolver;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.util.dns.SRVRecord;
-import de.measite.minidns.DNSMessage.RESPONSE_CODE;
-import de.measite.minidns.Question;
-import de.measite.minidns.hla.DnssecResolverApi;
-import de.measite.minidns.hla.ResolutionUnsuccessfulException;
-import de.measite.minidns.hla.ResolverApi;
-import de.measite.minidns.hla.ResolverResult;
-import de.measite.minidns.record.A;
-import de.measite.minidns.record.AAAA;
-import de.measite.minidns.record.SRV;
+import org.minidns.dnsmessage.DNSMessage.RESPONSE_CODE;
+import org.minidns.dnsmessage.Question;
+import org.minidns.dnsname.DNSName;
+import org.minidns.hla.DnssecResolverApi;
+import org.minidns.hla.ResolutionUnsuccessfulException;
+import org.minidns.hla.ResolverApi;
+import org.minidns.hla.ResolverResult;
+import org.minidns.hla.SrvResolverResult;
+import org.minidns.record.A;
+import org.minidns.record.AAAA;
+import org.minidns.record.SRV;
/**
@@ -64,12 +66,12 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer {
}
@Override
- protected List lookupSRVRecords0(final String name, List failedAddresses, DnssecMode dnssecMode) {
+ protected List lookupSRVRecords0(final DNSName name, List failedAddresses, DnssecMode dnssecMode) {
final ResolverApi resolver = getResolver(dnssecMode);
- ResolverResult result;
+ SrvResolverResult result;
try {
- result = resolver.resolve(name, SRV.class);
+ result = resolver.resolveSrv(name);
} catch (IOException e) {
failedAddresses.add(new HostAddress(name, e));
return null;
@@ -87,7 +89,7 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer {
List res = new LinkedList<>();
for (SRV srv : result.getAnswers()) {
- String hostname = srv.name.ace;
+ DNSName hostname = srv.target;
List hostAddresses = lookupHostAddress0(hostname, failedAddresses, dnssecMode);
if (shouldContinue(name, hostname, hostAddresses)) {
continue;
@@ -101,7 +103,7 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer {
}
@Override
- protected List lookupHostAddress0(final String name, List failedAddresses, DnssecMode dnssecMode) {
+ protected List lookupHostAddress0(final DNSName name, List failedAddresses, DnssecMode dnssecMode) {
final ResolverApi resolver = getResolver(dnssecMode);
final ResolverResult aResult;
@@ -161,7 +163,7 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer {
for (AAAA aaaa : aaaaResults) {
InetAddress inetAddress;
try {
- inetAddress = InetAddress.getByAddress(name, aaaa.getIp());
+ inetAddress = InetAddress.getByAddress(name.ace, aaaa.getIp());
}
catch (UnknownHostException e) {
continue;
@@ -191,7 +193,7 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer {
}
}
- private static boolean shouldAbortIfNotAuthentic(String name, DnssecMode dnssecMode,
+ private static boolean shouldAbortIfNotAuthentic(DNSName name, DnssecMode dnssecMode,
ResolverResult> result, List failedAddresses) {
switch (dnssecMode) {
case needsDnssec:
diff --git a/version.gradle b/version.gradle
index 8ba7f14f8..7a0aa27bb 100644
--- a/version.gradle
+++ b/version.gradle
@@ -3,6 +3,7 @@ allprojects {
shortVersion = '4.3.0-beta2'
isSnapshot = true
jxmppVersion = '0.6.0'
- smackMinAndroidSdk = 8
+ miniDnsVersion = '0.3.0-alpha1'
+ smackMinAndroidSdk = 9
}
}