summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2022-08-03 15:05:18 +0200
committerArne Schwabe <arne@rfc2549.org>2022-08-03 15:05:18 +0200
commitd523eb98316caaa60a6512ae6f45300205ad5abf (patch)
tree3591006a9910aa4ca4121e37742dc56b695e80ee
parent2ea430e30bb5078d52c783018eeb364e6e108138 (diff)
Disable profile encryption upon error
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java31
1 files changed, 25 insertions, 6 deletions
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 1185a697..b46a8f10 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
+import java.util.Vector;
import de.blinkt.openvpn.VpnProfile;
@@ -35,7 +36,8 @@ public class ProfileManager {
private static VpnProfile mLastConnectedVpn = null;
private static VpnProfile tmpprofile = null;
private HashMap<String, VpnProfile> profiles = new HashMap<>();
-
+ /* We got an error trying to save profiles, do not try encryption anymore */
+ private static boolean encryptionBroken = false;
private ProfileManager() {
}
@@ -107,6 +109,8 @@ public class ProfileManager {
public static void saveProfile(Context context, VpnProfile profile) {
SharedPreferences prefs = Preferences.getDefaultSharedPreferences(context);
boolean preferEncryption = prefs.getBoolean("preferencryption", true);
+ if (encryptionBroken)
+ preferEncryption = false;
profile.mVersion += 1;
ObjectOutputStream vpnFile;
@@ -136,10 +140,19 @@ public class ProfileManager {
VpnStatus.logInfo("Cannot rename " + encryptedFile);
}
}
- vpnFileOut = ProfileEncryption.getEncryptedVpOutput(context, encryptedFile);
- deleteIfExists = filename + ".vp";
- if (encryptedFileOld.exists()) {
- encryptedFileOld.delete();
+ try {
+ vpnFileOut = ProfileEncryption.getEncryptedVpOutput(context, encryptedFile);
+ deleteIfExists = filename + ".vp";
+ if (encryptedFileOld.exists()) {
+ encryptedFileOld.delete();
+ }
+ } catch (IOException ioe)
+ {
+ VpnStatus.logException(VpnStatus.LogLevel.INFO, "Error trying to write an encrypted VPN profile, disabling " +
+ "encryption", ioe);
+ encryptionBroken = true;
+ saveProfile(context, profile);
+ return;
}
}
else {
@@ -257,10 +270,16 @@ public class ProfileManager {
if (!profiles.containsKey(vpnentry))
loadVpnEntry(context, vpnentry);
}
+
+ Vector<String> removeUuids = new Vector<>();
for (String profileuuid:profiles.keySet())
{
if (!vlist.contains(profileuuid))
- profiles.remove(profileuuid);
+ removeUuids.add(profileuuid);
+ }
+ for (String uuid: removeUuids)
+ {
+ profiles.remove(uuid);
}
}