summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel/src/main')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java52
-rw-r--r--tunnel/src/main/proto/libwg.proto5
2 files changed, 52 insertions, 5 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);
diff --git a/tunnel/src/main/proto/libwg.proto b/tunnel/src/main/proto/libwg.proto
index ab6b2659..349166ca 100644
--- a/tunnel/src/main/proto/libwg.proto
+++ b/tunnel/src/main/proto/libwg.proto
@@ -56,7 +56,10 @@ message VersionResponse {
}
message StartHttpProxyRequest {
- string pacFileUrl = 1;
+ oneof pacFile {
+ string pacFileUrl = 1;
+ string pacFileContent = 2;
+ }
}
message StartHttpProxyResponse {