summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main
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-06-01 21:08:02 +0200
commit6d50dde1bb2eb8fd63e4543000b0b6ad0272cc67 (patch)
tree026372497146fbff2f02a2cb26e5f8d8b92e2c7a /tunnel/src/main
parent93f565d9dd9203c03dd578dabe3d7dce57cf74b6 (diff)
tunnel: download pac in java
Diffstat (limited to 'tunnel/src/main')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java35
-rw-r--r--tunnel/src/main/proto/libwg.proto5
2 files changed, 36 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 596bea7d..6afdfd95 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -59,6 +59,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;
@@ -287,12 +290,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() {
diff --git a/tunnel/src/main/proto/libwg.proto b/tunnel/src/main/proto/libwg.proto
index da6f6da4..c87eb9ef 100644
--- a/tunnel/src/main/proto/libwg.proto
+++ b/tunnel/src/main/proto/libwg.proto
@@ -50,7 +50,10 @@ message VersionResponse {
}
message StartHttpProxyRequest {
- string pacFileUrl = 1;
+ oneof pacFile {
+ string pacFileUrl = 1;
+ string pacFileContent = 2;
+ }
}
message StartHttpProxyResponse {