summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2022-02-18 17:09:45 +0100
committerArne Schwabe <arne@rfc2549.org>2022-02-18 17:09:45 +0100
commit78f2d906dd55811cc657e801847cd9315ae05cbf (patch)
treef593904e4e649d32d56b8a5470bd747728dadbee
parent2bb11be97a18253168ae1938e265220caf91bcbd (diff)
Use stdin instead android.conf in the file system to pass OpenVPN config
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java7
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java30
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java14
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java9
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java2
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java2
6 files changed, 34 insertions, 30 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 89154152..184c64fd 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -33,6 +33,8 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
@@ -816,12 +818,11 @@ public class VpnProfile implements Serializable, Cloneable {
return intent;
}
- public void writeConfigFile(Context context) throws IOException {
- FileWriter cfg = new FileWriter(VPNLaunchHelper.getConfigFilePath(context));
+ public void writeConfigFileOutput(Context context, OutputStream out) throws IOException {
+ OutputStreamWriter cfg = new OutputStreamWriter(out);
cfg.write(getConfigFile(context, false));
cfg.flush();
cfg.close();
-
}
public Intent getStartServiceIntent(Context context) {
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 517aa4e8..742e1aa5 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -51,6 +51,7 @@ import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Locale;
import java.util.Vector;
+import java.util.concurrent.ExecutionException;
import de.blinkt.openvpn.LaunchVPN;
import de.blinkt.openvpn.R;
@@ -585,13 +586,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
ProfileManager.setConnectedVpnProfile(this, mProfile);
VpnStatus.setConnectedVPNProfile(mProfile.getUUIDString());
- try {
- mProfile.writeConfigFile(this);
- } catch (IOException e) {
- VpnStatus.logException("Error writing config file", e);
- endVpnService();
- return;
- }
String nativeLibraryDirectory = getApplicationInfo().nativeLibraryDir;
String tmpDir;
try {
@@ -646,17 +640,21 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
mProcessThread.start();
}
- new Handler(getMainLooper()).post(new Runnable() {
- @Override
- public void run() {
- if (mDeviceStateReceiver != null)
- unregisterDeviceStateReceiver();
- registerDeviceStateReceiver(mManagement);
- }
- }
+ try {
+ mProfile.writeConfigFileOutput(this, ((OpenVPNThread)processThread).getOpenVPNStdin());
+ } catch (IOException | ExecutionException | InterruptedException e) {
+ VpnStatus.logException("Error generating config file", e);
+ endVpnService();
+ return;
+ }
+
+ boolean post = new Handler(getMainLooper()).post(() -> {
+ if (mDeviceStateReceiver != null)
+ unregisterDeviceStateReceiver();
- );
+ registerDeviceStateReceiver(mManagement);
+ });
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
index 1d8f6cc6..5ce8d864 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
@@ -14,11 +14,14 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.Locale;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -34,6 +37,7 @@ public class OpenVPNThread implements Runnable {
public static final int M_NONFATAL = (1 << 5);
public static final int M_WARN = (1 << 6);
public static final int M_DEBUG = (1 << 7);
+ private final CompletableFuture<OutputStream> mStreamFuture = new CompletableFuture<>();
private String[] mArgv;
private Process mProcess;
private String mNativeDir;
@@ -122,10 +126,13 @@ public class OpenVPNThread implements Runnable {
try {
mProcess = pb.start();
// Close the output, since we don't need it
- mProcess.getOutputStream().close();
+
InputStream in = mProcess.getInputStream();
+ OutputStream out = mProcess.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ mStreamFuture.complete(out);
+
while (true) {
String logline = br.readLine();
if (logline == null)
@@ -166,6 +173,7 @@ public class OpenVPNThread implements Runnable {
}
} catch (InterruptedException | IOException e) {
VpnStatus.logException("Error reading from output of OpenVPN process", e);
+ mStreamFuture.cancel(true);
stopProcess();
}
@@ -187,4 +195,8 @@ public class OpenVPNThread implements Runnable {
}
return lbpath;
}
+
+ public OutputStream getOpenVPNStdin() throws ExecutionException, InterruptedException {
+ return mStreamFuture.get();
+ }
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index 7f9508b1..cbb27c22 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -22,7 +22,6 @@ import de.blinkt.openvpn.VpnProfile;
public class VPNLaunchHelper {
private static final String MINIPIEVPN = "pie_openvpn";
- private static final String OVPNCONFIGFILE = "android.conf";
private static String writeMiniVPN(Context context) {
String nativeAPI = NativeUtils.getNativeAPI();
@@ -68,7 +67,7 @@ public class VPNLaunchHelper {
args.add(binaryName);
args.add("--config");
- args.add(getConfigFilePath(c));
+ args.add("stdin");
return args.toArray(new String[0]);
}
@@ -122,10 +121,4 @@ public class VPNLaunchHelper {
}
}
-
-
- public static String getConfigFilePath(Context context) {
- return context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE;
- }
-
}
diff --git a/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java b/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
index c9ce9745..1c5dd0e5 100644
--- a/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
+++ b/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
@@ -116,7 +116,7 @@ public class OpenVPNTileService extends TileService implements VpnStatus.StateLi
VpnProfile vpn;
Tile t = getQsTile();
if (level == ConnectionStatus.LEVEL_AUTH_FAILED || level == ConnectionStatus.LEVEL_NOTCONNECTED) {
- // No VPN connected, use stadnard VPN
+ // No VPN connected, use standard VPN
vpn = getQSVPN();
if (vpn == null) {
t.setLabel(getString(R.string.novpn_selected));
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java
index 8bbc14b0..a3c19955 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java
@@ -28,7 +28,7 @@ public abstract class OpenVpnPreferencesFragment extends PreferenceFragmentCompa
super.onCreate(savedInstanceState);
String profileUUID = getArguments().getString(getActivity().getPackageName() + ".profileUUID");
- mProfile = ProfileManager.get(getActivity(),profileUUID);
+ mProfile = ProfileManager.get(getActivity(), profileUUID);
getActivity().setTitle(getString(R.string.edit_profile_title, mProfile.getName()));
}