summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-02-24 23:55:03 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2023-02-24 23:55:03 +0100
commit35c5cb00d6af97dfd917ba7f051a8a6ba85180b8 (patch)
treedab1ae75b24b26df80f88f035a01803f6e9bb2c0 /tunnel/src/main/java/com/wireguard
parent1dbe14aefa8afd7513f6ae3b12e13044d48c684a (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.java52
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 f2eb86da..32e3572a 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);