Skip to content

Commit 8bb986f

Browse files
committed
Fix hash comparison when profile is base64 encoded. Allow going back to non-Alias config
1 parent 4c0e72f commit 8bb986f

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ private void removeChangesListener(Context c) {
6060
c.unregisterReceiver(mRestrictionsReceiver);
6161
}
6262

63-
private String hashConfig(String config) {
63+
private String hashConfig(String rawconfig) {
64+
String config = prepare(rawconfig);
6465
MessageDigest digest;
6566
try {
6667
digest = MessageDigest.getInstance("SHA1");
@@ -121,6 +122,10 @@ private void applyRestrictions(Context c) {
121122
continue;
122123
}
123124

125+
/* we always use lower case uuid since Android UUID class will use present
126+
* them that way */
127+
uuid = uuid.toLowerCase(Locale.US);
128+
124129
if (uuid.equals(defaultprofile))
125130
defaultprofileProvisioned = true;
126131

@@ -188,22 +193,43 @@ private void applyRestrictions(Context c) {
188193
* the authentication method and will also set the keystore alias
189194
*/
190195
private void addCertificateAlias(VpnProfile vpnProfile, String certAlias, Context c) {
191-
if (certAlias == null || vpnProfile == null)
196+
if (vpnProfile == null)
192197
return;
193198

194199
int oldType = vpnProfile.mAuthenticationType;
195200
String oldAlias = vpnProfile.mAlias;
196201

197-
switch (vpnProfile.mAuthenticationType)
202+
if (!TextUtils.isEmpty(certAlias)) {
203+
switch (vpnProfile.mAuthenticationType)
204+
{
205+
case VpnProfile.TYPE_PKCS12:
206+
case VpnProfile.TYPE_CERTIFICATES:
207+
vpnProfile.mAuthenticationType = VpnProfile.TYPE_KEYSTORE;
208+
break;
209+
case VpnProfile.TYPE_USERPASS_CERTIFICATES:
210+
case VpnProfile.TYPE_USERPASS_PKCS12:
211+
vpnProfile.mAuthenticationType = VpnProfile.TYPE_USERPASS_KEYSTORE;
212+
break;
213+
}
214+
215+
} else
198216
{
199-
case VpnProfile.TYPE_PKCS12:
200-
case VpnProfile.TYPE_CERTIFICATES:
201-
vpnProfile.mAuthenticationType = VpnProfile.TYPE_KEYSTORE;
202-
break;
203-
case VpnProfile.TYPE_USERPASS_CERTIFICATES:
204-
case VpnProfile.TYPE_USERPASS_PKCS12:
205-
vpnProfile.mAuthenticationType = VpnProfile.TYPE_USERPASS_KEYSTORE;
206-
break;
217+
/* Alias is null, return to non keystore method */
218+
boolean pkcs12present = !TextUtils.isEmpty(vpnProfile.mPKCS12Filename);
219+
switch (vpnProfile.mAuthenticationType) {
220+
case VpnProfile.TYPE_USERPASS_KEYSTORE:
221+
if (pkcs12present)
222+
vpnProfile.mAuthenticationType = VpnProfile.TYPE_USERPASS_PKCS12;
223+
else
224+
vpnProfile.mAuthenticationType = VpnProfile.TYPE_USERPASS_CERTIFICATES;
225+
break;
226+
case VpnProfile.TYPE_KEYSTORE:
227+
if (pkcs12present)
228+
vpnProfile.mAuthenticationType = VpnProfile.TYPE_PKCS12;
229+
else
230+
vpnProfile.mAuthenticationType = VpnProfile.TYPE_CERTIFICATES;
231+
break;
232+
}
207233
}
208234
vpnProfile.mAlias = certAlias;
209235

0 commit comments

Comments
 (0)