From 0e1c26c569ee909aca027bbe21e966c68fee5d7c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 5 Sep 2019 13:17:45 +0200 Subject: [PATCH] do not include link local in direct candidates --- .../services/AbstractConnectionManager.java | 1 + .../xmpp/jingle/DirectConnectionUtils.java | 5 ++-- .../xmpp/jingle/JingleCandidate.java | 9 +++---- .../xmpp/jingle/JingleConnection.java | 26 +++++++++---------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java index 432c70390..43c28b854 100644 --- a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java @@ -26,6 +26,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.utils.Compatibility; +import eu.siacs.conversations.utils.CryptoHelper; public class AbstractConnectionManager { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/DirectConnectionUtils.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/DirectConnectionUtils.java index 41a9455b7..d418e4e93 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/DirectConnectionUtils.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/DirectConnectionUtils.java @@ -26,9 +26,10 @@ public class DirectConnectionUtils { final Enumeration inetAddressEnumeration = networkInterface.getInetAddresses(); while (inetAddressEnumeration.hasMoreElements()) { final InetAddress inetAddress = inetAddressEnumeration.nextElement(); - if (!inetAddress.isLoopbackAddress()) { - addresses.add(inetAddress); + if (inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) { + continue; } + addresses.add(inetAddress); } } return addresses; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java index 3f69980aa..7415c32aa 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java @@ -110,15 +110,12 @@ public class JingleCandidate { } public static JingleCandidate parse(Element candidate) { - JingleCandidate parsedCandidate = new JingleCandidate( - candidate.getAttribute("cid"), false); + JingleCandidate parsedCandidate = new JingleCandidate(candidate.getAttribute("cid"), false); parsedCandidate.setHost(candidate.getAttribute("host")); parsedCandidate.setJid(InvalidJid.getNullForInvalid(candidate.getAttributeAsJid("jid"))); parsedCandidate.setType(candidate.getAttribute("type")); - parsedCandidate.setPriority(Integer.parseInt(candidate - .getAttribute("priority"))); - parsedCandidate - .setPort(Integer.parseInt(candidate.getAttribute("port"))); + parsedCandidate.setPriority(Integer.parseInt(candidate.getAttribute("priority"))); + parsedCandidate.setPort(Integer.parseInt(candidate.getAttribute("port"))); return parsedCandidate; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 828d4a021..45539f8f5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -174,7 +174,7 @@ public class JingleConnection implements Transferable { @Override public void failed() { - Log.d(Config.LOGTAG, account.getJid().asBareJid()+": proxy activation failed"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": proxy activation failed"); if (initiating()) { sendFallbackToIbb(); } @@ -320,22 +320,20 @@ public class JingleConnection implements Transferable { @Override public void failed() { - Log.d(Config.LOGTAG, - "connection to our own primary candidete failed"); + Log.d(Config.LOGTAG, "connection to our own proxy65 candidate failed"); sendInitRequest(); } @Override public void established() { - Log.d(Config.LOGTAG, - "successfully connected to our own primary candidate"); + Log.d(Config.LOGTAG, "successfully connected to our own proxy65 candidate"); mergeCandidate(candidate); sendInitRequest(); } }); mergeCandidate(candidate); } else { - Log.d(Config.LOGTAG, "no primary candidate of our own was found"); + Log.d(Config.LOGTAG, "no proxy65 candidate of our own was found"); sendInitRequest(); } }); @@ -437,7 +435,7 @@ public class JingleConnection implements Transferable { if (encrypted == null) { final Element security = content.findChild("security", Namespace.JINGLE_ENCRYPTED_TRANSPORT); if (security != null && AxolotlService.PEP_PREFIX.equals(security.getAttribute("type"))) { - Log.d(Config.LOGTAG, account.getJid().asBareJid()+": received jingle file offer with JET"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received jingle file offer with JET"); encrypted = security.findChild("encrypted", AxolotlService.PEP_PREFIX); } } @@ -533,7 +531,7 @@ public class JingleConnection implements Transferable { this.file.setExpectedSize(file.getSize() + 16); final Element file = content.setFileOffer(this.file, false, this.ftVersion); if (remoteSupportsOmemoJet) { - Log.d(Config.LOGTAG, account.getJid().asBareJid()+": remote announced support for JET"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": remote announced support for JET"); final Element security = new Element("security", Namespace.JINGLE_ENCRYPTED_TRANSPORT); security.setAttribute("name", this.contentName); security.setAttribute("cipher", JET_OMEMO_CIPHER); @@ -619,7 +617,7 @@ public class JingleConnection implements Transferable { @Override public void failed() { - Log.d(Config.LOGTAG, "connection to our own primary candidate failed"); + Log.d(Config.LOGTAG, "connection to our own proxy65 candidate failed"); content.socks5transport().setChildren(getCandidatesAsElements()); packet.setContent(content); sendJinglePacket(packet); @@ -628,7 +626,7 @@ public class JingleConnection implements Transferable { @Override public void established() { - Log.d(Config.LOGTAG, "connected to primary candidate"); + Log.d(Config.LOGTAG, "connected to proxy65 candidate"); mergeCandidate(candidate); content.socks5transport().setChildren(getCandidatesAsElements()); packet.setContent(content); @@ -637,7 +635,7 @@ public class JingleConnection implements Transferable { } }); } else { - Log.d(Config.LOGTAG, "did not find a primary candidate for ourselves"); + Log.d(Config.LOGTAG, "did not find a proxy65 candidate for ourselves"); content.socks5transport().setChildren(getCandidatesAsElements()); packet.setContent(content); sendJinglePacket(packet); @@ -770,14 +768,14 @@ public class JingleConnection implements Transferable { final JingleSocks5Transport connection = chooseConnection(); this.transport = connection; if (connection == null) { - Log.d(Config.LOGTAG, account.getJid().asBareJid()+": could not find suitable candidate"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not find suitable candidate"); this.disconnectSocks5Connections(); if (initiating()) { this.sendFallbackToIbb(); } } else { final JingleCandidate candidate = connection.getCandidate(); - Log.d(Config.LOGTAG, account.getJid().asBareJid()+": elected candidate "+candidate.getHost()+":"+candidate.getPort()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": elected candidate " + candidate.getHost() + ":" + candidate.getPort()); this.mJingleStatus = JINGLE_STATUS_TRANSMITTING; if (connection.needsActivation()) { if (connection.getCandidate().isOurs()) { @@ -888,7 +886,7 @@ public class JingleConnection implements Transferable { private boolean receiveFallbackToIbb(JinglePacket packet) { - Log.d(Config.LOGTAG, account.getJid().asBareJid()+": receiving fallback to ibb"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": receiving fallback to ibb"); final String receivedBlockSize = packet.getJingleContent().ibbTransport().getAttribute("block-size"); if (receivedBlockSize != null) { try {