diff options
author | Aurélien Chabot <aurelien@chabot.fr> | 2018-03-01 19:10:06 +1100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-17 02:15:24 +0200 |
commit | d97312b96a5f350fd50a667e23d8fb896a72b85c (patch) | |
tree | 704727b6e704a2841c94c42f9ad5140920087068 /app | |
parent | 9dfab4d60f5dc06445df53d675a458dfae8cb5f6 (diff) |
GoBackend: Resolve endpoint before passing it to the go lib
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/wireguard/android/backend/GoBackend.java | 17 |
1 files changed, 15 insertions, 2 deletions
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) { |