DPM: Propagate StrongBox-related exception

When the caller attempts to generate a key via DevicePolicyManager
(using DevicePolicyManager.generateKeyPair), and specifies that
StrongBox should be used, throw the right exception indicating
StrongBox unavailability - the same one that is thrown if the same
parameters were passed to the KeyStore's key generation method.

This is achieved by catching the StrongBoxUnavailableException in
KeyChain, returning an error code indicating this particular failure
to the DevicePolicyManagerService, which then propagates it by
throwing a service-specific exception with a value indicating
StrongBox unavailability.
The DevicePolicyManager then raises StrongBoxUnavailableException.

Prior to this change the exception propagated from KeyChain would be
a generic failure so the caller would simply get a null result.

Bug: 110882855
Bug: 111183576
Bug: 111322478
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedDeviceOwnerTest#testKeyManagement
Change-Id: I9abe3f449b48eb5a960fafbc15c59b9b4ce7a966
This commit is contained in:
Eran Messeri
2018-07-09 17:58:26 +01:00
parent 309adbff03
commit 607a995691
3 changed files with 34 additions and 2 deletions

View File

@@ -282,11 +282,17 @@ public final class KeyChain {
*/
public static final int KEY_GEN_NO_KEYSTORE_PROVIDER = 5;
/**
* StrongBox unavailable when calling {@link #generateKeyPair}
* @hide
*/
public static final int KEY_GEN_STRONGBOX_UNAVAILABLE = 6;
/**
* General failure while calling {@link #generateKeyPair}
* @hide
*/
public static final int KEY_GEN_FAILURE = 6;
public static final int KEY_GEN_FAILURE = 7;
/**
* Successful call to {@link #attestKey}