diff options
author | Arne Schwabe <arne@rfc2549.org> | 2023-05-05 16:20:44 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2023-05-05 16:20:44 +0200 |
commit | 4c0e72f7a213b5204f10cc030155fa26f65e9865 (patch) | |
tree | 8b048ffda09506bfc3d866a5d0619bc9eed7832c /main/src | |
parent | 0aa5df0b6e7c61a631bfee6513eb97512aac075f (diff) |
Fix crash on certificate alias import
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java index 6815f234..c2f539ae 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java +++ b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java @@ -14,7 +14,6 @@ import android.text.TextUtils; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; -import de.blinkt.openvpn.core.Connection; import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; @@ -135,14 +134,14 @@ public class AppRestrictions { if (vpnProfile != null) { // Profile exists, check if need to update it if (ovpnHash.equals(vpnProfile.importedProfileHash)) { - addCertificateAlias(vpnProfile, certAlias); + addCertificateAlias(vpnProfile, certAlias, c); // not modified skip to next profile continue; } } - addProfile(c, ovpn, uuid, name, vpnProfile); - addCertificateAlias(vpnProfile, certAlias); + vpnProfile = addProfile(c, ovpn, uuid, name, vpnProfile); + addCertificateAlias(vpnProfile, certAlias, c); } Vector<VpnProfile> profilesToRemove = new Vector<>(); @@ -188,10 +187,13 @@ public class AppRestrictions { * If certAlias is non-null will modify the profile type to use the keystore variant of * the authentication method and will also set the keystore alias */ - private void addCertificateAlias(VpnProfile vpnProfile, String certAlias) { - if (certAlias == null) + private void addCertificateAlias(VpnProfile vpnProfile, String certAlias, Context c) { + if (certAlias == null || vpnProfile == null) return; + int oldType = vpnProfile.mAuthenticationType; + String oldAlias = vpnProfile.mAlias; + switch (vpnProfile.mAuthenticationType) { case VpnProfile.TYPE_PKCS12: @@ -204,6 +206,12 @@ public class AppRestrictions { break; } vpnProfile.mAlias = certAlias; + + if (!certAlias.equals(oldAlias) || oldType != vpnProfile.mAuthenticationType) + { + ProfileManager pm = ProfileManager.getInstance(c); + pm.saveProfile(c, vpnProfile); + } } private String prepare(String config) { @@ -222,7 +230,7 @@ public class AppRestrictions { ; - private void addProfile(Context c, String config, String uuid, String name, VpnProfile vpnProfile) { + VpnProfile addProfile(Context c, String config, String uuid, String name, VpnProfile vpnProfile) { config = prepare(config); ConfigParser cp = new ConfigParser(); try { @@ -248,9 +256,11 @@ public class AppRestrictions { pm.addProfile(vp); pm.saveProfile(c, vp); pm.saveProfileList(c); + return vp; } catch (ConfigParser.ConfigParseError | IOException | IllegalArgumentException e) { VpnStatus.logException("Error during import of managed profile", e); + return null; } } |