diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-02-24 23:55:03 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-03-23 22:55:18 +0100 |
commit | d6153ccbff8c1fa8d3648daa16ac26e7c37e4d9d (patch) | |
tree | 75124b9fd90cf6ab7aa7e1583d6cc6e86d7f4f09 /tunnel/src/main/java/com/wireguard | |
parent | 045e875d9c49334a2cf48f01116edac8bfcfb9b1 (diff) |
WIP: experimental pac content
Diffstat (limited to 'tunnel/src/main/java/com/wireguard')
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java index c4c72459..1a5e54dd 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -66,6 +66,9 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.Inet4Address; import java.net.Inet6Address; @@ -310,12 +313,38 @@ public final class GoBackend implements Backend { return getState(tunnel); } - private int startHttpProxy(Uri pacFileUrl) { + private static String downloadPacFile(Network network, Uri pacFileUrl) { + HttpURLConnection urlConnection = null; + StringBuffer buf = new StringBuffer(); + try { + URL url = new URL(pacFileUrl.toString()); + urlConnection = (HttpURLConnection) network.openConnection(url); + + InputStream in = urlConnection.getInputStream(); + InputStreamReader isw = new InputStreamReader(in); + + int data = isw.read(); + while (data != -1) { + char current = (char) data; + data = isw.read(); + buf.append(current); + } + } catch (Exception e) { + } finally { + if (urlConnection != null) { + urlConnection.disconnect(); + } + } + + return buf.toString(); + } + + private int startHttpProxy(String pacFile) { LibwgGrpc.LibwgStub asyncStub = LibwgGrpc.newStub(channel); LibwgGrpc.LibwgBlockingStub stub = LibwgGrpc.newBlockingStub(channel); StartHttpProxyRequest.Builder reqBuilder = StartHttpProxyRequest.newBuilder(); - if (pacFileUrl != null && pacFileUrl != Uri.EMPTY) { - reqBuilder.setPacFileUrl(pacFileUrl.toString()); + if (pacFile != null && pacFile != "") { + reqBuilder.setPacFileContent(pacFile); } Thread streamer = new Thread(new Runnable() { @@ -530,20 +559,35 @@ public final class GoBackend implements Backend { Log.i(TAG, "Builder 14"); Optional<HttpProxy> proxy = config.getInterface().getHttpProxy(); + Log.i(TAG, "Builder 14.1"); if (proxy.isPresent()) { + Log.i(TAG, "Builder 14.2"); ProxyInfo pi = proxy.get().getProxyInfo(); + Log.i(TAG, "Builder 14.3"); Uri pacFileUrl = pi.getPacFileUrl(); + Log.i(TAG, "Builder 14.4"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + Log.i(TAG, "Builder 14.5"); if (pacFileUrl != null && pacFileUrl != Uri.EMPTY) { - int listenPort = startHttpProxy(pacFileUrl); + Log.i(TAG, "Builder 14.6"); + String pacFile = downloadPacFile(activeNetwork, pacFileUrl); + int listenPort = startHttpProxy(pacFile); + Log.i(TAG, "Builder 14.7"); ProxyInfo localPi = ProxyInfo.buildDirectProxy("localhost", listenPort); + Log.i(TAG, "Builder 14.8"); builder.setHttpProxy(localPi); + Log.i(TAG, "Builder 14.9"); } else { + Log.i(TAG, "Builder 14.10"); builder.setHttpProxy(pi); + Log.i(TAG, "Builder 14.11"); } + Log.i(TAG, "Builder 14.12"); } + Log.i(TAG, "Builder 14.13"); } + Log.i(TAG, "Builder 14.14"); Log.i(TAG, "Builder 15"); builder.setBlocking(true); |