mirror of
https://github.com/schwabe/ics-openvpn.git
synced 2024-09-19 19:42:29 +02:00
Use stdin instead android.conf in the file system to pass OpenVPN config
This commit is contained in:
parent
2bb11be97a
commit
78f2d906dd
@ -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) {
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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()));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user