- * The JavaDoc of these methods is directly copied from libunbound, licensed as - * follows: - *
- * Copyright (c) 2007, NLnet Labs. All rights reserved. - * - * This software is open source. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the NLNET LABS nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @author Ingo Bauersachs - */ -public class UnboundApi -{ - private static boolean isAvailable; - private static final Object syncRoot = new Object(); - - static - { - tryLoadUnbound(); - } - - /** - * Attempts to load the Unbound native library. When successful, - * {@link #isAvailable()} returns true. - */ - public static void tryLoadUnbound() - { - synchronized(syncRoot) - { - try - { - System.loadLibrary("junbound"); - isAvailable = true; - } - catch(UnsatisfiedLinkError e) - { - isAvailable = false; - } - } - } - - /** - * Indicates whether the Unbound library is loaded. - * @return True when the JNI wrapper could be loaded, false otherwise. - */ - public static boolean isAvailable() - { - return isAvailable; - } - - /** - * Set debug verbosity for the context. Output is directed to stderr. Higher - * debug level gives more output. - * - * @param context context. - * @param level The debug level. - */ - public static native void setDebugLevel(long context, int level); - - /** - * Create a resolving and validation context. - * @return a new context. default initialization. returns NULL on error. - */ - public static native long createContext(); - - /** - * Destroy a validation context and free all its resources. Outstanding - * async queries are killed and callbacks are not called for them. - * - * @param context context to delete - */ - public static native void deleteContext(long context); - - /** - * Set machine to forward DNS queries to, the caching resolver to use. - *
- * IP4 or IP6 address. Forwards all DNS requests to that machine, which is - * expected to run a recursive resolver. If the proxy is not DNSSEC-capable, - * validation may fail. Can be called several times, in that case the - * addresses are used as backup servers. - * - * @param context context. At this time it is only possible to set - * configuration before the first resolve is done. - * @param server address, IP4 or IP6 in string format. If the server is - * NULL, forwarding is disabled. - */ - public static native void setForwarder(long context, String server); - - /** - * Add a trust anchor to the given context. - *
- * The trust anchor is a string, on one line, that holds a valid DNSKEY or - * DS RR. - * - * @param context context. At this time it is only possible to add trusted - * keys before the first resolve is done. - * @param anchor string, with zone-format RR on one line. [domainname] [TTL - * optional] [type] [class optional] [rdata contents] - */ - public static native void addTrustAnchor(long context, String anchor); - - /** - * Perform resolution and validation of the target name. - * - * @param context context. The context is finalized, and can no longer - * accept config changes. - * @param name domain name in text format (a zero terminated text string). - * @param rrtype type of RR in host order, 1 is A (address). - * @param rrclass class of RR in host order, 1 is IN (for internet). - * @return the result data is returned in a newly allocated result - * structure. May be NULL on return, return value is set to an error - * in that case (out of memory). - * @throws UnboundException when an error occurred. - */ - public static native UnboundResult resolve(long context, String name, - int rrtype, int rrclass) throws UnboundException; - - /** - * Perform resolution and validation of the target name. - *
- * Asynchronous, after a while, the callback will be called with your data
- * and the result.
- *
- * @param context context. If no thread or process has been created yet to
- * perform the work in the background, it is created now. The
- * context is finalized, and can no longer accept config changes.
- * @param name domain name in text format (a string).
- * @param rrtype type of RR in host order, 1 is A.
- * @param rrclass class of RR in host order, 1 is IN (for internet).
- * @param data this data is your own data (you can pass null), and is passed
- * on to the callback function.
- * @param cb this is called on completion of the resolution.
- * @return an identifier number is returned for the query as it is in
- * progress. It can be used to cancel the query.
- * @throws UnboundException when an error occurred.
- */
- public static native int resolveAsync(long context, String name,
- int rrtype, int rrclass, Object data, UnboundCallback cb)
- throws UnboundException;
-
- /**
- * Cancel an async query in progress. Its callback will not be called.
- *
- * @param context context.
- * @param asyncId which query to cancel.
- * @throws UnboundException This routine can error if the async_id passed
- * does not exist or has already been delivered. If another
- * thread is processing results at the same time, the result may
- * be delivered at the same time and the cancel fails with an
- * error. Also the cancel can fail due to a system error, no
- * memory or socket failures.
- */
- public static native void cancelAsync(long context, int asyncId)
- throws UnboundException;
-
- /**
- * Convert error value to a human readable string.
- *
- * @param code error code from one of the Unbound functions.
- * @return text string of the error code.
- */
- public static native String errorCodeToString(int code);
-
- /**
- * Wait for a context to finish with results. Call this routine to continue
- * processing results from the validating resolver. After the wait, there
- * are no more outstanding asynchronous queries.
- *
- * @param context context.
- * @throws UnboundException when an error occurred.
- */
- public static native void processAsync(long context)
- throws UnboundException;
-
- /**
- * Interface for the async resolve callback.
- */
- public interface UnboundCallback
- {
- /**
- * Called on completion of the async resolution.
- *
- * @param data the same object as passed to
- * {@link UnboundApi#resolveAsync(long, String, int, int,
- * Object, UnboundCallback)}
- * @param err 0 when a result has been found, an Unbound error code
- * otherwise
- * @param result a newly allocated result structure. The result may be
- * null, in that case err is set.
- */
- public void UnboundResolveCallback(Object data, int err,
- UnboundResult result);
- }
-}
diff --git a/src/net/java/sip/communicator/impl/dns/UnboundException.java b/src/net/java/sip/communicator/impl/dns/UnboundException.java
deleted file mode 100644
index a27a60791..000000000
--- a/src/net/java/sip/communicator/impl/dns/UnboundException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Copyright @ 2015 Atlassian Pty Ltd
- *
- * 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 net.java.sip.communicator.impl.dns;
-
-/**
- * Exception that is being thrown when native Unbound code resulted in an error.
- *
- * @author Ingo Bauersachs
- */
-public class UnboundException
- extends Exception
-{
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- /**
- * Creates a new instance of this class.
- *
- * @param message the detail message.
- */
- public UnboundException(String message)
- {
- super(message);
- }
-}
diff --git a/src/net/java/sip/communicator/impl/dns/UnboundResolver.java b/src/net/java/sip/communicator/impl/dns/UnboundResolver.java
deleted file mode 100644
index 3f3d8c984..000000000
--- a/src/net/java/sip/communicator/impl/dns/UnboundResolver.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Copyright @ 2015 Atlassian Pty Ltd
- *
- * 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 net.java.sip.communicator.impl.dns;
-
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import java.util.concurrent.*;
-
-import net.java.sip.communicator.service.dns.*;
-import net.java.sip.communicator.util.*;
-
-import org.xbill.DNS.*;
-
-/**
- * Implementation of the {@link Resolver} interface, wrapping the native NLnet
- * Labs Unbound resolver. Only the basic methods for queries are supported.
- *
- * @author Ingo Bauersachs
- */
-public class UnboundResolver
- implements CustomResolver
-{
- private final static Logger logger =
- Logger.getLogger(UnboundResolver.class);
-
- /**
- * Helper class to synchronize on asynchronous queries.
- */
- private static class CallbackData
- {
- /**
- * The resolver consumer that wishes to be informed when the request
- * completed.
- */
- ResolverListener listener;
-
- /**
- * The unbound session context.
- */
- long context;
-
- /**
- * The ID of the unbound async query.
- */
- int asyncId;
-
- /**
- * Java synchronization on top of unbound.
- */
- CountDownLatch sync = new CountDownLatch(1);
- }
-
- /**
- * Timeout for DNS queries.
- */
- private int timeout = 10000;
-
- /**
- * The recursive DNS servers answering our queries.
- */
- private String[] forwarders;
-
- /**
- * DNSSEC trust anchors for signed zones (usually for the root zone).
- */
- private List
- * The JavaDoc of these fields is directly copied from libunbound, licensed as
- * follows:
- *
- * Copyright (c) 2007, NLnet Labs. All rights reserved.
- *
- * This software is open source.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the NLNET LABS nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * @author Ingo Bauersachs
- */
-public class UnboundResult
-{
- /**
- * The original question, name text string.
- */
- String qname;
-
- /**
- * the type asked for
- */
- int qtype;
-
- /**
- * the type asked for
- */
- int qclass;
-
-
- /**
- * a list of network order DNS rdata items, terminated with a NULL pointer,
- * so that data[0] is the first result entry, data[1] the second, and the
- * last entry is NULL.
- */
- byte[][] data;
-
- /**
- * canonical name for the result (the final cname).
- */
- String canonname;
-
- /**
- * DNS RCODE for the result.
- */
- int rcode;
-
- /**
- * The DNS answer packet.
- */
- byte[] answerPacket;
-
-
- /**
- * If there is any data, this is true.
- */
- boolean haveData;
-
- /**
- * If there was no data, and the domain did not exist, this is true.
- */
- boolean nxDomain;
-
- /**
- * True, if the result is validated securely.
- */
- boolean secure;
-
- /**
- * If the result was not secure ({@link #secure} == false), and this result
- * is due to a security failure, bogus is true.
- */
- boolean bogus;
-
- /**
- * If the result is bogus this contains a string (zero terminated) that
- * describes the failure.
- */
- String whyBogus;
-}
diff --git a/src/net/java/sip/communicator/impl/dns/dns.manifest.mf b/src/net/java/sip/communicator/impl/dns/dns.manifest.mf
index 331eba133..33174b5b6 100644
--- a/src/net/java/sip/communicator/impl/dns/dns.manifest.mf
+++ b/src/net/java/sip/communicator/impl/dns/dns.manifest.mf
@@ -8,6 +8,8 @@ Import-Package: org.jitsi.util,
org.osgi.framework,
net.java.sip.communicator.util,
net.java.sip.communicator.plugin.desktoputil,
+ org.jitsi.dnssec,
+ org.jitsi.dnssec.validator,
org.jitsi.service.resources,
org.jitsi.service.fileaccess,
net.java.sip.communicator.service.resources,
diff --git a/src/net/java/sip/communicator/launcher/SIPCommunicator.java b/src/net/java/sip/communicator/launcher/SIPCommunicator.java
index 0fccc20a4..fee1e4043 100644
--- a/src/net/java/sip/communicator/launcher/SIPCommunicator.java
+++ b/src/net/java/sip/communicator/launcher/SIPCommunicator.java
@@ -118,7 +118,7 @@ public static void main(String[] args)
{
System.setProperty(
"sun.net.spi.nameservice.provider.1",
- "dns,dnsjava");
+ "dns,jitsi");
}
if (version.startsWith("1.5") || vmVendor.startsWith("Gnu") ||
diff --git a/src/net/java/sip/communicator/plugin/dnsconfig/DnssecPanel.java b/src/net/java/sip/communicator/plugin/dnsconfig/DnssecPanel.java
index 0500c07dd..27bf565f0 100644
--- a/src/net/java/sip/communicator/plugin/dnsconfig/DnssecPanel.java
+++ b/src/net/java/sip/communicator/plugin/dnsconfig/DnssecPanel.java
@@ -267,7 +267,7 @@ public void actionPerformed(ActionEvent e)
if(chkEnabled.isSelected())
{
if(!f.createNewFile() && !f.exists())
- chkEnabled.setSelected(UnboundApi.isAvailable());
+ chkEnabled.setSelected(false);
}
else
{
diff --git a/src/net/java/sip/communicator/util/JitsiDnsNameService.java b/src/net/java/sip/communicator/util/JitsiDnsNameService.java
new file mode 100644
index 000000000..cf68ad5e3
--- /dev/null
+++ b/src/net/java/sip/communicator/util/JitsiDnsNameService.java
@@ -0,0 +1,151 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Copyright @ 2016 Atlassian Pty Ltd
+ *
+ * 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 net.java.sip.communicator.util;
+
+import java.lang.reflect.Method;
+import java.net.*;
+
+import org.xbill.DNS.*;
+
+import sun.net.spi.nameservice.*;
+
+/**
+ * JNDI DNS service to send DNS lookup through the dnsjava Lookup
+ * infrastructure. This is needed to catch lookups that are not made
+ * through the DNSSEC-aware NetworkUtils.
+ *
+ * @author Ingo Bauersachs
+ */
+public class JitsiDnsNameService
+ implements NameService
+{
+ private static boolean v6first;
+ private static Name localhostName = null;
+ private static InetAddress[] localhostAddresses = null;
+ private static InetAddress[] localhostNamedAddresses = null;
+ private static boolean addressesLoaded = false;
+
+ static
+ {
+ v6first = Boolean.getBoolean("java.net.preferIPv6Addresses");
+ try
+ {
+ // retrieve the name from the system that is used as localhost
+ Class> inClass = Class.forName("java.net.InetAddressImplFactory");
+ Method create = inClass.getDeclaredMethod("create");
+ create.setAccessible(true);
+
+ Object impl = create.invoke(null);
+ Class> clazz = Class.forName("java.net.InetAddressImpl");
+ Method hostname = clazz.getMethod("getLocalHostName");
+ hostname.setAccessible(true);
+ localhostName = new Name((String) hostname.invoke(impl));
+ Method lookup = clazz.getMethod("lookupAllHostAddr", String.class);
+ lookup.setAccessible(true);
+
+ localhostNamedAddresses = (InetAddress[])lookup.invoke(impl,
+ localhostName.toString());
+ localhostAddresses = (InetAddress[])lookup.invoke(impl,
+ "localhost");
+
+ addressesLoaded = true;
+ }
+ catch (Exception e)
+ {
+ System.err.println("Could not obtain localhost: " + e);
+ }
+ }
+
+ @Override
+ public String getHostByAddr(final byte[] bytes)
+ throws UnknownHostException
+ {
+ InetAddress addr = InetAddress.getByAddress(bytes);
+ if (addr.isLoopbackAddress())
+ {
+ return "localhost";
+ }
+
+ Name name = ReverseMap.fromAddress(addr);
+ Lookup l = new Lookup(name, Type.PTR);
+ Record[] records = l.run();
+ if (records == null)
+ {
+ throw new UnknownHostException();
+ }
+
+ return ((PTRRecord) records[0]).getTarget().toString();
+ }
+
+ @Override
+ public InetAddress[] lookupAllHostAddr(final String host)
+ throws UnknownHostException
+ {
+ Name n;
+ try
+ {
+ n = new Name(host);
+ // Avoid sending queries to a nameserver for localhost
+ // and the machine's hostname. Unless in an enterprise environment
+ // the nameserver wouldn't know about that machine name anyway.
+ if (addressesLoaded)
+ {
+ if (n.equals(localhostName))
+ {
+ return localhostNamedAddresses;
+ }
+ else if (host.equals("localhost"))
+ {
+ return localhostAddresses;
+ }
+ }
+ }
+ catch (TextParseException e)
+ {
+ throw new UnknownHostException(host);
+ }
+
+ Lookup l = new Lookup(n, v6first ? Type.AAAA : Type.A);
+ Record[] r = l.run();
+ if (r == null || r.length == 0)
+ {
+ l = new Lookup(n, v6first ? Type.A : Type.AAAA);
+ r = l.run();
+ }
+
+ if (r == null || r.length == 0)
+ {
+ throw new UnknownHostException(host);
+ }
+
+ InetAddress[] results = new InetAddress[r.length];
+ for (int i = 0; i < r.length; i++)
+ {
+ if (r[i] instanceof AAAARecord)
+ {
+ results[i] = ((AAAARecord) r[i]).getAddress();
+ }
+ else if (r[i] instanceof ARecord)
+ {
+ results[i] = ((ARecord) r[i]).getAddress();
+ }
+ }
+
+ return results;
+ }
+}
diff --git a/src/net/java/sip/communicator/util/JitsiDnsNameServiceDescriptor.java b/src/net/java/sip/communicator/util/JitsiDnsNameServiceDescriptor.java
new file mode 100644
index 000000000..559646a40
--- /dev/null
+++ b/src/net/java/sip/communicator/util/JitsiDnsNameServiceDescriptor.java
@@ -0,0 +1,58 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Copyright @ 2016 Atlassian Pty Ltd
+ *
+ * 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 net.java.sip.communicator.util;
+
+import sun.net.spi.nameservice.*;
+
+/**
+ * A name service descriptor for Jitsi's DNS service. It is instantiated by the
+ * JRE when DNSSEC is enabled in Jitsi's options.
+ *
+ * @author Ingo Bauersachs
+ */
+public class JitsiDnsNameServiceDescriptor
+ implements NameServiceDescriptor
+{
+ /**
+ * Gets and creates an instance of the Jitsi's name service.
+ *
+ * @return an instance of the Jitsi's name service.
+ */
+ public NameService createNameService()
+ {
+ return new JitsiDnsNameService();
+ }
+
+ /**
+ * Gets the type of this name service.
+ * @return the string dns
+ */
+ public String getType()
+ {
+ return "dns";
+ }
+
+ /**
+ * Gets the name of this name service.
+ * @return the string jitsi
+ */
+ public String getProviderName()
+ {
+ return "jitsi";
+ }
+}
\ No newline at end of file
diff --git a/src/net/java/sip/communicator/util/util.manifest.mf b/src/net/java/sip/communicator/util/util.manifest.mf
index 7de9af7ab..a6e4db7bc 100644
--- a/src/net/java/sip/communicator/util/util.manifest.mf
+++ b/src/net/java/sip/communicator/util/util.manifest.mf
@@ -56,8 +56,7 @@ Import-Package: com.sun.awt,
sun.awt.shell,
sun.net.dns,
sun.net.util
-Export-Package: org.xbill.DNS,
- net.java.sip.communicator.util,
+Export-Package: net.java.sip.communicator.util,
net.java.sip.communicator.util.launchutils,
net.java.sip.communicator.util.skin,
net.java.sip.communicator.util.xml,