From d97312b96a5f350fd50a667e23d8fb896a72b85c Mon Sep 17 00:00:00 2001 From: Aurélien Chabot Date: Thu, 1 Mar 2018 19:10:06 +1100 Subject: GoBackend: Resolve endpoint before passing it to the go lib Signed-off-by: Jason A. Donenfeld --- .../java/com/wireguard/android/backend/GoBackend.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/com/wireguard/android') diff --git a/app/src/main/java/com/wireguard/android/backend/GoBackend.java b/app/src/main/java/com/wireguard/android/backend/GoBackend.java index eda4123c..4967e63d 100644 --- a/app/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/app/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -14,6 +14,8 @@ import com.wireguard.config.Interface; import com.wireguard.config.Peer; import com.wireguard.crypto.KeyEncoding; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.util.Collections; import java.util.Formatter; import java.util.Set; @@ -113,6 +115,16 @@ public final class GoBackend implements Backend { return getState(tunnel); } + private String ResolveSocketAddress(String string) throws Exception { + String[] part = string.split(":", 2); + if (part.length != 2 || part[0].isEmpty() || part[1].isEmpty()) + throw new Exception("Invalid socket address " + string); + InetAddress address = InetAddress.getByName(part[0]); + int port = Integer.valueOf(part[1]); + InetSocketAddress socketAddress = new InetSocketAddress(address, port); + return socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort(); + } + private void setStateInternal(final Tunnel tunnel, final Config config, final State state) throws Exception { @@ -143,8 +155,9 @@ public final class GoBackend implements Backend { fmt.format("public_key=%s\n", KeyEncoding.keyToHex(KeyEncoding.keyFromBase64(peer.getPublicKey()))); if (peer.getPreSharedKey() != null) fmt.format("preshared_key=%s\n", KeyEncoding.keyToHex(KeyEncoding.keyFromBase64(peer.getPreSharedKey()))); - if (peer.getEndpoint() != null) - fmt.format("endpoint=%s\n", peer.getEndpoint()); + if (peer.getEndpoint() != null) { + fmt.format("endpoint=%s\n", ResolveSocketAddress(peer.getEndpoint())); + } if (peer.getPersistentKeepalive() != null) fmt.format("persistent_keepalive_interval=%d\n", Integer.parseInt(peer.getPersistentKeepalive())); if (peer.getAllowedIPs() != null) { -- cgit v1.2.3