summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-10-04 04:18:06 +0200
committerArne Schwabe <arne@rfc2549.org>2021-10-04 04:18:06 +0200
commit650e238b7676393cd426a7cdb86fcc4fd2d87a6d (patch)
tree440328c0d9f99ca232d2c505c0427ec0ccfdbc60
parentaf6c8187ecff2ca2955f267975e346e34f0a4c91 (diff)
Ensure profile is saved if auth/password is queried on startup
This ensure the profile counter is incremented and the profile is saved to disk to avoid the race condition of not getting the user/pass which was started. Closes #1342
-rw-r--r--main/src/main/java/de/blinkt/openvpn/LaunchVPN.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java26
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java17
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt2
4 files changed, 24 insertions, 23 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
index 7bc0b7ed..86eef35a 100644
--- a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
+++ b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
@@ -209,6 +209,8 @@ public class LaunchVPN extends Activity {
mSelectedProfile.mPassword = null;
mTransientAuthPW = pw;
}
+ ProfileManager.saveProfile( LaunchVPN.this, mSelectedProfile);
+
} else {
mTransientCertOrPCKS12PW = entry.getText().toString();
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
index 26d4893f..14f25aa0 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
@@ -699,17 +699,21 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
String pw = null;
String username = null;
- if (needed.equals("Private Key")) {
- pw = mProfile.getPasswordPrivateKey();
- } else if (needed.equals("Auth")) {
- pw = mProfile.getPasswordAuth();
- username = mProfile.mUsername;
-
- } else if (needed.equals("HTTP Proxy")) {
- if( mCurrentProxyConnection != null) {
- pw = mCurrentProxyConnection.mProxyAuthPassword;
- username = mCurrentProxyConnection.mProxyAuthUser;
- }
+ switch (needed) {
+ case "Private Key":
+ pw = mProfile.getPasswordPrivateKey();
+ break;
+ case "Auth":
+ pw = mProfile.getPasswordAuth();
+ username = mProfile.mUsername;
+
+ break;
+ case "HTTP Proxy":
+ if (mCurrentProxyConnection != null) {
+ pw = mCurrentProxyConnection.mProxyAuthPassword;
+ username = mCurrentProxyConnection.mProxyAuthUser;
+ }
+ break;
}
if (pw != null) {
if (username !=null) {
diff --git a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
index b9edc4b2..4cf98da2 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
@@ -130,25 +130,20 @@ public class ProfileManager {
public static void setTemporaryProfile(Context c, VpnProfile tmp) {
tmp.mTemporaryProfile = true;
ProfileManager.tmpprofile = tmp;
- saveProfile(c, tmp, true, true);
+ saveProfile(c, tmp);
}
public static boolean isTempProfile() {
return mLastConnectedVpn != null && mLastConnectedVpn == tmpprofile;
}
- public void saveProfile(Context context, VpnProfile profile) {
- saveProfile(context, profile, true, false);
- }
-
- private static void saveProfile(Context context, VpnProfile profile, boolean updateVersion, boolean isTemporary) {
+ public static void saveProfile(Context context, VpnProfile profile) {
- if (updateVersion)
- profile.mVersion += 1;
+ profile.mVersion += 1;
ObjectOutputStream vpnFile;
String filename = profile.getUUID().toString() + ".vp";
- if (isTemporary)
+ if (profile.mTemporaryProfile)
filename = TEMPORARY_PROFILE_FILENAME + ".vp";
try {
@@ -261,7 +256,7 @@ public class ProfileManager {
public static void updateLRU(Context c, VpnProfile profile) {
profile.mLastUsed = System.currentTimeMillis();
// LRU does not change the profile, no need for the service to refresh
- if (profile!=tmpprofile)
- saveProfile(c, profile, false, false);
+ if (profile != tmpprofile)
+ saveProfile(c, profile);
}
}
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt b/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt
index a2799d09..5426f669 100644
--- a/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt
@@ -197,7 +197,7 @@ class ConfigConverter : BaseActivity(), FileSelectCallback, View.OnClickListener
ConfigParser.useEmbbedUserAuth(mResult, mEmbeddedPwFile)
vpl.addProfile(mResult)
- vpl.saveProfile(this, mResult)
+ ProfileManager.saveProfile(this, mResult)
vpl.saveProfileList(this)
result.putExtra(VpnProfile.EXTRA_PROFILEUUID, mResult!!.uuid.toString())
setResult(Activity.RESULT_OK, result)