Keystore 2.0: Make Legacy VPN settings ready for Keystore 2.0

Keystore 2.0 no longer stores vpn profiles. It still offers a
Legacy VPN profile store, to access existing profiles.

Test: N/A
Bug: 171305607
Bug: 171305388
Change-Id: I40dea0b9c3824b56814ae4c2fb6c7663c7d97af5
This commit is contained in:
Janis Danisevskis
2021-01-25 14:59:38 -08:00
parent 00f07cf138
commit b5caf84154
5 changed files with 44 additions and 39 deletions

View File

@@ -20,7 +20,7 @@ import android.net.VpnManager;
import android.os.RemoteException;
import android.provider.Settings;
import android.security.Credentials;
import android.security.KeyStore;
import android.security.LegacyVpnProfileStore;
import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
@@ -28,27 +28,25 @@ import com.android.internal.net.VpnConfig;
/**
* Utility functions for vpn.
*
* Keystore methods should only be called in system user
* LegacyVpnProfileStore methods should only be called in system user
*/
public class VpnUtils {
private static final String TAG = "VpnUtils";
public static String getLockdownVpn() {
final byte[] value = KeyStore.getInstance().get(
Credentials.LOCKDOWN_VPN, true /* suppressKeyNotFoundWarning */);
final byte[] value = LegacyVpnProfileStore.get(Credentials.LOCKDOWN_VPN);
return value == null ? null : new String(value);
}
public static void clearLockdownVpn(Context context) {
KeyStore.getInstance().delete(Credentials.LOCKDOWN_VPN);
LegacyVpnProfileStore.remove(Credentials.LOCKDOWN_VPN);
// Always notify VpnManager after keystore update
getVpnManager(context).updateLockdownVpn();
}
public static void setLockdownVpn(Context context, String lockdownKey) {
KeyStore.getInstance().put(Credentials.LOCKDOWN_VPN, lockdownKey.getBytes(),
KeyStore.UID_SELF, /* flags */ 0);
LegacyVpnProfileStore.put(Credentials.LOCKDOWN_VPN, lockdownKey.getBytes());
// Always notify VpnManager after keystore update
getVpnManager(context).updateLockdownVpn();
}