From 350fc57d87038f3bbd83552f176b07695ed8a81c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 8 May 2020 17:52:41 +0200 Subject: [PATCH] properly wrap IPv6 addresses --- src/main/java/eu/siacs/conversations/utils/IP.java | 8 ++++++++ .../conversations/xmpp/jingle/JingleRtpConnection.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/IP.java b/src/main/java/eu/siacs/conversations/utils/IP.java index 2b7a3f888..a7182e207 100644 --- a/src/main/java/eu/siacs/conversations/utils/IP.java +++ b/src/main/java/eu/siacs/conversations/utils/IP.java @@ -19,4 +19,12 @@ public class IP { || PATTERN_IPV6_HEXCOMPRESSED.matcher(server).matches()); } + public static String wrapIPv6(final String host) { + if (matches(host)) { + return String.format("[%s]", host); + } else { + return host; + } + } + } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 01840189a..5bb0e7b60 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -36,6 +36,7 @@ import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.RtpSessionStatus; import eu.siacs.conversations.services.AppRTCAudioManager; +import eu.siacs.conversations.utils.IP; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xmpp.jingle.stanzas.Group; @@ -1109,9 +1110,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": skipping invalid combination of udp/tls in external services"); continue; } - //TODO wrap ipv6 addresses final PeerConnection.IceServer.Builder iceServerBuilder = PeerConnection.IceServer - .builder(String.format("%s:%s:%s?transport=%s", type, host, port, transport)); + .builder(String.format("%s:%s:%s?transport=%s", type, IP.wrapIPv6(host), port, transport)); iceServerBuilder.setTlsCertPolicy(PeerConnection.TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK); if (username != null && password != null) { iceServerBuilder.setUsername(username);